Skip to content

Commit

Permalink
Add test class
Browse files Browse the repository at this point in the history
  • Loading branch information
goodjava committed Nov 16, 2023
1 parent 89cf871 commit 118b0b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void onEvent(String str) {
public void end() {
latch.countDown();
}
});
}, ReqConfig.builder().model("gpt-4-1106-preview").build());
latch.await();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static String modifyCode(String filePath, String className, List<MethodCo
codeBlockBuilder.addStatement(mm.getCode());
CodeBlock newCode = codeBlockBuilder.build();
NodeList<Statement> newStatements = javaParser.parseBlock("{" + newCode.toString() + "}").getResult().get().getStatements();
// 在方法的开头插入新代码
//Insert new code at the beginning of the method.
method.getBody().ifPresent(body -> {
NodeList<Statement> statements = body.getStatements();
statements.addAll(0, newStatements);
Expand All @@ -91,7 +91,6 @@ public static String modifyCode(String filePath, String className, List<MethodCo
}



public static List<String> readImports(String code) {
CharSource source = CharSource.wrap(code);
String output = null;
Expand Down Expand Up @@ -145,6 +144,7 @@ public static String removeImports(String code) {

/**
* 是否是class
*
* @param code
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ public void testParse() {
System.out.println(cu.getType(0).getName().getIdentifier());
}

@SneakyThrows
@Test
public void testParseClass() {
JavaParser javaParser = new JavaParser();
CompilationUnit cu = javaParser.parse(new File("/tmp/e")).getResult().get();
cu.findAll(ClassOrInterfaceDeclaration.class).stream().limit(300).forEach(c->{
System.out.println(c.getName());
System.out.println(c);
System.out.println("-------");
});
}


@Test
public void test0() {
Expand Down

0 comments on commit 118b0b6

Please sign in to comment.