From 118b0b60daba999fb0634d0390b87540e8984fe3 Mon Sep 17 00:00:00 2001 From: zhangzhiyong Date: Thu, 16 Nov 2023 17:56:08 +0800 Subject: [PATCH] Add test class --- .../src/test/java/run/mone/openapi/OpenApiTest.java | 2 +- .../java/run/mone/processor/common/CodeUtils.java | 4 ++-- .../java/run/mone/processor/test/JavaPoetTest.java | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/jcommon/openai/src/test/java/run/mone/openapi/OpenApiTest.java b/jcommon/openai/src/test/java/run/mone/openapi/OpenApiTest.java index c37f33d55..0bdcdaba0 100644 --- a/jcommon/openai/src/test/java/run/mone/openapi/OpenApiTest.java +++ b/jcommon/openai/src/test/java/run/mone/openapi/OpenApiTest.java @@ -178,7 +178,7 @@ public void onEvent(String str) { public void end() { latch.countDown(); } - }); + }, ReqConfig.builder().model("gpt-4-1106-preview").build()); latch.await(); } diff --git a/jcommon/processor/src/main/java/run/mone/processor/common/CodeUtils.java b/jcommon/processor/src/main/java/run/mone/processor/common/CodeUtils.java index 8e2909bc6..4fc012660 100644 --- a/jcommon/processor/src/main/java/run/mone/processor/common/CodeUtils.java +++ b/jcommon/processor/src/main/java/run/mone/processor/common/CodeUtils.java @@ -77,7 +77,7 @@ public static String modifyCode(String filePath, String className, List newStatements = javaParser.parseBlock("{" + newCode.toString() + "}").getResult().get().getStatements(); - // 在方法的开头插入新代码 + //Insert new code at the beginning of the method. method.getBody().ifPresent(body -> { NodeList statements = body.getStatements(); statements.addAll(0, newStatements); @@ -91,7 +91,6 @@ public static String modifyCode(String filePath, String className, List readImports(String code) { CharSource source = CharSource.wrap(code); String output = null; @@ -145,6 +144,7 @@ public static String removeImports(String code) { /** * 是否是class + * * @param code * @return */ diff --git a/jcommon/processor/src/test/java/run/mone/processor/test/JavaPoetTest.java b/jcommon/processor/src/test/java/run/mone/processor/test/JavaPoetTest.java index 329160516..912c295dc 100644 --- a/jcommon/processor/src/test/java/run/mone/processor/test/JavaPoetTest.java +++ b/jcommon/processor/src/test/java/run/mone/processor/test/JavaPoetTest.java @@ -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() {