Skip to content

Commit b78bf02

Browse files
committed
Code Refactoring
1 parent 71ee728 commit b78bf02

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎src/main/java/liquidjava/mcp/runtime/AnalysisKey.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public static AnalysisKey read(String input, boolean debug) throws IOException {
3030
private static List<Path> sourceFiles(Path path) throws IOException {
3131
if (!Files.isDirectory(path)) return List.of(path);
3232
try (Stream<Path> paths = Files.walk(path, FileVisitOption.FOLLOW_LINKS)) {
33-
return paths.filter(Files::isRegularFile)
34-
.filter(file -> file.toString().endsWith(".java"))
35-
.sorted().toList();
33+
return paths.filter(PathUtils::isJavaSourceFile).sorted().toList();
3634
} catch (UncheckedIOException e) {
3735
throw e.getCause();
3836
}

‎src/main/java/liquidjava/mcp/runtime/LiquidJavaRunner.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public final class LiquidJavaRunner {
2727
1, Thread.ofPlatform().daemon().name("liquidjava-runner").factory());
2828
static {
2929
EXECUTOR.setRemoveOnCancelPolicy(true);
30-
};
30+
}
3131
private static CachedAnalysis cachedAnalysis;
3232
private record CachedAnalysis(AnalysisKey key, String output) {}
3333

‎src/main/java/liquidjava/mcp/tools/verification/VerifyRequest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public record VerifyRequest(String path, boolean debug) {
99
public VerifyRequest {
1010
Path source = PathUtils.requireExisting(path);
11-
if (!Files.isDirectory(source) && (!Files.isRegularFile(source) || !source.getFileName().toString().endsWith(".java")))
11+
if (!Files.isDirectory(source) && !PathUtils.isJavaSourceFile(source))
1212
throw new IllegalArgumentException("path must be a Java source file or directory");
1313
}
1414

‎src/main/java/liquidjava/mcp/utils/PathUtils.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ public static Path requireExistingJavaFile(String value, String name) {
3333
} catch (IOException e) {
3434
throw new IllegalArgumentException(name + " must be an existing Java source file", e);
3535
}
36-
if (!Files.isRegularFile(source) || !source.getFileName().toString().endsWith(".java"))
36+
if (!isJavaSourceFile(source))
3737
throw new IllegalArgumentException(name + " must be an existing Java source file");
3838
return source;
3939
}
4040

41+
public static boolean isJavaSourceFile(Path path) {
42+
return path != null && Files.isRegularFile(path) && path.getFileName().toString().endsWith(".java");
43+
}
44+
4145
public static Path canonicalPath(String path) throws IOException {
4246
return Path.of(path).toRealPath();
4347
}

0 commit comments

Comments
 (0)