Skip to content

Commit 42a0928

Browse files
committed
feat: clean up source
1 parent 8902086 commit 42a0928

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/CodeGenerationService.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package ch.xxx.aidoclibchat.usecase.service;
1414

15+
import java.util.concurrent.atomic.AtomicBoolean;
16+
1517
import org.springframework.stereotype.Service;
1618

1719
import ch.xxx.aidoclibchat.domain.model.dto.GithubClient;
@@ -20,13 +22,31 @@
2022
@Service
2123
public class CodeGenerationService {
2224
private final GithubClient githubClient;
23-
25+
2426
public CodeGenerationService(GithubClient githubClient) {
2527
this.githubClient = githubClient;
2628
}
27-
29+
2830
public GithubSource generateTests(String url) {
2931
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;
3151
}
3252
}

0 commit comments

Comments
 (0)