Bug 574982 - [content assist] quick fix for java.util.Arrays not
proposed in anonymous class
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
Change-Id: I1f9508e79c34eb7ae534fb6fc924889fd65bbae0
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183339
Reviewed-by: Stephan Herrmann <stephan.herrmann@berlin.de>
Tested-by: JDT Bot <jdt-bot@eclipse.org>
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 7eca5bf..cd84004 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
@@ -26380,4 +26380,72 @@
"App[TYPE_REF]{App, , LApp;, null, null, 56}",
requestor.getResults());
}
+public void testBug573702_qualifiedName_firstSegment_start() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "Completion/src/App.java",
+ "import java.util.Collection;\n" +
+ "import java.util.Map;\n" +
+ "\n" +
+ "interface ObjectProperty<T> {\n" +
+ " void addListener(SingleFireInvalidationListener singleFireInvalidationListener);\n" +
+ "}\n" +
+ "class SingleFireInvalidationListener {\n" +
+ " public SingleFireInvalidationListener(Collection<String> list) { }\n" +
+ "}\n" +
+ "public class App {\n" +
+ " static Map<String, String> data;\n" +
+ " public void boo() {\n" +
+ " System.out.println(\"PopOver direct buffer delayed patch installation started\");\n" +
+ " App.getDataProperty().addListener(new SingleFireInvalidationListener(App.data.values()));\n" +
+ " System.out.println(\"PopOver direct buffer delayed patch installation done\");\n" +
+ " }\n" +
+ "\n" +
+ " public static ObjectProperty<Map<String, String>> getDataProperty() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "new SingleFireInvalidationListener(A";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "ABC[TYPE_REF]{p1.ABC, p1, Lp1.ABC;, null, null, 49}\n" +
+ "ABC[TYPE_REF]{p2.ABC, p2, Lp2.ABC;, null, null, 49}\n" +
+ "A3[TYPE_REF]{A3, , LA3;, null, null, 52}\n" +
+ "App[TYPE_REF]{App, , LApp;, null, null, 52}\n" +
+ "A[TYPE_REF]{A, , LA;, null, null, 56}",
+ requestor.getResults());
+}
+public void testBug574982() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "Completion/src/ArrayTest.java",
+ "public class ArrayTest {\n" +
+ " public void test() {\n" +
+ " new Runnable() {\n" +
+ " public void run() {\n" +
+ " boolean equals = Arrays.equals(new Object[0], new Object[0]);\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "equals = A";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "ABC[TYPE_REF]{p1.ABC, p1, Lp1.ABC;, null, null, 49}\n" +
+ "ABC[TYPE_REF]{p2.ABC, p2, Lp2.ABC;, null, null, 49}\n" +
+ "A3[TYPE_REF]{A3, , LA3;, null, null, 52}\n" +
+ "ArrayTest[TYPE_REF]{ArrayTest, , LArrayTest;, null, null, 52}\n" +
+ "A[TYPE_REF]{A, , LA;, null, null, 56}",
+ 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 6cb3d79..690f31d 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
@@ -5405,7 +5405,7 @@
char[] token = this.identifierStack[this.identifierPtr];
long position = this.identifierPositionStack[this.identifierPtr--];
int start = (int) (position >>> 32), end = (int) position;
- if (this.assistNode == null && start < this.cursorLocation && end >= this.cursorLocation) {
+ if (this.assistNode == null && start <= this.cursorLocation && end >= this.cursorLocation) {
ref = new CompletionOnSingleNameReference(token, position, isInsideAttributeValue());
this.assistNode = ref;
} else {
@@ -5419,7 +5419,7 @@
long[] positions = new long[length];
System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
int start = (int) (positions[0] >>> 32), end = (int) positions[length-1];
- if (this.assistNode == null && start < this.cursorLocation && end >= this.cursorLocation) {
+ if (this.assistNode == null && start <= this.cursorLocation && end >= this.cursorLocation) {
// find the token at cursorLocation:
int previousCount = 0;
for (int i=0; i<length; i++) {