Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2017-05-16 18:14:38 +0000
committerJay Arthanareeswaran2017-05-16 18:14:38 +0000
commit76bed57151387767b0043f9581cbafbad2365693 (patch)
tree1d31a40119d8a3437d2a8999088413edf3b7939c
parent2f237565131a82ca117237057293771bc9fc9723 (diff)
downloadeclipse.jdt.core-76bed57151387767b0043f9581cbafbad2365693.tar.gz
eclipse.jdt.core-76bed57151387767b0043f9581cbafbad2365693.tar.xz
eclipse.jdt.core-76bed57151387767b0043f9581cbafbad2365693.zip
Bug 485492 - Content assist does not work in a braced lambda in enumI20170516-2000
constructor call Change-Id: Id7ede634d93bc0d7a0d853b54d0fca05b66a37d4 Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java68
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java4
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java14
3 files changed, 83 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java
index 9831553458..dda4d17fd0 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java
@@ -2970,4 +2970,72 @@ public void test515809() throws JavaModelException {
"expectedTypesKeys=null\n" +
"completion token location={STATEMENT_START}", requestor.getContext());
}
+//https://bugs.eclipse.org/485492
+public void test485492a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Foo.java",
+ "import java.util.function.Function;\n" +
+ "public enum Foo {\n" +
+ " BAR((z) -> {\n" +
+ " z.has\n" +
+ " return z;\n" +
+ " });\n" +
+ " Foo(Function<String, String> func) { }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, true, true, false);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "z.has";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.String;, ()I, null, null, hashCode, null, [71, 74], 60}",
+ requestor.getResults());
+}
+public void test485492b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Foo.java",
+ "import java.util.function.Function;\n" +
+ "public enum Foo {\n" +
+ " BAR((zilch) -> {\n" +
+ " return zil;\n" +
+ " });\n" +
+ " Foo(Function<String, String> func) { }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, true, true, false);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "return zil";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "zilch[LOCAL_VARIABLE_REF]{zilch, null, Ljava.lang.String;, null, null, zilch, null, [81, 84], 52}",
+ requestor.getResults());
+}
+public void test485492c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/Foo.java",
+ "import java.util.function.Function;\n" +
+ "public enum Foo {\n" +
+ " BAR((z) -> {\n" +
+ " return z.has;\n" +
+ " });\n" +
+ " Foo(Function<String, String> func) { }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, true, true, false);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "z.has";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.String;, ()I, null, null, hashCode, null, [79, 82], 60}",
+ requestor.getResults());
+}
}
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 03994be96c..8b4af64bbd 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
@@ -3517,7 +3517,7 @@ protected void consumeToken(int token) {
int previous = this.previousToken;
int prevIdentifierPtr = this.previousIdentifierPtr;
- if (isInsideMethod() || isInsideFieldInitialization() || isInsideAnnotation()) {
+ if (isInsideMethod() || isInsideFieldInitialization() || isInsideAnnotation() || isInsideEnumConstantnitialization()) {
switch(token) {
case TokenNameLPAREN:
if(previous == TokenNameIdentifier &&
@@ -3577,7 +3577,7 @@ protected void consumeToken(int token) {
}
// if in a method or if in a field initializer
- if (isInsideMethod() || isInsideFieldInitialization() || isInsideAttributeValue()) {
+ if (isInsideMethod() || isInsideFieldInitialization() || isInsideAttributeValue() || isInsideEnumConstantnitialization()) {
switch (token) {
case TokenNameDOT:
switch (previous) {
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
index a9a1eb4c23..754641a959 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
@@ -1021,7 +1021,7 @@ protected void consumeToken(int token) {
}
// register message send selector only if inside a method or if looking at a field initializer
// and if the current token is an open parenthesis
- if (isInsideMethod() || isInsideFieldInitialization() || isInsideAttributeValue()) {
+ if (isInsideMethod() || isInsideFieldInitialization() || isInsideAttributeValue() || isInsideEnumConstantnitialization()) {
switch (token) {
case TokenNameLPAREN :
this.bracketDepth++;
@@ -1516,6 +1516,18 @@ protected boolean isInsideFieldInitialization(){
case K_TYPE_DELIMITER : return false;
case K_METHOD_DELIMITER : return false;
case K_FIELD_INITIALIZER_DELIMITER :
+ return true;
+ }
+ i--;
+ }
+ return false;
+}
+protected boolean isInsideEnumConstantnitialization(){
+ int i = this.elementPtr;
+ while(i > -1) {
+ switch (this.elementKindStack[i]) {
+ case K_TYPE_DELIMITER : return false;
+ case K_METHOD_DELIMITER : return false;
case K_ENUM_CONSTANT_DELIMITER :
return true;
}

Back to the top