From 0b56d73cda52eac4853a758169f228c30a15730d Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 21 May 2024 17:31:13 +0200 Subject: [PATCH] Apply formatter and more minor fixes --- .../ai/AgentGenerativeModelClient.java | 33 +++++----- .../java/io/moderne/ai/ClusteringClient.java | 1 - .../io/moderne/ai/EmbeddingModelClient.java | 10 +-- .../io/moderne/ai/FindCommentsLanguage.java | 6 +- .../ai/LanguageDetectorModelClient.java | 11 ++-- .../io/moderne/ai/RelatedModelClient.java | 4 +- .../ai/SpellCheckCommentsInFrench.java | 9 ++- .../ai/SpellCheckCommentsInFrenchPomXml.java | 5 +- .../io/moderne/ai/SpellCheckerClient.java | 8 +-- .../ai/research/FindCodeThatResembles.java | 15 ++--- .../moderne/ai/research/GetCodeEmbedding.java | 28 ++++----- .../ai/research/GetRecommendations.java | 5 +- .../java/io/moderne/ai/table/CodeSearch.java | 6 +- .../SpongeBobCase.java | 2 - .../moderne/ai/EmbeddingModelClientTest.java | 2 +- .../io/moderne/ai/ListAllMethodsUsedTest.java | 34 +++++----- .../SpellCheckCommentsInFrenchPomXmlTest.java | 62 +++++++++---------- .../ai/SpellCheckCommentsInFrenchTest.java | 55 ++++++++-------- .../ai/research/GetCodeEmbeddingTest.java | 32 +++++----- 19 files changed, 163 insertions(+), 165 deletions(-) diff --git a/src/main/java/io/moderne/ai/AgentGenerativeModelClient.java b/src/main/java/io/moderne/ai/AgentGenerativeModelClient.java index 5b73e6c..0d21758 100644 --- a/src/main/java/io/moderne/ai/AgentGenerativeModelClient.java +++ b/src/main/java/io/moderne/ai/AgentGenerativeModelClient.java @@ -14,6 +14,7 @@ * limitations under the License. */ package io.moderne.ai; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -76,7 +77,7 @@ public static synchronized AgentGenerativeModelClient getInstance() { if (INSTANCE == null) { //Check if llama.cpp is already built File f = new File(pathToLLama + "/main"); - if(!(f.exists() && !f.isDirectory()) ) { + if (!(f.exists() && !f.isDirectory())) { //Build llama.cpp StringWriter sw = new StringWriter(); PrintWriter procOut = new PrintWriter(sw); @@ -106,12 +107,13 @@ public static synchronized AgentGenerativeModelClient getInstance() { try { Runtime runtime = Runtime.getRuntime(); Process proc_server = runtime.exec((new String[] - {"/bin/sh", "-c", pathToLLama + "/server -m " + pathToModel + " --port " + port })); + {"/bin/sh", "-c", pathToLLama + "/server -m " + pathToModel + " --port " + port})); - EXECUTOR_SERVICE.submit(() -> {new BufferedReader(new InputStreamReader(proc_server.getInputStream())).lines() - .forEach(procOut::println); - new BufferedReader(new InputStreamReader(proc_server.getErrorStream())).lines() - .forEach(procOut::println); + EXECUTOR_SERVICE.submit(() -> { + new BufferedReader(new InputStreamReader(proc_server.getInputStream())).lines() + .forEach(procOut::println); + new BufferedReader(new InputStreamReader(proc_server.getErrorStream())).lines() + .forEach(procOut::println); }); if (!INSTANCE.checkForUp()) { @@ -130,12 +132,13 @@ public static synchronized AgentGenerativeModelClient getInstance() { private int checkForUpRequest() { try { - HttpResponse response = Unirest.head("http://127.0.0.1:"+port).asString(); + HttpResponse response = Unirest.head("http://127.0.0.1:" + port).asString(); return response.getStatus(); } catch (UnirestException e) { return 523; } } + private boolean checkForUp() { for (int i = 0; i < 60; i++) { try { @@ -152,7 +155,7 @@ private boolean checkForUp() { public static void populateMethodsToSample(String pathToCenters) { HashMap tempMethodsToSample = new HashMap<>(); - try (BufferedReader bufferedReader = new BufferedReader(new FileReader(pathToCenters))){ + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(pathToCenters))) { String line; String source; String methodCall; @@ -183,11 +186,11 @@ public ArrayList getRecommendations(String code) { while ((line = bufferedReader.readLine()) != null) { promptContent.append(line).append("\n"); } - String text = "[INST]" + promptContent + code + "```\n[/INST]1." ; + String text = "[INST]" + promptContent + code + "```\n[/INST]1."; HttpSender http = new HttpUrlConnectionSender(Duration.ofSeconds(20), Duration.ofSeconds(60)); HttpSender.Response raw; - HashMap input = new HashMap<>(); + HashMap input = new HashMap<>(); input.put("stream", false); input.put("prompt", text); input.put("temperature", 0.5); @@ -196,7 +199,7 @@ public ArrayList getRecommendations(String code) { try { raw = http .post("http://127.0.0.1:" + port + "/completion") - .withContent("application/json" , + .withContent("application/json", mapper.writeValueAsBytes(input)).send(); } catch (JsonProcessingException e) { throw new RuntimeException(e); @@ -254,7 +257,7 @@ public boolean isRelated(String query, String code, double threshold) { HttpSender http = new HttpUrlConnectionSender(Duration.ofSeconds(20), Duration.ofSeconds(60)); HttpSender.Response raw; - HashMap input = new HashMap<>(); + HashMap input = new HashMap<>(); input.put("stream", false); input.put("prompt", promptContent); input.put("temperature", 0.0); @@ -265,7 +268,7 @@ public boolean isRelated(String query, String code, double threshold) { try { raw = http .post("http://127.0.0.1:" + port + "/completion") - .withContent("application/json" , + .withContent("application/json", mapper.writeValueAsBytes(input)).send(); } catch (JsonProcessingException e) { @@ -290,9 +293,11 @@ private boolean parseRelated(String s) { return (s.contains("Yes") || s.contains("yes")); } + @Value private static class LlamaResponse { String content; + public String getResponse() { return content; } @@ -315,7 +320,7 @@ public List getCompletionProbabilities() { public boolean isRelated(double threshold) { for (CompletionProbability cp : completionProbabilities) { if (cp.getContent().equals(" Yes")) { - return cp.getProbs().get(0).getProb()>=threshold; + return cp.getProbs().get(0).getProb() >= threshold; } } return false; diff --git a/src/main/java/io/moderne/ai/ClusteringClient.java b/src/main/java/io/moderne/ai/ClusteringClient.java index 45f7410..6b7758e 100644 --- a/src/main/java/io/moderne/ai/ClusteringClient.java +++ b/src/main/java/io/moderne/ai/ClusteringClient.java @@ -168,5 +168,4 @@ public int[] getCenters() { } - } diff --git a/src/main/java/io/moderne/ai/EmbeddingModelClient.java b/src/main/java/io/moderne/ai/EmbeddingModelClient.java index 4ca3ff1..a21f767 100644 --- a/src/main/java/io/moderne/ai/EmbeddingModelClient.java +++ b/src/main/java/io/moderne/ai/EmbeddingModelClient.java @@ -68,11 +68,11 @@ protected boolean removeEldestEntry(java.util.Map.Entry eldest) } } - public static synchronized EmbeddingModelClient getInstance() { + public static synchronized EmbeddingModelClient getInstance() { if (INSTANCE == null) { INSTANCE = new EmbeddingModelClient(); if (INSTANCE.checkForUpRequest() != 200) { - String cmd = String.format("/usr/bin/python3 'import gradio\ngradio.'", MODELS_DIR); + String cmd = "/usr/bin/python3 'import gradio\ngradio.'"; try { Process proc = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", cmd}); } catch (IOException e) { @@ -168,10 +168,10 @@ private static double dist(float[] v1, float[] v2) { float diff = v1[i] - v2[i]; sumOfSquaredDifferences += diff * diff; } - return 1-Math.sqrt(sumOfSquaredDifferences); + return 1 - Math.sqrt(sumOfSquaredDifferences); } - public float[] getEmbedding(String text) { + public float[] getEmbedding(String text) { HttpSender http = new HttpUrlConnectionSender(Duration.ofSeconds(20), Duration.ofSeconds(30)); HttpSender.Response raw = null; @@ -179,7 +179,7 @@ public float[] getEmbedding(String text) { try { raw = http .post("http://127.0.0.1:7860/run/predict") - .withContent("application/json" , mapper.writeValueAsBytes(new EmbeddingModelClient.GradioRequest(text))) + .withContent("application/json", mapper.writeValueAsBytes(new EmbeddingModelClient.GradioRequest(text))) .send(); } catch (JsonProcessingException e) { throw new RuntimeException(e); diff --git a/src/main/java/io/moderne/ai/FindCommentsLanguage.java b/src/main/java/io/moderne/ai/FindCommentsLanguage.java index cdba2b7..82c27d1 100644 --- a/src/main/java/io/moderne/ai/FindCommentsLanguage.java +++ b/src/main/java/io/moderne/ai/FindCommentsLanguage.java @@ -57,9 +57,9 @@ public Space visitSpace(Space space, Space.Location loc, ExecutionContext ctx) { if (comment instanceof TextComment) { JavaSourceFile javaSourceFile = getCursor().firstEnclosing(JavaSourceFile.class); distribution.insertRow(ctx, new LanguageDistribution.Row( - javaSourceFile.getSourcePath().toString(), - ((TextComment) comment).getText(), - LanguageDetectorModelClient.getInstance().getLanguage(((TextComment) comment).getText()).getLanguage() + javaSourceFile.getSourcePath().toString(), + ((TextComment) comment).getText(), + LanguageDetectorModelClient.getInstance().getLanguage(((TextComment) comment).getText()).getLanguage() ) ); diff --git a/src/main/java/io/moderne/ai/LanguageDetectorModelClient.java b/src/main/java/io/moderne/ai/LanguageDetectorModelClient.java index e4bbcf0..a501f4d 100644 --- a/src/main/java/io/moderne/ai/LanguageDetectorModelClient.java +++ b/src/main/java/io/moderne/ai/LanguageDetectorModelClient.java @@ -46,7 +46,7 @@ public class LanguageDetectorModelClient { private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(3); private static final Path MODELS_DIR = Paths.get(System.getProperty("user.home") + "/.moderne/models"); - private ObjectMapper mapper = JsonMapper.builder() + private final ObjectMapper mapper = JsonMapper.builder() .constructorDetector(ConstructorDetector.USE_PROPERTIES_BASED) .build() .registerModule(new ParameterNamesModule()) @@ -68,11 +68,11 @@ protected boolean removeEldestEntry(Map.Entry eldest) { } } - public static synchronized LanguageDetectorModelClient getInstance() { + public static synchronized LanguageDetectorModelClient getInstance() { if (INSTANCE == null) { INSTANCE = new LanguageDetectorModelClient(); if (INSTANCE.checkForUpRequest() != 200) { - String cmd = String.format("/usr/bin/python3 'import gradio\ngradio.'", MODELS_DIR); + String cmd = "/usr/bin/python3 'import gradio\ngradio.'"; try { Process proc = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", cmd}); } catch (IOException e) { @@ -153,7 +153,7 @@ private Function timeLanguage(List timings) { } - public String getLanguageGradio(String text) { + public String getLanguageGradio(String text) { HttpSender http = new HttpUrlConnectionSender(Duration.ofSeconds(20), Duration.ofSeconds(30)); @@ -162,7 +162,7 @@ public String getLanguageGradio(String text) { try { raw = http .post("http://127.0.0.1:7861/run/predict") - .withContent("application/json" , + .withContent("application/json", mapper.writeValueAsBytes(new LanguageDetectorModelClient.GradioRequest(new String[]{text}))) .send(); } catch (JsonProcessingException e) { @@ -191,6 +191,7 @@ private static class GradioRequest { @Value private static class GradioResponse { String[] data; + public String getLanguage() { return data[0]; } diff --git a/src/main/java/io/moderne/ai/RelatedModelClient.java b/src/main/java/io/moderne/ai/RelatedModelClient.java index aac0bd2..61a0690 100644 --- a/src/main/java/io/moderne/ai/RelatedModelClient.java +++ b/src/main/java/io/moderne/ai/RelatedModelClient.java @@ -55,11 +55,11 @@ protected boolean removeEldestEntry(java.util.Map.Entry eldest } } - public static synchronized RelatedModelClient getInstance() { + public static synchronized RelatedModelClient getInstance() { if (INSTANCE == null) { INSTANCE = new RelatedModelClient(); if (INSTANCE.checkForUpRequest() != 200) { - String cmd = String.format("/usr/bin/python3 'import gradio\ngradio.'", MODELS_DIR); + String cmd = "/usr/bin/python3 'import gradio\ngradio.'"; try { Process proc = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", cmd}); } catch (IOException e) { diff --git a/src/main/java/io/moderne/ai/SpellCheckCommentsInFrench.java b/src/main/java/io/moderne/ai/SpellCheckCommentsInFrench.java index 0d4420a..66a25dd 100644 --- a/src/main/java/io/moderne/ai/SpellCheckCommentsInFrench.java +++ b/src/main/java/io/moderne/ai/SpellCheckCommentsInFrench.java @@ -55,8 +55,8 @@ public Javadoc visitDocComment(Javadoc.DocComment javadoc, ExecutionContext ctx) dc = dc.withBody(ListUtils.map(dc.getBody(), docLine -> { if (docLine instanceof Javadoc.Text) { String commentText = ((Javadoc.Text) docLine).getText(); - if (!commentText.trim().isEmpty() && LanguageDetectorModelClient.getInstance() - .getLanguage(commentText).getLanguage().equals("fr")) { + if (!commentText.trim().isEmpty() && "fr".equals(LanguageDetectorModelClient.getInstance() + .getLanguage(commentText).getLanguage())) { String fixedComment = SpellCheckerClient.getInstance().getCommentGradio(commentText); if (!fixedComment.equals(commentText)) { docLine = ((Javadoc.Text) docLine).withText(fixedComment); @@ -78,9 +78,8 @@ public Space visitSpace(Space space, Space.Location loc, ExecutionContext ctx) { if (c instanceof TextComment) { TextComment tc = (TextComment) c; String commentText = tc.getText(); - if (!commentText.isEmpty() && LanguageDetectorModelClient.getInstance() - .getLanguage(commentText).getLanguage().equals("fr") - ) { + if (!commentText.isEmpty() && "fr".equals(LanguageDetectorModelClient.getInstance() + .getLanguage(commentText).getLanguage())) { String fixedComment = SpellCheckerClient.getInstance().getCommentGradio(commentText); if (!fixedComment.equals(commentText)) { return tc.withText(fixedComment); diff --git a/src/main/java/io/moderne/ai/SpellCheckCommentsInFrenchPomXml.java b/src/main/java/io/moderne/ai/SpellCheckCommentsInFrenchPomXml.java index cd4cfb1..670d209 100644 --- a/src/main/java/io/moderne/ai/SpellCheckCommentsInFrenchPomXml.java +++ b/src/main/java/io/moderne/ai/SpellCheckCommentsInFrenchPomXml.java @@ -43,9 +43,8 @@ public TreeVisitor getVisitor() { @Override public Xml.Comment visitComment(Xml.Comment comment, ExecutionContext ctx) { String commentText = comment.getText(); - if (!commentText.isEmpty() && LanguageDetectorModelClient.getInstance() - .getLanguage(commentText).getLanguage().equals("fr") - ) { + if (!commentText.isEmpty() && "fr".equals(LanguageDetectorModelClient.getInstance() + .getLanguage(commentText).getLanguage())) { String fixedComment = SpellCheckerClient.getInstance().getCommentGradio(commentText); if (!fixedComment.equals(commentText)) { return comment.withText(fixedComment); diff --git a/src/main/java/io/moderne/ai/SpellCheckerClient.java b/src/main/java/io/moderne/ai/SpellCheckerClient.java index 561b784..92e98e8 100644 --- a/src/main/java/io/moderne/ai/SpellCheckerClient.java +++ b/src/main/java/io/moderne/ai/SpellCheckerClient.java @@ -61,7 +61,7 @@ public class SpellCheckerClient { } } - public static synchronized SpellCheckerClient getInstance() { + public static synchronized SpellCheckerClient getInstance() { if (INSTANCE == null) { INSTANCE = new SpellCheckerClient(); if (INSTANCE.checkForUpRequest() != 200) { @@ -121,8 +121,7 @@ private int checkForUpRequest() { } - - public String getCommentGradio(String text) { + public String getCommentGradio(String text) { HttpSender http = new HttpUrlConnectionSender(Duration.ofSeconds(20), Duration.ofSeconds(30)); HttpSender.Response raw = null; @@ -130,7 +129,7 @@ public String getCommentGradio(String text) { try { raw = http .post("http://127.0.0.1:7866/run/predict") - .withContent("application/json" , + .withContent("application/json", mapper.writeValueAsBytes(new SpellCheckerClient.GradioRequest(new String[]{text}))) .send(); } catch (JsonProcessingException e) { @@ -159,6 +158,7 @@ private static class GradioRequest { @Value private static class GradioResponse { String[] data; + public String getSpellCheck() { return data[0]; } diff --git a/src/main/java/io/moderne/ai/research/FindCodeThatResembles.java b/src/main/java/io/moderne/ai/research/FindCodeThatResembles.java index bc790a2..675654c 100644 --- a/src/main/java/io/moderne/ai/research/FindCodeThatResembles.java +++ b/src/main/java/io/moderne/ai/research/FindCodeThatResembles.java @@ -121,8 +121,6 @@ public Accumulator getInitialValue(ExecutionContext ctx) { public TreeVisitor getScanner(Accumulator acc) { return new JavaIsoVisitor() { - - private String extractTypeName(String fullyQualifiedTypeName) { return fullyQualifiedTypeName.replace("<.*>", "") .substring(fullyQualifiedTypeName.lastIndexOf('.') + 1); @@ -133,20 +131,20 @@ private String extractTypeName(String fullyQualifiedTypeName) { public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) { cu.getTypesInUse().getUsedMethods().forEach(type -> { String methodSignature = extractTypeName(Optional.ofNullable(type.getReturnType()) - .map(Object::toString).orElse("")) + " " + type.getName() ; + .map(Object::toString).orElse("")) + " " + type.getName(); String[] parameters = new String[type.getParameterTypes().size()]; for (int i = 0; i < type.getParameterTypes().size(); i++) { String typeName = extractTypeName(type.getParameterTypes().get(i).toString()); String paramName = type.getParameterNames().get(i); - parameters[i] = typeName + " " + paramName ; + parameters[i] = typeName + " " + paramName; } - methodSignature += "(" + String.join(", ", parameters) + ")"; + methodSignature += "(" + String.join(", ", parameters) + ")"; String methodPattern = Optional.ofNullable(type.getDeclaringType()).map(Object::toString) - .orElse("") + " " + type.getName() + "(..)"; + .orElse("") + " " + type.getName() + "(..)"; acc.add(methodSignature, methodPattern, resembles); }); @@ -170,8 +168,7 @@ public TreeVisitor getVisitor(Accumulator acc) { @Override public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) { - boolean acceptable = sourceFile instanceof J.CompilationUnit; - return acceptable; + return sourceFile instanceof J.CompilationUnit; } @Override @@ -236,7 +233,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu method.printTrimmed(getCursor()), resembles, resultEmbeddingModels, - calledGenerativeModel ? ( result ? 1 : -1) : 0 + calledGenerativeModel ? (result ? 1 : -1) : 0 )); } diff --git a/src/main/java/io/moderne/ai/research/GetCodeEmbedding.java b/src/main/java/io/moderne/ai/research/GetCodeEmbedding.java index 51e4c1f..abb7e21 100644 --- a/src/main/java/io/moderne/ai/research/GetCodeEmbedding.java +++ b/src/main/java/io/moderne/ai/research/GetCodeEmbedding.java @@ -27,7 +27,6 @@ import org.openrewrite.java.tree.J; import org.openrewrite.java.tree.JavaSourceFile; - @Value @EqualsAndHashCode(callSuper = false) public class GetCodeEmbedding extends Recipe { @@ -54,7 +53,7 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { - if ("methods".equals(codeSnippetType)){ + if ("methods".equals(codeSnippetType)) { return new JavaIsoVisitor() { @Override public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) { @@ -62,23 +61,22 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex // Get embedding JavaSourceFile javaSourceFile = getCursor().firstEnclosing(JavaSourceFile.class); float[] embedding = EmbeddingModelClient.getInstance().getEmbedding(md.printTrimmed(getCursor())); - String s = javaSourceFile.getSourcePath().toString(); embeddings.insertRow(ctx, new Embeddings.Row(javaSourceFile.getSourcePath().toString(), md.getSimpleName(), embedding)); return md; } }; - } else{ - return new JavaIsoVisitor() { - @Override - public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration clazz, ExecutionContext ctx) { - J.ClassDeclaration cd = getCursor().firstEnclosing(J.ClassDeclaration.class); - // Get embedding - JavaSourceFile javaSourceFile = getCursor().firstEnclosing(JavaSourceFile.class); - float[] embedding = EmbeddingModelClient.getInstance().getEmbedding(cd.printTrimmed(getCursor())); - embeddings.insertRow(ctx, new Embeddings.Row(javaSourceFile.getSourcePath().toString(), cd.getSimpleName(), embedding)); - return cd; - } - }; + } else { + return new JavaIsoVisitor() { + @Override + public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration clazz, ExecutionContext ctx) { + J.ClassDeclaration cd = getCursor().firstEnclosing(J.ClassDeclaration.class); + // Get embedding + JavaSourceFile javaSourceFile = getCursor().firstEnclosing(JavaSourceFile.class); + float[] embedding = EmbeddingModelClient.getInstance().getEmbedding(cd.printTrimmed(getCursor())); + embeddings.insertRow(ctx, new Embeddings.Row(javaSourceFile.getSourcePath().toString(), cd.getSimpleName(), embedding)); + return cd; + } + }; } diff --git a/src/main/java/io/moderne/ai/research/GetRecommendations.java b/src/main/java/io/moderne/ai/research/GetRecommendations.java index e30d83e..d57a3fa 100644 --- a/src/main/java/io/moderne/ai/research/GetRecommendations.java +++ b/src/main/java/io/moderne/ai/research/GetRecommendations.java @@ -76,6 +76,7 @@ public class Accumulator { List methods = new ArrayList<>(); List embeddings = new ArrayList<>(); + @Nullable int[] centers; public int[] getCenters(int numberOfCenters) { @@ -139,8 +140,8 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex } else { for (Method methodToSample : acc.getMethodsToSample(numberOfCenters)) { if (methodToSample.file.equals(source) && - methodToSample.name.equals(md.getSimpleName()) && - methodToSample.method.equals(md.printTrimmed(getCursor()))) { + methodToSample.name.equals(md.getSimpleName()) && + methodToSample.method.equals(md.printTrimmed(getCursor()))) { isMethodToSample = true; break; } diff --git a/src/main/java/io/moderne/ai/table/CodeSearch.java b/src/main/java/io/moderne/ai/table/CodeSearch.java index cad5386..644539c 100644 --- a/src/main/java/io/moderne/ai/table/CodeSearch.java +++ b/src/main/java/io/moderne/ai/table/CodeSearch.java @@ -45,13 +45,13 @@ public static class Row { @Column(displayName = "Result of first models", description = "First two embeddings models result," + - " where -1 means negative match, 0 means unsure, and 1 means positive match.") + " where -1 means negative match, 0 means unsure, and 1 means positive match.") int resultEmbedding; @Column(displayName = "Result of second model", description = "Second generative model's result," + - " where -1 means negative match and 1 means positive match. " + - "If the model was never queried, then the result is 0.") + " where -1 means negative match and 1 means positive match. " + + "If the model was never queried, then the result is 0.") int resultGenerative; } } diff --git a/src/main/java/io/moderne/transposeCapitalization/SpongeBobCase.java b/src/main/java/io/moderne/transposeCapitalization/SpongeBobCase.java index 02d71c0..ff45e9d 100644 --- a/src/main/java/io/moderne/transposeCapitalization/SpongeBobCase.java +++ b/src/main/java/io/moderne/transposeCapitalization/SpongeBobCase.java @@ -76,8 +76,6 @@ public Space visitSpace(Space space, Space.Location loc, ExecutionContext ctx) { return comment; })); } - }; } - } diff --git a/src/test/java/io/moderne/ai/EmbeddingModelClientTest.java b/src/test/java/io/moderne/ai/EmbeddingModelClientTest.java index 5e12bfe..1cd6647 100644 --- a/src/test/java/io/moderne/ai/EmbeddingModelClientTest.java +++ b/src/test/java/io/moderne/ai/EmbeddingModelClientTest.java @@ -26,7 +26,7 @@ class EmbeddingModelClientTest { @Test void start() { EmbeddingModelClient client = EmbeddingModelClient.getInstance(); - assertThat(client.getEmbedding("test").length>0); + assertThat(client.getEmbedding("test").length > 0); String a = ""; } } diff --git a/src/test/java/io/moderne/ai/ListAllMethodsUsedTest.java b/src/test/java/io/moderne/ai/ListAllMethodsUsedTest.java index 95e70af..cf685d7 100644 --- a/src/test/java/io/moderne/ai/ListAllMethodsUsedTest.java +++ b/src/test/java/io/moderne/ai/ListAllMethodsUsedTest.java @@ -34,23 +34,23 @@ public void defaults(RecipeSpec spec) { @Test void listMethods() { rewriteRun( - spec -> spec.dataTable(MethodInUse.Row.class, - methods -> assertThat(methods).hasSize(2) - .anySatisfy(row -> assertThat(row.getMethodName()).isEqualTo("println")) - .anySatisfy(row -> assertThat(row.getMethodName()).isEqualTo("method1"))), - //language=java - java( - """ - class A { - void method1(){ - System.out.println("Hello"); - } - void method2(){ - method1(); - } - } - """ - ) + spec -> spec.dataTable(MethodInUse.Row.class, + methods -> assertThat(methods).hasSize(2) + .anySatisfy(row -> assertThat(row.getMethodName()).isEqualTo("println")) + .anySatisfy(row -> assertThat(row.getMethodName()).isEqualTo("method1"))), + //language=java + java( + """ + class A { + void method1(){ + System.out.println("Hello"); + } + void method2(){ + method1(); + } + } + """ + ) ); } } diff --git a/src/test/java/io/moderne/ai/SpellCheckCommentsInFrenchPomXmlTest.java b/src/test/java/io/moderne/ai/SpellCheckCommentsInFrenchPomXmlTest.java index b658d4c..05e89b9 100644 --- a/src/test/java/io/moderne/ai/SpellCheckCommentsInFrenchPomXmlTest.java +++ b/src/test/java/io/moderne/ai/SpellCheckCommentsInFrenchPomXmlTest.java @@ -40,37 +40,37 @@ void pom() { ), pomXml( """ - - 4.0.0 - com.mycompany.app - my-app - 1 - - - - com.google.guava - guava - 29.0-jre - - - - """, - """ - - 4.0.0 - com.mycompany.app - my-app - 1 - - - - com.google.guava - guava - 29.0-jre - - - - """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + + + com.google.guava + guava + 29.0-jre + + + + """, + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + + + com.google.guava + guava + 29.0-jre + + + + """ ) ); } diff --git a/src/test/java/io/moderne/ai/SpellCheckCommentsInFrenchTest.java b/src/test/java/io/moderne/ai/SpellCheckCommentsInFrenchTest.java index 1916ed9..bdf3795 100644 --- a/src/test/java/io/moderne/ai/SpellCheckCommentsInFrenchTest.java +++ b/src/test/java/io/moderne/ai/SpellCheckCommentsInFrenchTest.java @@ -90,12 +90,12 @@ void test() { } """, """ - class Test { - void test() { - // c'est une valeur simplifié - } - } - """ + class Test { + void test() { + // c'est une valeur simplifié + } + } + """ ) ); } @@ -114,30 +114,31 @@ void test() { } """, """ - class Test { - void test() { - // Gérer la variable - } - } - """ + class Test { + void test() { + // Gérer la variable + } + } + """ ) ); } - @Test - void questionMarkAlone() { - rewriteRun( - spec -> spec.parser(JavaParser.fromJavaVersion()), - //language=java - java( - """ - class Test { - void test() { - // C'est quoi ça ? C'est quoi? - // C'est quoi ça ? - } + + @Test + void questionMarkAlone() { + rewriteRun( + spec -> spec.parser(JavaParser.fromJavaVersion()), + //language=java + java( + """ + class Test { + void test() { + // C'est quoi ça ? C'est quoi? + // C'est quoi ça ? } - """) - ); + } + """) + ); } @Test @@ -164,7 +165,7 @@ void test() { } } """ - ) + ) ); } diff --git a/src/test/java/io/moderne/ai/research/GetCodeEmbeddingTest.java b/src/test/java/io/moderne/ai/research/GetCodeEmbeddingTest.java index 193e984..3e0b0e7 100644 --- a/src/test/java/io/moderne/ai/research/GetCodeEmbeddingTest.java +++ b/src/test/java/io/moderne/ai/research/GetCodeEmbeddingTest.java @@ -26,29 +26,29 @@ class GetCodeEmbeddingTest implements RewriteTest { @Test void methods() { - rewriteRun( spec -> spec.recipe(new GetCodeEmbedding("methods")), + rewriteRun(spec -> spec.recipe(new GetCodeEmbedding("methods")), java( - """ - public class Foo { - public void hello(){ - System.out.println("hello"); - } - } - """) + """ + public class Foo { + public void hello(){ + System.out.println("hello"); + } + } + """) ); } @Test void classes() { - rewriteRun( spec -> spec.recipe(new GetCodeEmbedding("classes")), + rewriteRun(spec -> spec.recipe(new GetCodeEmbedding("classes")), java( - """ - public class Foo { - public void hello(){ - System.out.println("hello"); - } - } - """) + """ + public class Foo { + public void hello(){ + System.out.println("hello"); + } + } + """) ); } }