From e060e0428f7f92647e77ad8da2c7818eb4c4e3a7 Mon Sep 17 00:00:00 2001 From: ssankaran Date: Thu, 23 Oct 2014 17:37:44 +0530 Subject: Bug 446765 - [1.8][content assist] Completion does not work with both lambdas and anonymous classes in the picture --- .../compiler/parser/CompletionParserTest18.java | 242 +++++++++++++++++++-- 1 file changed, 226 insertions(+), 16 deletions(-) (limited to 'org.eclipse.jdt.core.tests.compiler') diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest18.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest18.java index bba49fa8bc..a1cdbef2df 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest18.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest18.java @@ -1710,7 +1710,6 @@ public void test430656() { "diet ast"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=438952, [1.8][content assist] StackOverflowError at org.eclipse.jdt.internal.compiler.ast.SingleTypeReference.traverse(SingleTypeReference.java:108) -// FIXME: Recovered parse tree isn't quite correct, but is harmless. public void test438952() { String string = "import java.util.function.Supplier;\n" + @@ -1738,22 +1737,7 @@ public void test438952() { "class SO {\n" + " {\n" + " int Supplier;\n" + - " new SO() {\n" + - " {\n" + - " }\n" + - " void test() {\n" + - " ;\n" + - " }\n" + - " void test() {\n" + - " ;\n" + - " }\n" + - " };\n" + " m6 = () -> new SO() {\n" + - " {\n" + - " }\n" + - " void test() {\n" + - " ;\n" + - " }\n" + " void test() {\n" + " ;\n" + " }\n" + @@ -2068,4 +2052,230 @@ public void test430667d() { expectedReplacedSource, "diet ast"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446765, +public void test446765() { + String string = + "class Stepper {\n" + + " public interface Step {\n" + + " void run();\n" + + " }\n" + + " public Stepper(Handler> handler) {}\n" + + "\n" + + " @SafeVarargs\n" + + " public final void run(Step ... steps) {}\n" + + "}\n" + + "interface AsyncResult {}\n" + + "interface Handler {\n" + + " void handle(E event);\n" + + "}\n" + + "class Z {\n" + + " void foo() {}\n" + + "}\n" + + "interface I {\n" + + " void foo(Z z);\n" + + "}\n" + + "class Y {\n" + + " void request(I i) {}\n" + + "}\n" + + "public class X {\n" + + " void test() {\n" + + " new Stepper(r -> {}) {\n" + + " private void step1() {\n" + + " Y y = new Y();\n" + + " y.request(response -> {\n" + + " if (response.)\n" + + " });\n" + + " }\n" + + " }.run(); \n" + + " } \n" + + "}\n"; + + String completeBehind = "response."; + int cursorLocation = string.indexOf(completeBehind) + completeBehind.length() - 1; + + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "if ()\n" + + " ;"; + String completionIdentifier = ""; + String expectedReplacedSource = "response."; + String expectedUnitDisplayString = + "class Stepper {\n" + + " public interface Step {\n" + + " void run();\n" + + " }\n" + + " public Stepper(Handler> handler) {\n" + + " }\n" + + " public final @SafeVarargs void run(Step... steps) {\n" + + " }\n" + + "}\n" + + "interface AsyncResult {\n" + + "}\n" + + "interface Handler {\n" + + " void handle(E event);\n" + + "}\n" + + "class Z {\n" + + " Z() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void foo(Z z);\n" + + "}\n" + + "class Y {\n" + + " Y() {\n" + + " }\n" + + " void request(I i) {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void test() {\n" + + " new Stepper(( r) -> {\n" + + "}) {\n" + + " private void step1() {\n" + + " Y y;\n" + + " y.request(( response) -> {\n" + + " ;\n" + + "});\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n"; + + checkMethodParse( + string.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428735, [1.8][assist] Missing completion proposals inside lambda body expression - other than first token +public void test428735h() { + String string = + "import java.util.List;\n" + + "class Person {\n" + + " String getLastName() { return null; }\n" + + "}\n" + + "public class X {\n" + + " void test2(List people) {\n" + + " people.sort((x,y) -> {\n" + + " if (true) return \"\" + x.get); \n" + + " else return \"\";\n" + + " }\n" + + "}\n"; + + String completeBehind = "x.get"; + int cursorLocation = string.indexOf(completeBehind) + completeBehind.length() - 1; + + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(\"\" + )"; + String completionIdentifier = "get"; + String expectedReplacedSource = "x.get"; + String expectedUnitDisplayString = + "import java.util.List;\n" + + "class Person {\n" + + " Person() {\n" + + " }\n" + + " String getLastName() {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void test2(List people) {\n" + + " people.sort(( x, y) -> {\n" + + " if (true)\n" + + " return (\"\" + );\n" + + " ;\n" + + " return \"\";\n" + + "});\n" + + " }\n" + + "}\n"; + + checkMethodParse( + string.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422468, [1.8][assist] Code assist issues with type elided lambda parameters +public void test422468() { // computing visible elements in lambda scope. + String string = + "interface I {\n" + + " void foo(X x);\n" + + "}\n" + + "public class X {\n" + + " static X xField;\n" + + " static X goo(String s) {\n" + + " return null;\n" + + " }\n" + + " static void goo(I i) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X xLocal = null;\n" + + " args = null;\n" + + " if (args != null) {\n" + + " xField = null;\n" + + " else \n" + + " xField = null;\n" + + " while (true);\n" + + " goo((xyz) -> {\n" + + " X xLambdaLocal = null;\n" + + " System.out.println(xyz.)\n" + + " });\n" + + " }\n" + + "}\n"; + String completeBehind = "xyz."; + int cursorLocation = string.indexOf(completeBehind) + completeBehind.length() - 1; + + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "System.out.println()"; + String completionIdentifier = ""; + String expectedReplacedSource = "xyz."; + String expectedUnitDisplayString = + "interface I {\n" + + " void foo(X x);\n" + + "}\n" + + "public class X {\n" + + " static X xField;\n" + + " public X() {\n" + + " }\n" + + " () {\n" + + " }\n" + + " static X goo(String s) {\n" + + " }\n" + + " static void goo(I i) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X xLocal;\n" + + " {\n" + + " {\n" + + " goo(( xyz) -> {\n" + + " X xLambdaLocal;\n" + + " System.out.println();\n" + + "});\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + checkMethodParse( + string.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} } -- cgit v1.2.3