File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed
backend/src/main/java/ch/xxx/aidoclibchat/usecase/service Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change 12
12
*/
13
13
package ch .xxx .aidoclibchat .usecase .service ;
14
14
15
+ import java .util .concurrent .atomic .AtomicBoolean ;
16
+
15
17
import org .springframework .stereotype .Service ;
16
18
17
19
import ch .xxx .aidoclibchat .domain .model .dto .GithubClient ;
20
22
@ Service
21
23
public class CodeGenerationService {
22
24
private final GithubClient githubClient ;
23
-
25
+
24
26
public CodeGenerationService (GithubClient githubClient ) {
25
27
this .githubClient = githubClient ;
26
28
}
27
-
29
+
28
30
public GithubSource generateTests (String url ) {
29
31
var myUrl = url .replace ("https://github.com" , GithubClient .GITHUB_BASE_URL ).replace ("/blob" , "" );
30
- return this .githubClient .readSourceFile (myUrl );
32
+ var result = this .githubClient .readSourceFile (myUrl );
33
+ var isComment = new AtomicBoolean (false );
34
+ var sourceLines = result .lines ().stream ().map (myLine -> myLine .replaceAll ("[\t ]" , "" ).trim ()).filter (myLine -> !myLine .isBlank ())
35
+ .filter (myLine -> filterComments (isComment , myLine )).toList ();
36
+ return new GithubSource (result .sourceName (), result .sourcePackage (), sourceLines );
37
+ }
38
+
39
+ private boolean filterComments (AtomicBoolean isComment , String myLine ) {
40
+ var result1 = true ;
41
+ if (myLine .contains ("/*" ) || isComment .get ()) {
42
+ isComment .set (true );
43
+ result1 = false ;
44
+ }
45
+ if (myLine .contains ("*/" )) {
46
+ isComment .set (false );
47
+ result1 = false ;
48
+ }
49
+ result1 = result1 && !myLine .trim ().startsWith ("//" );
50
+ return result1 ;
31
51
}
32
52
}
You can’t perform that action at this time.
0 commit comments