diff options
author | George Fraser <george@fivetran.com> | 2018-05-20 16:49:03 -0700 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2018-05-20 16:49:03 -0700 |
commit | e70f3f6772a8d9c099cca83209cc439e81b45948 (patch) | |
tree | ff17385180912b046e02cf8e94a8753bca76f5d5 /src/test | |
parent | b108cd5d852217e2abb385764957ffb5a0aa7b48 (diff) | |
download | java-language-server-e70f3f6772a8d9c099cca83209cc439e81b45948.zip |
Prune methods by erasing
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/org/javacs/JavaPresentationCompilerTest.java | 48 | ||||
-rw-r--r-- | src/test/resources/BuildUpScope.java | 8 | ||||
-rw-r--r-- | src/test/resources/HelloWorld.java | 5 | ||||
-rw-r--r-- | src/test/resources/PruneMethods.java | 8 | ||||
-rw-r--r-- | src/test/resources/PruneMethods_erased.java | 8 |
5 files changed, 57 insertions, 20 deletions
diff --git a/src/test/java/org/javacs/JavaPresentationCompilerTest.java b/src/test/java/org/javacs/JavaPresentationCompilerTest.java index e396133..0d7cf80 100644 --- a/src/test/java/org/javacs/JavaPresentationCompilerTest.java +++ b/src/test/java/org/javacs/JavaPresentationCompilerTest.java @@ -5,9 +5,11 @@ import static org.junit.Assert.*; import com.sun.source.tree.*; import com.sun.source.util.*; +import java.io.*; import java.net.URI; import java.util.*; import java.util.logging.*; +import java.util.stream.Collectors; import javax.lang.model.*; import javax.lang.model.element.*; import javax.lang.model.type.*; @@ -19,37 +21,34 @@ public class JavaPresentationCompilerTest { private JavaPresentationCompiler compiler = new JavaPresentationCompiler(); - private String helloWorld = - "public class HelloWorld {\n" - + " public static void main(String[] args) {\n" - + " System.out.println(\"Hello world!\");\n" - + " }\n" - + "}"; + private String contents(String resourceFile) { + try (InputStream in = + JavaPresentationCompilerTest.class.getResourceAsStream(resourceFile)) { + return new BufferedReader(new InputStreamReader(in)) + .lines() + .collect(Collectors.joining("\n")); + } catch (IOException e) { + throw new RuntimeException(e); + } + } @Test public void element() { - Element found = compiler.element(URI.create("/HelloWorld.java"), helloWorld, 3, 18); + Element found = + compiler.element( + URI.create("/HelloWorld.java"), contents("/HelloWorld.java"), 3, 24); assertThat(found.getSimpleName(), hasToString(containsString("println"))); } - private String buildUpScope = - "class BuildUpScope {\n" - + " void main() {\n" - + " int a = 1;\n" - + " int b = 2;\n" - + " int c = 3;\n" - + " }\n" - + " void otherMethod() { }\n" - + "}\n"; - @Test public void buildUpScope() { - Scope a = compiler.scope(URI.create("/BuildUpScope.java"), buildUpScope, 3, 12); + String contents = contents("/BuildUpScope.java"); + Scope a = compiler.scope(URI.create("/BuildUpScope.java"), contents, 3, 17); assertThat(localElements(a), containsInAnyOrder("super", "this", "a")); - Scope b = compiler.scope(URI.create("/BuildUpScope.java"), buildUpScope, 4, 12); + Scope b = compiler.scope(URI.create("/BuildUpScope.java"), contents, 4, 17); assertThat(localElements(b), containsInAnyOrder("super", "this", "a", "b")); - Scope c = compiler.scope(URI.create("/BuildUpScope.java"), buildUpScope, 5, 12); + Scope c = compiler.scope(URI.create("/BuildUpScope.java"), contents, 5, 17); assertThat(localElements(c), containsInAnyOrder("super", "this", "a", "b", "c")); } @@ -60,4 +59,13 @@ public class JavaPresentationCompilerTest { } return result; } + + @Test + public void pruneMethods() { + Pruner pruner = + new Pruner(URI.create("/PruneMethods.java"), contents("/PruneMethods.java")); + String pruned = pruner.prune(6, 17); + String expected = contents("/PruneMethods_erased.java"); + assertThat(pruned, equalToIgnoringWhiteSpace(expected)); + } } diff --git a/src/test/resources/BuildUpScope.java b/src/test/resources/BuildUpScope.java new file mode 100644 index 0000000..171d816 --- /dev/null +++ b/src/test/resources/BuildUpScope.java @@ -0,0 +1,8 @@ +class BuildUpScope { + void main() { + int a = 1; + int b = 2; + int c = 3; + } + void otherMethod() { } +}
\ No newline at end of file diff --git a/src/test/resources/HelloWorld.java b/src/test/resources/HelloWorld.java new file mode 100644 index 0000000..b86724f --- /dev/null +++ b/src/test/resources/HelloWorld.java @@ -0,0 +1,5 @@ +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +}
\ No newline at end of file diff --git a/src/test/resources/PruneMethods.java b/src/test/resources/PruneMethods.java new file mode 100644 index 0000000..474cee2 --- /dev/null +++ b/src/test/resources/PruneMethods.java @@ -0,0 +1,8 @@ +class PruneMethods { + void a() { + int a = 1; + } + void b() { + int b = 2; + } +}
\ No newline at end of file diff --git a/src/test/resources/PruneMethods_erased.java b/src/test/resources/PruneMethods_erased.java new file mode 100644 index 0000000..e3d1a4b --- /dev/null +++ b/src/test/resources/PruneMethods_erased.java @@ -0,0 +1,8 @@ +class PruneMethods { + void a() { + + } + void b() { + int b = 2; + } +}
\ No newline at end of file |