Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnirban Chakraborty2013-05-24 05:07:54 +0000
committerssankaran2013-05-24 05:07:54 +0000
commitf0cc0529135fe43e5b6252dca937651f0a04d49c (patch)
tree45d2f859cfa31a6dbf8428a9c66be92d260156fb
parent9a4ee57f61298f3e4fc702f795ebdbaf6a532c93 (diff)
downloadeclipse.jdt.core-f0cc0529135fe43e5b6252dca937651f0a04d49c.tar.gz
eclipse.jdt.core-f0cc0529135fe43e5b6252dca937651f0a04d49c.tar.xz
eclipse.jdt.core-f0cc0529135fe43e5b6252dca937651f0a04d49c.zip
Fixed Bug 406468 - [1.8][code assist] No completion proposals after the
use of a constructor reference
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java89
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java12
2 files changed, 101 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
index b73d13dc6b..9e56c4f4c6 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
@@ -1060,6 +1060,8 @@ public static Test suite() {
suite.addTest(new CompletionTests("testBug402812c"));
suite.addTest(new CompletionTests("testBug402812d"));
suite.addTest(new CompletionTests("testBug370971"));
+ suite.addTest(new CompletionTests("testBug406468a"));
+ suite.addTest(new CompletionTests("testBug406468b"));
return suite;
}
public CompletionTests(String name) {
@@ -26375,4 +26377,91 @@ public void testBug370971() throws JavaModelException {
COMPLETION_PROJECT.setOptions(options);
}
}
+// Bug 406468 - [1.8][code assist] No completion proposals after the use of a constructor reference
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406468
+public void testBug406468a() throws JavaModelException {
+ Map options = COMPLETION_PROJECT.getOptions(true);
+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
+ Object savedOptionSource = options.get(CompilerOptions.OPTION_Source);
+ try {
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
+ COMPLETION_PROJECT.setOptions(options);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/X.java",
+ "interface I {\n" +
+ " X [][][] copy (int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = X[][][]::new;\n" +
+ " X[][][] x = i.copy(136);\n" +
+ " System.out.println(x.length);\n" +
+ " \n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "System.out.println(x.length);";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "I[TYPE_REF]{I, test, Ltest.I;, null, null, 27}\n" +
+ "X[TYPE_REF]{X, test, Ltest.X;, null, null, 27}\n" +
+ "args[LOCAL_VARIABLE_REF]{args, null, [Ljava.lang.String;, args, null, 27}\n" +
+ "i[LOCAL_VARIABLE_REF]{i, null, Ltest.I;, i, null, 27}\n" +
+ "main[METHOD_REF]{main(), Ltest.X;, ([Ljava.lang.String;)V, main, (args), 27}\n" +
+ "x[LOCAL_VARIABLE_REF]{x, null, [[[Ltest.X;, x, null, 27}",
+ requestor.getResults());
+ } finally {
+ // Restore compliance settings.
+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
+ options.put(CompilerOptions.OPTION_Source, savedOptionSource);
+ COMPLETION_PROJECT.setOptions(options);
+ }
+}
+public void testBug406468b() throws JavaModelException {
+ Map options = COMPLETION_PROJECT.getOptions(true);
+ Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
+ Object savedOptionSource = options.get(CompilerOptions.OPTION_Source);
+ try {
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
+ COMPLETION_PROJECT.setOptions(options);
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/X.java",
+ "interface I {\n" +
+ " X<java.lang.String> copy ();\n" +
+ "}\n" +
+ "public class X<S> {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = X<java.lang.String>::new;\n" +
+ " X x = i.copy();\n" +
+ " System.out.println(x);\n" +
+ " \n" +
+ " }\n" +
+ "}\n");
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "System.out.println(x);";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "I[TYPE_REF]{I, test, Ltest.I;, null, null, 27}\n" +
+ "S[TYPE_REF]{S, null, TS;, null, null, 27}\n" +
+ "X<S>[TYPE_REF]{X, test, Ltest.X<TS;>;, null, null, 27}\n" +
+ "args[LOCAL_VARIABLE_REF]{args, null, [Ljava.lang.String;, args, null, 27}\n" +
+ "i[LOCAL_VARIABLE_REF]{i, null, Ltest.I;, i, null, 27}\n" +
+ "main[METHOD_REF]{main(), Ltest.X<TS;>;, ([Ljava.lang.String;)V, main, (args), 27}\n" +
+ "x[LOCAL_VARIABLE_REF]{x, null, Ltest.X;, x, null, 27}",
+ requestor.getResults());
+ } finally {
+ // Restore compliance settings.
+ options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
+ options.put(CompilerOptions.OPTION_Source, savedOptionSource);
+ COMPLETION_PROJECT.setOptions(options);
+ }
+}
}
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
index 9e035ed8f1..57f4c671ae 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
@@ -169,6 +169,7 @@ public class CompletionParser extends AssistParser {
private boolean storeSourceEnds;
public HashtableOfObjectToInt sourceEnds;
+ private boolean inReferenceExpression;
public CompletionParser(ProblemReporter problemReporter, boolean storeExtraSourceEnds) {
super(problemReporter);
@@ -3517,7 +3518,12 @@ protected void consumeToken(int token) {
break;
}
break;
+ case TokenNameCOLON_COLON:
+ this.inReferenceExpression = true;
+ break;
case TokenNameIdentifier:
+ if (this.inReferenceExpression)
+ break;
if (previous == TokenNameDOT) { // e.g. foo().[fred]()
if (this.invocationType != SUPER_RECEIVER // e.g. not super.[fred]()
&& this.invocationType != NAME_RECEIVER // e.g. not bar.[fred]()
@@ -3542,6 +3548,8 @@ protected void consumeToken(int token) {
}
break;
case TokenNamenew:
+ if (this.inReferenceExpression)
+ break;
pushOnElementStack(K_BETWEEN_NEW_AND_LEFT_BRACKET);
this.qualifier = this.expressionPtr; // NB: even if there is no qualification, set it to the expression ptr so that the number of arguments are correctly computed
if (previous == TokenNameDOT) { // e.g. fred().[new] X()
@@ -3964,6 +3972,10 @@ protected void consumeToken(int token) {
}
}
}
+protected void consumeIdentifierOrNew(boolean newForm) {
+ this.inReferenceExpression = false;
+ super.consumeIdentifierOrNew(newForm);
+}
protected void consumeOnlySynchronized() {
super.consumeOnlySynchronized();
this.hasUnusedModifiers = false;

Back to the top