diff options
author | George Fraser <george@fivetran.com> | 2019-01-02 23:24:55 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2019-01-02 23:24:55 -0800 |
commit | c89a5187264bd93c85c5cdb3060d289a72399aeb (patch) | |
tree | f4b724b6dfa80519d09fadd50a2eca0612af8a20 /src/test | |
parent | ad06e0d42d72160502790188d0a8c5fe3a09bdf3 (diff) | |
download | java-language-server-c89a5187264bd93c85c5cdb3060d289a72399aeb.zip |
Allow virtual references and definitions
Diffstat (limited to 'src/test')
4 files changed, 50 insertions, 63 deletions
diff --git a/src/test/java/org/javacs/FindReferencesTest.java b/src/test/java/org/javacs/FindReferencesTest.java index 9ce21c7..e728cc9 100644 --- a/src/test/java/org/javacs/FindReferencesTest.java +++ b/src/test/java/org/javacs/FindReferencesTest.java @@ -37,6 +37,12 @@ public class FindReferencesTest { } @Test + public void findInterfaceReference() { + assertThat( + items("/org/javacs/example/GotoImplementation.java", 14, 26), contains("GotoImplementation.java(5)")); + } + + @Test public void findConstructorReferences() { assertThat(items("/org/javacs/example/ConstructorRefs.java", 4, 10), contains("ConstructorRefs.java(9)")); } diff --git a/src/test/java/org/javacs/GotoTest.java b/src/test/java/org/javacs/GotoTest.java index 7ad39ea..ac5d1cc 100644 --- a/src/test/java/org/javacs/GotoTest.java +++ b/src/test/java/org/javacs/GotoTest.java @@ -10,6 +10,7 @@ import org.javacs.lsp.*; import org.junit.Ignore; import org.junit.Test; +// TODO change :n to (n) public class GotoTest { private static final String file = "/org/javacs/example/Goto.java"; private static final String defaultConstructorFile = "/org/javacs/example/GotoDefaultConstructor.java"; @@ -18,91 +19,91 @@ public class GotoTest { public void localVariable() { var suggestions = doGoto(file, 10, 9); - assertThat(suggestions, contains("Goto.java:5")); + assertThat(suggestions, hasItem("Goto.java:5")); } @Test public void defaultConstructor() { var suggestions = doGoto(defaultConstructorFile, 5, 46); - assertThat(suggestions, contains("GotoDefaultConstructor.java:3")); + assertThat(suggestions, hasItem("GotoDefaultConstructor.java:3")); } @Test public void constructor() { var suggestions = doGoto(file, 11, 21); - assertThat(suggestions, contains("Goto.java:3")); + assertThat(suggestions, hasItem("Goto.java:3")); } @Test public void className() { var suggestions = doGoto(file, 16, 9); - assertThat(suggestions, contains("Goto.java:3")); + assertThat(suggestions, hasItem("Goto.java:3")); } @Test public void staticField() { var suggestions = doGoto(file, 13, 22); - assertThat(suggestions, contains("Goto.java:36")); + assertThat(suggestions, hasItem("Goto.java:36")); } @Test public void field() { var suggestions = doGoto(file, 14, 22); - assertThat(suggestions, contains("Goto.java:37")); + assertThat(suggestions, hasItem("Goto.java:37")); } @Test public void staticMethod() { var suggestions = doGoto(file, 16, 14); - assertThat(suggestions, contains("Goto.java:38")); + assertThat(suggestions, hasItem("Goto.java:38")); } @Test public void method() { var suggestions = doGoto(file, 17, 14); - assertThat(suggestions, contains("Goto.java:41")); + assertThat(suggestions, hasItem("Goto.java:41")); } @Test public void staticMethodReference() { var suggestions = doGoto(file, 19, 27); - assertThat(suggestions, contains("Goto.java:38")); + assertThat(suggestions, hasItem("Goto.java:38")); } @Test public void methodReference() { var suggestions = doGoto(file, 20, 27); - assertThat(suggestions, contains("Goto.java:41")); + assertThat(suggestions, hasItem("Goto.java:41")); } @Test public void otherStaticMethod() { var suggestions = doGoto(file, 29, 25); - assertThat(suggestions, contains(startsWith("GotoOther.java:"))); + assertThat(suggestions, hasItem(startsWith("GotoOther.java:"))); } @Test public void otherMethod() { var suggestions = doGoto(file, 30, 18); - assertThat(suggestions, contains(startsWith("GotoOther.java:"))); + assertThat(suggestions, hasItem(startsWith("GotoOther.java:"))); } @Test public void otherCompiledFile() { var suggestions = doGoto(file, 29, 25); - assertThat(suggestions, contains(startsWith("GotoOther.java:"))); + assertThat(suggestions, hasItem(startsWith("GotoOther.java:"))); } @Test @@ -110,7 +111,7 @@ public class GotoTest { public void typeParam() { var suggestions = doGoto(file, 46, 12); - assertThat(suggestions, contains("Goto.java:3")); + assertThat(suggestions, hasItem("Goto.java:3")); } @Test @@ -125,18 +126,25 @@ public class GotoTest { public void gotoOverload() { String file = "/org/javacs/example/GotoOverload.java"; - assertThat(doGoto(file, 7, 12), contains("GotoOverload.java:4")); - assertThat(doGoto(file, 8, 12), contains("GotoOverload.java:12")); - assertThat(doGoto(file, 9, 12), contains("GotoOverload.java:16")); + assertThat(doGoto(file, 7, 12), hasItem("GotoOverload.java:4")); + assertThat(doGoto(file, 8, 12), hasItem("GotoOverload.java:12")); + assertThat(doGoto(file, 9, 12), hasItem("GotoOverload.java:16")); } @Test public void gotoOverloadInOtherFile() { String file = "/org/javacs/example/GotoOverloadInOtherFile.java"; - assertThat(doGoto(file, 5, 25), contains("GotoOverload.java:4")); - assertThat(doGoto(file, 6, 25), contains("GotoOverload.java:12")); - assertThat(doGoto(file, 7, 25), contains("GotoOverload.java:16")); + assertThat(doGoto(file, 5, 25), hasItem("GotoOverload.java:4")); + assertThat(doGoto(file, 6, 25), hasItem("GotoOverload.java:12")); + assertThat(doGoto(file, 7, 25), hasItem("GotoOverload.java:16")); + } + + @Test + public void gotoImplementation() { + String file = "/org/javacs/example/GotoImplementation.java"; + + assertThat(doGoto(file, 5, 18), hasItems("GotoImplementation.java:9", "GotoImplementation.java:14")); } private static final JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer(); diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java index 0785acb..c947bde 100644 --- a/src/test/java/org/javacs/JavaCompilerServiceTest.java +++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java @@ -226,49 +226,6 @@ public class JavaCompilerServiceTest { assertThat(names, hasItem("concurrent")); } - /* - @Test - public void gotoDefinition() { - var def = - compiler.definition("/GotoDefinition.java"; - assertTrue(def.isPresent()); - - var t = def.get(); - var unit = t.getCompilationUnit(); - assertThat(unit.getSourceFile().getName(), endsWith("GotoDefinition.java")); - - var trees = compiler.trees(); - var pos = trees.getSourcePositions(); - var lines = unit.getLineMap(); - long start = pos.getStartPosition(unit, t.getLeaf()); - long line = lines.getLineNumber(start); - assertThat(line, equalTo(6L)); - } - */ - - @Test - public void references() { - var file = "GotoDefinition.java"; - var to = compiler.compileFocus(resourceUri(file), contents(file), 6, 13).element(); - var possible = compiler.potentialReferences(to); - assertThat( - "GotoDefinition.java can have references to itself", - possible, - hasItem(hasToString(endsWith("/GotoDefinition.java")))); - - var batch = compiler.compileBatch(possible); - var refs = batch.references(to); - var stringify = new ArrayList<String>(); - for (var r : refs) { - var uri = r.getCompilationUnit().getSourceFile().toUri(); - var fileName = Paths.get(uri).getFileName(); - var range = batch.range(r).get(); - stringify.add(String.format("%s:%d", fileName, range.start.line + 1)); - } - assertThat(stringify, hasItem("GotoDefinition.java:3")); - assertThat(stringify, not(hasItem("GotoDefinition.java:6"))); - } - @Test public void overloads() { var uri = resourceUri("Overloads.java"); diff --git a/src/test/test-project/workspace/src/org/javacs/example/GotoImplementation.java b/src/test/test-project/workspace/src/org/javacs/example/GotoImplementation.java new file mode 100644 index 0000000..e1a0798 --- /dev/null +++ b/src/test/test-project/workspace/src/org/javacs/example/GotoImplementation.java @@ -0,0 +1,16 @@ +package org.javacs.example; + +class GotoImplementation { + void main(IGoto i) { + i.virtualMethod(); + } + + interface IGoto { + void virtualMethod(); + } + + class CGoto implements IGoto { + @Override + public void virtualMethod() { } + } +}
\ No newline at end of file |