Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGayan Perera2021-01-07 11:33:32 +0000
committerVikas Chandra2021-01-20 10:47:02 +0000
commit3c46376e7756e2a66ab99e594bc33dbba24e28ee (patch)
tree4df1f0934128326d00135a966086e6077ab0131b
parentdb4cdd0d6f17900633280e6d0f46325660f36408 (diff)
downloadeclipse.jdt.core-3c46376e7756e2a66ab99e594bc33dbba24e28ee.tar.gz
eclipse.jdt.core-3c46376e7756e2a66ab99e594bc33dbba24e28ee.tar.xz
eclipse.jdt.core-3c46376e7756e2a66ab99e594bc33dbba24e28ee.zip
Bug 570016: Enable type argument completions in lambda blockI20210121-2140I20210120-1800I20210120-1400
Inside lambda block the type argument completion is not working due to the ParameterizedSingleTypeReference is not resolved. This fix will try to move the ParameterizedSingleTypeReference expression as a lambda block statement so that it get resolved when resolving the CompilationUnit. Also reverted and adjusted the https://bugs.eclipse.org/bugs/show_bug.cgi?id=460410 Change-Id: Ib8bbe848675fc961eb69952039e4314ace9e25e2 Signed-off-by: Gayan Perera <gayanper@gmail.com>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java48
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java3
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java6
3 files changed, 49 insertions, 8 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 6e2444f0b3..f38b48b005 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
@@ -2495,7 +2495,7 @@ public void testBug459189_004() throws JavaModelException {
requestor.getResults());
}
public void testBug460410() throws JavaModelException {
- this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies = new ICompilationUnit[2];
this.workingCopies[0] = getWorkingCopy(
"/Completion/src/X.java",
"import java.util.ArrayList;\n" +
@@ -2504,9 +2504,16 @@ public void testBug460410() throws JavaModelException {
" public static void main(String[] args) {\n"+
" ArrayList<Supplier<Runnable>> list = new ArrayList<>();\n"+
" list.forEach((supp) -> {\n"+
- " Supplier<Run/* HERE */>}\n"+
+ " Supplier<Bug460/* HERE */>}\n"+
" });\n"+
" }\n"+
+ " public static class Bug460410 {" +
+ " }" +
+ "}\n");
+ this.workingCopies[1] = getWorkingCopy(
+ "/Completion/src/Bug460411.java",
+ "package abc;" +
+ "public class Bug460411 {\n"+
"}\n");
CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
@@ -2515,7 +2522,42 @@ public void testBug460410() throws JavaModelException {
String completeBehind = "/* HERE */";
int cursorLocation = str.indexOf(completeBehind);
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
- assertResults("", requestor.getResults());
+ assertResults(
+ "Bug460411[TYPE_REF]{abc.Bug460411, abc, Labc.Bug460411;, null, null, " + (R_DEFAULT + 39) + "}\n" +
+ "Bug460410[TYPE_REF]{Bug460410, , LBug460410;, null, null, " + (R_DEFAULT + 42) + "}",
+ requestor.getResults());
+}
+public void testBug462015() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/X.java",
+ "package abc;\n" +
+ "import java.util.ArrayList;\n" +
+ "import java.util.stream.Collectors;\n" +
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " ArrayList<Entry> list = new ArrayList<>();\n"+
+ " list.stream().collect(Collectors.averagingInt(e -> e.a/* HERE */));\n"+
+ " }\n"+
+ "}\n");
+ this.workingCopies[1] = getWorkingCopy(
+ "/Completion/src/Entry.java",
+ "package abc;" +
+ "public class Entry {\n"+
+ " public String age() {\n"+
+ " return \"10\";"+
+ " }"+
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "/* HERE */";
+ int cursorLocation = str.indexOf(completeBehind);
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ assertResults(
+ "age[METHOD_REF]{age(), LEntry;, ()Ljava.lang.String;, age, null, " + (R_DEFAULT + 30) + "}",
+ requestor.getResults());
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=481564
public void testBug481564() throws JavaModelException {
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index afffe434a9..27e4f01b0e 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -13038,9 +13038,6 @@ public final class CompletionEngine
if(parent instanceof ParameterizedSingleTypeReference) {
ParameterizedSingleTypeReference ref = (ParameterizedSingleTypeReference) parent;
- if (ref.resolvedType == null) {
- return false;
- }
TypeVariableBinding[] typeVariables = ((ReferenceBinding)ref.resolvedType).typeVariables();
int length = ref.typeArguments == null ? 0 : ref.typeArguments.length;
int nodeIndex = -1;
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 ecbcfcb88f..e54d74513d 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
@@ -2744,8 +2744,10 @@ protected void consumeEmptyStatement() {
we don't know whether it is the first or subsequent statement in a block to be able to
decide whether to call contactNodeLists. See Parser.consumeBlockStatement(s)
*/
- if (this.shouldStackAssistNode && this.assistNode != null)
- this.astStack[this.astPtr] = this.assistNodeParent instanceof MessageSend ? this.assistNodeParent : this.assistNode;
+ if (this.shouldStackAssistNode && this.assistNode != null) {
+ this.astStack[this.astPtr] = (this.assistNodeParent instanceof MessageSend)
+ || (this.assistNodeParent instanceof ParameterizedSingleTypeReference) ? this.assistNodeParent : this.assistNode;
+ }
this.shouldStackAssistNode = false;
}
@Override

Back to the top