mirror of
https://github.com/giancarloerra/socraticode.git
synced 2026-07-03 14:05:21 +02:00
fix: cover JVM annotation and Scala callable edge cases
This commit is contained in:
@@ -532,7 +532,9 @@ function extractFromJvm(
|
||||
function stripJvmAnnotations(text: string): string {
|
||||
return text
|
||||
.split("\n")
|
||||
.filter((line) => !line.trim().startsWith("@"))
|
||||
.map((line) =>
|
||||
line.replace(/^\s*(?:@(?:[\w$]+:)?[\w$.]+(?:\([^)]*\))?\s*)+/, "")
|
||||
)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
@@ -551,6 +553,10 @@ function extractJvmCallableName(text: string): string | null {
|
||||
.split("{", 1)[0]
|
||||
.split("=", 1)[0]
|
||||
.trim();
|
||||
const scalaDefMatches = Array.from(signature.matchAll(/\bdef\s+([A-Za-z_$][\w$]*)\b/g));
|
||||
if (scalaDefMatches.length > 0) {
|
||||
return scalaDefMatches[scalaDefMatches.length - 1][1];
|
||||
}
|
||||
const matches = Array.from(signature.matchAll(/([A-Za-z_$][\w$]*)\s*\(/g));
|
||||
return matches.length > 0 ? matches[matches.length - 1][1] : null;
|
||||
}
|
||||
|
||||
@@ -184,6 +184,19 @@ class SecurityAuthClientRequireSubjectTest {
|
||||
expect(names).not.toContain("Test");
|
||||
});
|
||||
|
||||
it("preserves Java declarations when annotations share the same line", () => {
|
||||
const src = `
|
||||
class InlineAnnotationTest {
|
||||
@Test void cleanup() {}
|
||||
}
|
||||
`;
|
||||
const out = extractSymbolsAndCalls(src, "java" as unknown as Lang, ".java", "InlineAnnotationTest.java");
|
||||
const names = out.symbols.map((s) => s.name);
|
||||
expect(names).toContain("InlineAnnotationTest");
|
||||
expect(names).toContain("cleanup");
|
||||
expect(names).not.toContain("Test");
|
||||
});
|
||||
|
||||
it("extracts Kotlin top-level fun and class methods", () => {
|
||||
const src = `
|
||||
fun greet(name: String): String = "Hi"
|
||||
@@ -203,6 +216,8 @@ class Bar {
|
||||
const src = `
|
||||
class Foo {
|
||||
def bar(): Int = 1
|
||||
def size: Int = 1
|
||||
def now = Instant.now()
|
||||
}
|
||||
|
||||
object Main {
|
||||
@@ -212,6 +227,8 @@ object Main {
|
||||
const out = extractSymbolsAndCalls(src, "scala" as unknown as Lang, ".scala", "Main.scala");
|
||||
const names = out.symbols.map((s) => s.name);
|
||||
expect(names).toContain("bar");
|
||||
expect(names).toContain("size");
|
||||
expect(names).toContain("now");
|
||||
expect(names).toContain("main");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user