Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGayan Perera2022-01-11 20:11:25 +0000
committerGayan Perera2022-01-20 20:03:09 +0000
commita81b036a420340ffba6cb0b5d17bf936324f5d9d (patch)
tree39c415d7de961d74ed0a5804e52747981f03a0bb
parent7689121add86e69dab85eae35dc2aa449552e851 (diff)
downloadeclipse.jdt.core-I20220123-1800.tar.gz
eclipse.jdt.core-I20220123-1800.tar.xz
eclipse.jdt.core-I20220123-1800.zip
Bug 578167 - fix completion for arguments inside lambdaI20220123-1800I20220122-1800I20220121-1800I20220120-1800
When a method CompletionOnMessageSend is inside a lambda block, The first expected types computations seems to empty the expected types array, which should be in length of 1. This cause later computations to find expected types for current argument position fails with an AIOB. The fix guard the array copy which erroneously resize the expected types array to zero length in first computation. Change-Id: I34bc9a6409d8c6623d3de008764b1cd93a2520ca Signed-off-by: Gayan Perera <gayanper@gmail.com> Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/189486 Tested-by: JDT Bot <jdt-bot@eclipse.org>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java29
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java3
2 files changed, 29 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 0d7dd30165..b8b9d4e12d 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
@@ -6393,10 +6393,10 @@ public void testBug577883_expectCompletions_onOuterLambdaVars_inNestedLambdas()
public void testBug577885_expectCompletions_onMethodArguments_followingMethodInvocationWithMethodRefArguments() throws JavaModelException {
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy(
- "Completion/src/Bug443091.java",
+ "Completion/src/Bug577885.java",
"import java.util.stream.Stream;\n" +
"\n" +
- "public class Bug443091 {\n" +
+ "public class Bug577885 {\n" +
" private void foo() {\n" +
" Stream.of(\"1\").map(Long::valueOf).filter()\n" +
" }\n" +
@@ -6413,6 +6413,31 @@ public void testBug577885_expectCompletions_onMethodArguments_followingMethodInv
+ "[LAMBDA_EXPRESSION]{->, Ljava.util.function.Predicate<Ljava.lang.Long;>;, (Ljava.lang.Long;)Z, test, (arg0), 89}",
result);
}
+public void testBug577885_expectCompletions_onMethodArguments_followingMethodInvocationWithMethodRefArguments_InsideLambda() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "Completion/src/Bug577885.java",
+ "import java.util.stream.Stream;\n" +
+ "\n" +
+ "public class Bug577885 {\n" +
+ " private void foo() {\n" +
+ " Runnable run = () -> {\n" +
+ " Stream.of(\"1\").map(Long::valueOf).filter()\n" +
+ " };\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "filter(";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ String result = requestor.getResults();
+ assertResults("filter[METHOD_REF]{, Ljava.util.stream.Stream<Ljava.lang.Long;>;, (Ljava.util.function.Predicate<-Ljava.lang.Long;>;)Ljava.util.stream.Stream<Ljava.lang.Long;>;, filter, (arg0), 56}\n"
+ + "[LAMBDA_EXPRESSION]{->, Ljava.util.function.Predicate<Ljava.lang.Long;>;, (Ljava.lang.Long;)Z, test, (arg0), 89}",
+ result);
+}
public void testBug578116_expectCompletions_forConstructorsInsideLamndaBlock() throws JavaModelException {
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getWorkingCopy(
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 eafc1e5beb..a5d50c36f1 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
@@ -4602,7 +4602,8 @@ public final class CompletionEngine
}
}
- if(this.expectedTypesPtr + 1 != this.expectedTypes.length) {
+ // Guard it, otherwise we end up with a empty array which cause issues down the line
+ if((this.expectedTypesPtr > -1) && ((this.expectedTypesPtr + 1) != this.expectedTypes.length)) {
System.arraycopy(this.expectedTypes, 0, this.expectedTypes = new TypeBinding[this.expectedTypesPtr + 1], 0, this.expectedTypesPtr + 1);
}
}

Back to the top