diff options
| author | Stephan Herrmann | 2021-05-01 13:26:39 +0000 |
|---|---|---|
| committer | Stephan Herrmann | 2021-05-01 16:52:48 +0000 |
| commit | 1e898ec9c2f982e045bbb910f6d94f084cb5d545 (patch) | |
| tree | 3f1f0c62f2279666bd2181c5a941e7ff794a516e | |
| parent | 2685ba0b578528628dc5926cdffb1c0ebcdf7335 (diff) | |
| download | eclipse.jdt.core-1e898ec9c2f982e045bbb910f6d94f084cb5d545.tar.gz eclipse.jdt.core-1e898ec9c2f982e045bbb910f6d94f084cb5d545.tar.xz eclipse.jdt.core-1e898ec9c2f982e045bbb910f6d94f084cb5d545.zip | |
Bug 573279 - [content assist] Wrong completion suggestion when methodI20210501-1800
invocations are nested
Change-Id: I87acc6ae0f364dcb5c1a252352495f54ffac00ec
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/180085
Tested-by: JDT Bot <jdt-bot@eclipse.org>
Reviewed-by: Stephan Herrmann <stephan.herrmann@berlin.de>
2 files changed, 45 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java index 8dc635bc1e..3043a433e6 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java @@ -14672,4 +14672,47 @@ public void testBug532366() throws Exception { assertEquals("GREEN[FIELD_REF]{GREEN, Ltest.Color;, Ltest.Color;, null, null, GREEN, null, replace[43, 44], token[43, 44], 81}", requestor.getResults()); } +public void testBug573279() throws Exception { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/App.java", + "class MyArrayList<T> {\n" + + " boolean add(T t) {}\n" + + " boolean remove(Object o) {}\n" + + " int size() { return 0; }\n" + + "}\n" + + "\n" + + "public class App {\n" + + " MyArrayList<String> list = new MyArrayList<String>();\n" + + " public static void main(String[] args) {}\n" + + "\n" + + " private void foo() {\n" + + " String template = \"temp\";\n" + + " this.list.add(template.concat(\"late\"));\n" + + " }\n" + + "}" + ); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, true, true, true, true, true); + requestor.allowAllRequiredProposals(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "this.list."; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + int relevance = R_DEFAULT + R_INTERESTING + R_RESOLVED + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; + assertEquals("add[METHOD_REF]{add(), LMyArrayList<Ljava.lang.String;>;, (Ljava.lang.String;)Z, null, null, add, (t), replace[289, 318], token[289, 292], "+relevance+"}\n" + + "clone[METHOD_REF]{clone(), Ljava.lang.Object;, ()Ljava.lang.Object;, null, null, clone, null, replace[289, 318], token[289, 292], "+relevance+"}\n" + + "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, null, null, equals, (obj), replace[289, 318], token[289, 292], "+relevance+"}\n" + + "finalize[METHOD_REF]{finalize(), Ljava.lang.Object;, ()V, null, null, finalize, null, replace[289, 318], token[289, 292], "+relevance+"}\n" + + "getClass[METHOD_REF]{getClass(), Ljava.lang.Object;, ()Ljava.lang.Class<+Ljava.lang.Object;>;, null, null, getClass, null, replace[289, 318], token[289, 292], "+relevance+"}\n" + + "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, null, null, hashCode, null, replace[289, 318], token[289, 292], "+relevance+"}\n" + + "notify[METHOD_REF]{notify(), Ljava.lang.Object;, ()V, null, null, notify, null, replace[289, 318], token[289, 292], "+relevance+"}\n" + + "notifyAll[METHOD_REF]{notifyAll(), Ljava.lang.Object;, ()V, null, null, notifyAll, null, replace[289, 318], token[289, 292], "+relevance+"}\n" + + "remove[METHOD_REF]{remove(), LMyArrayList<Ljava.lang.String;>;, (Ljava.lang.Object;)Z, null, null, remove, (o), replace[289, 318], token[289, 292], "+relevance+"}\n" + + "size[METHOD_REF]{size(), LMyArrayList<Ljava.lang.String;>;, ()I, null, null, size, null, replace[289, 318], token[289, 292], "+relevance+"}\n" + + "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, null, null, toString, null, replace[289, 318], token[289, 292], "+relevance+"}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, ()V, null, null, wait, null, replace[289, 318], token[289, 292], "+relevance+"}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (J)V, null, null, wait, (millis), replace[289, 318], token[289, 292], "+relevance+"}\n" + + "wait[METHOD_REF]{wait(), Ljava.lang.Object;, (JI)V, null, null, wait, (millis, nanos), replace[289, 318], token[289, 292], "+relevance+"}", + 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 c96e227508..de79ff84c0 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 @@ -5590,7 +5590,8 @@ protected MessageSend newMessageSendWithTypeArguments() { } private MessageSend internalNewMessageSend() { MessageSend m = null; - if (this.assistNode == null && this.lParenPos > this.cursorLocation) { + long nameStart = this.identifierPositionStack[this.identifierPtr] >>> 32; + if (this.assistNode == null && this.lParenPos > this.cursorLocation && nameStart <= this.cursorLocation + 1) { m = new CompletionOnMessageSendName(null, 0, 0); // positions will be set in consumeMethodInvocationName(), if that's who called us } else if (this.assistNode != null && this.lParenPos == this.assistNode.sourceEnd) { // this branch corresponds to work done in checkParemeterizedMethodName(), just the latter isn't called in absence of a syntax error |
