Skip to content

Commit

Permalink
feat: return recursive result
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Jul 9, 2024
1 parent 53f3d41 commit e61494a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package ch.xxx.aidoclibchat.adapter.client;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
Expand All @@ -34,6 +36,6 @@ public GithubSource readSourceFile(String url) {
var resultLines = result.lines().toList();
var sourcePackage = resultLines.stream().filter(myLine -> myLine.contains("package")).findFirst().orElseThrow()
.trim().split(" ")[1].split(";")[0].trim();
return new GithubSource(sourceName, sourcePackage, resultLines);
return new GithubSource(sourceName, sourcePackage, resultLines, new LinkedList<GithubSource>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public CodeGenerationController(CodeGenerationService codeGenerationService) {

@GetMapping("/test")
public GithubSource getGenerateTests(@RequestParam("url") String url) {
return this.codeGenerationService.generateTests(URLDecoder.decode(url, StandardCharsets.UTF_8));
return this.codeGenerationService.generateTests(URLDecoder.decode(url, StandardCharsets.UTF_8), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

import java.util.List;

public record GithubSource(String sourceName, String sourcePackage, List<String> lines) {
public record GithubSource(String sourceName, String sourcePackage, List<String> lines, List<GithubSource> dependencies) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ public CodeGenerationService(GithubClient githubClient) {
this.githubClient = githubClient;
}

public GithubSource generateTests(String url) {
public GithubSource generateTests(String url, final boolean referencedSources) {
final var myUrl = url.replace("https://github.com", GithubClient.GITHUB_BASE_URL).replace("/blob", "");
var result = this.githubClient.readSourceFile(myUrl);
var isComment = new AtomicBoolean(false);
var sourceLines = result.lines().stream().map(myLine -> myLine.replaceAll("[\t]", "").trim())
.filter(myLine -> !myLine.isBlank()).filter(myLine -> filterComments(isComment, myLine)).toList();
final var basePackage = List.of(result.sourcePackage().split("\\.")).stream().limit(2)
.collect(Collectors.joining("."));
var importLines = sourceLines.stream().filter(myLine -> myLine.contains("import"))
var importLines = sourceLines.stream().filter(x -> referencedSources).filter(myLine -> myLine.contains("import"))
.filter(myLine -> myLine.contains(basePackage))
.map(myLine -> String.format("%s%s%s", myUrl.split(basePackage.replace(".", "/"))[0].trim(),
myLine.split("import")[1].split(";")[0].replaceAll("\\.", "/").trim(), ".java"))
.toList();
importLines.forEach(myLine -> LOGGER.info(myLine));
return new GithubSource(result.sourceName(), result.sourcePackage(), sourceLines);
.map(myLine -> this.generateTests(myLine, false)).toList();
// importLines.forEach(myLine -> LOGGER.info(myLine));
return new GithubSource(result.sourceName(), result.sourcePackage(), sourceLines, importLines);
}

private boolean filterComments(AtomicBoolean isComment, String myLine) {
Expand Down

0 comments on commit e61494a

Please sign in to comment.