Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGayan Perera2021-09-24 19:30:18 +0000
committerGayan Perera2021-10-12 18:00:09 +0000
commitc0cd9f53b1e7fc050b27a87b72b95d1ed2e0404c (patch)
tree33e498742b222d920084e41413b32efd9fb7ac27
parent9525f3eec57b403f918771025f4280bba56b1221 (diff)
downloadeclipse.jdt.core-c0cd9f53b1e7fc050b27a87b72b95d1ed2e0404c.tar.gz
eclipse.jdt.core-c0cd9f53b1e7fc050b27a87b72b95d1ed2e0404c.tar.xz
eclipse.jdt.core-c0cd9f53b1e7fc050b27a87b72b95d1ed2e0404c.zip
Bug 575149 - Add support to resolve 1st arg type on overload methodsI20211012-1800
The fix will resolve the first argument type of all matching method overloads. It also make the relevance of the overload completions higher so they appear first in the completion list to preserve the existing behavior. Other completions are strictly provided based on the expected types. This also update the CompletionContext expected types signatures so that other completion computers can be benefited. Change-Id: Id842ff7ad064aabfd9e57c89a94d385d37d8a6dc Signed-off-by: Gayan Perera <gayanper@gmail.com> Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/185826 Tested-by: JDT Bot <jdt-bot@eclipse.org>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java16
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java1
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests18.java102
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java3
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SubwordCompletionTests.java1
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java122
7 files changed, 227 insertions, 22 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java
index 18fda7acda..0a9a3e9204 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java
@@ -2489,8 +2489,8 @@ public void test0090() throws JavaModelException {
"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
"completion token=\"\"\n" +
"completion token kind=TOKEN_KIND_NAME\n" +
- "expectedTypesSignatures=null\n" +
- "expectedTypesKeys=null\n"+
+ "expectedTypesSignatures={I}\n" +
+ "expectedTypesKeys={I}\n"+
"completion token location=UNKNOWN",
result.context);
}
@@ -2545,8 +2545,8 @@ public void test0092() throws JavaModelException {
"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
"completion token=\"\"\n" +
"completion token kind=TOKEN_KIND_NAME\n" +
- "expectedTypesSignatures=null\n" +
- "expectedTypesKeys=null\n"+
+ "expectedTypesSignatures={I}\n" +
+ "expectedTypesKeys={I}\n"+
"completion token location=UNKNOWN",
result.context);
}
@@ -2601,8 +2601,8 @@ public void test0094() throws JavaModelException {
"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
"completion token=\"\"\n" +
"completion token kind=TOKEN_KIND_NAME\n" +
- "expectedTypesSignatures=null\n" +
- "expectedTypesKeys=null\n"+
+ "expectedTypesSignatures={I}\n" +
+ "expectedTypesKeys={I}\n"+
"completion token location=UNKNOWN",
result.context);
}
@@ -2657,8 +2657,8 @@ public void test0096() throws JavaModelException {
"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
"completion token=\"\"\n" +
"completion token kind=TOKEN_KIND_NAME\n" +
- "expectedTypesSignatures=null\n" +
- "expectedTypesKeys=null\n"+
+ "expectedTypesSignatures={I}\n" +
+ "expectedTypesKeys={I}\n"+
"completion token location=UNKNOWN",
result.context);
}
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 cd84004ab0..eaff34a610 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
@@ -13324,6 +13324,7 @@ public void testCompletionPrefixMethodName3() throws JavaModelException {
int tEnd = tStart;
assertResults(
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, replace["+tStart+", "+tEnd+"], token["+tStart+", "+tEnd+"], 52}\n" +
"xBar[METHOD_REF]{CompletionPrefixMethodName3.this.xBar(1,, LCompletionPrefixMethodName3;, (II)I, xBar, (a, b), replace["+rStart1+", "+rEnd1+"], token["+tStart+", "+tEnd+"], "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME+ R_NON_RESTRICTED)+"}\n"+
"xBar[METHOD_REF]{, LCompletionPrefixMethodName3$classFoo;, (II)I, xBar, (a, b), replace["+rStart2+", "+rEnd2+"], token["+tStart+", "+tEnd+"], "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED)+"}",
requestor.getResults());
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 90aad655c9..39152f4574 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
@@ -26,6 +26,7 @@ import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.eval.IEvaluationContext;
import org.eclipse.jdt.internal.codeassist.RelevanceConstants;
@@ -5948,8 +5949,8 @@ public void testBug574912_comment6() throws JavaModelException {
int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
String result = requestor.getResults();
- assertResults("getMinimum[METHOD_REF]{, Ljava.util.Calendar;, (I)I, getMinimum, (arg0), 86}",
- result);
+ assertResults("num[FIELD_REF]{num, LLambdaFreeze2;, I, num, null, 52}\n"
+ + "getMinimum[METHOD_REF]{, Ljava.util.Calendar;, (I)I, getMinimum, (arg0), 86}", result);
}
public void testBug574912_comment6b() throws JavaModelException {
this.workingCopies = new ICompilationUnit[1];
@@ -6024,4 +6025,101 @@ public void testBug574882() throws Exception {
"completion token location={STATEMENT_START}", // this is required for sysout template proposal
requestor.getContext());
}
+public void testBug575149_expectOverloadedMethodsAndVariablesRankedWithExpectedType() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "Completion/src/Bug443091.java",
+ "import java.util.function.Consumer;\n" +
+ "import java.util.function.Function;\n" +
+ "\n" +
+ "public class Bug443091 {\n" +
+ " private void foo() {\n" +
+ " Consumer<Integer> capture = null;\n" +
+ " forEach()" +
+ " }\n" +
+ " private void forEach(Consumer<Integer> in) {}\n" +
+ " private void forEach(Function<Integer, String> in) {}\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "forEach(";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ String result = requestor.getResults();
+ assertResults(
+ "capture[LOCAL_VARIABLE_REF]{capture, null, Ljava.util.function.Consumer<Ljava.lang.Integer;>;, capture, null, 52}\n"
+ + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;)V, forEach, (in), 56}\n"
+ + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Function<Ljava.lang.Integer;Ljava.lang.String;>;)V, forEach, (in), 56}",
+ result);
+ assertTrue("expected type signatures don't match", CharOperation.equals(requestor.getExpectedTypesSignatures(),
+ new char[][] {"Ljava.util.function.Function<Ljava.lang.Integer;Ljava.lang.String;>;".toCharArray(),
+ "Ljava.util.function.Consumer<Ljava.lang.Integer;>;".toCharArray()}, true));
+}
+public void testBug575149_expectRemainingOverloadedMethodsMatchingFilledArguments() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "Completion/src/Bug443091.java",
+ "import java.util.function.Consumer;\n" +
+ "import java.util.function.Function;\n" +
+ "\n" +
+ "public class Bug443091 {\n" +
+ " private void foo() {\n" +
+ " Consumer<Integer> capture = null;\n" +
+ " forEach(capture, )" +
+ " }\n" +
+ " private void forEach(Consumer<Integer> in) {}\n" +
+ " private void forEach(Consumer<Integer> in, Integer limit) {}\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "forEach(capture,";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ String result = requestor.getResults();
+ assertResults("hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, 52}\n"
+ + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;)V, forEach, (in), 56}\n"
+ + "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;Ljava.lang.Integer;)V, forEach, (in, limit), 56}",
+ result);
+ assertTrue("expected type signatures don't match", CharOperation.equals(requestor.getExpectedTypesSignatures(), new char[][] {"Ljava.lang.Integer;".toCharArray()}, true));
+}
+public void testBug575149_expectOverloadsOverEnumLiterals() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "Completion/src/Bug443091.java",
+ "import java.util.function.Consumer;\n" +
+ "import java.util.function.Function;\n" +
+ "\n" +
+ "public class Bug443091 {\n" +
+ " private void foo() {\n" +
+ " Consumer<Integer> capture = null;\n" +
+ " forEach(capture, )" +
+ " }\n" +
+ " private Thread.State defaultState() { return null;} \n" +
+ " private void forEach(Consumer<Integer> in, Thread.State state) {}\n" +
+ " private void forEach(Consumer<Integer> in, Thread.State state, Integer limit) {}\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "forEach(capture,";
+ int cursorLocation = str.indexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+ String result = requestor.getResults();
+ assertResults("BLOCKED[FIELD_REF]{State.BLOCKED, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, BLOCKED, null, 49}\n" +
+ "NEW[FIELD_REF]{State.NEW, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, NEW, null, 49}\n" +
+ "RUNNABLE[FIELD_REF]{State.RUNNABLE, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, RUNNABLE, null, 49}\n" +
+ "TERMINATED[FIELD_REF]{State.TERMINATED, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, TERMINATED, null, 49}\n" +
+ "TIMED_WAITING[FIELD_REF]{State.TIMED_WAITING, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, TIMED_WAITING, null, 49}\n" +
+ "WAITING[FIELD_REF]{State.WAITING, Ljava.lang.Thread$State;, Ljava.lang.Thread$State;, WAITING, null, 49}\n" +
+ "defaultState[METHOD_REF]{defaultState(), LBug443091;, ()Ljava.lang.Thread$State;, defaultState, null, 52}\n" +
+ "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;Ljava.lang.Thread$State;)V, forEach, (in, state), 56}\n" +
+ "forEach[METHOD_REF]{, LBug443091;, (Ljava.util.function.Consumer<Ljava.lang.Integer;>;Ljava.lang.Thread$State;Ljava.lang.Integer;)V, forEach, (in, state, limit), 56}",
+ result);
+ assertTrue("expected type signatures don't match", CharOperation.equals(requestor.getExpectedTypesSignatures(), new char[][] {"Ljava.lang.Thread$State;".toCharArray()}, true));
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java
index 072cbe50d0..4d6b84f11c 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java
@@ -709,4 +709,8 @@ public class CompletionTestsRequestor2 extends CompletionRequestor {
}
return null;
}
+
+ public char[][] getExpectedTypesSignatures() {
+ return this.context.getExpectedTypesSignatures();
+ }
}
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 d7e4fe6361..ddb5871ce0 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
@@ -11609,6 +11609,7 @@ public void test0360() throws JavaModelException {
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults(
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" +
"get[METHOD_REF]{, Ltest.util.List<Ljava.lang.String;>;, (I)Ljava.lang.String;, get, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
requestor.getResults());
}
@@ -11676,6 +11677,7 @@ public void test0362() throws JavaModelException {
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults(
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" +
"abs[METHOD_REF]{, Ltest.util.Math;, (I)I, abs, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
requestor.getResults());
}
@@ -11706,6 +11708,7 @@ public void test0363() throws JavaModelException {
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults(
+ "hashCode[METHOD_REF]{hashCode(), Ljava.lang.Object;, ()I, hashCode, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" +
"abs[METHOD_REF]{, Ltest.util.Math;, (I)I, abs, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
requestor.getResults());
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SubwordCompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SubwordCompletionTests.java
index d3773047b8..a6e80433ad 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SubwordCompletionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SubwordCompletionTests.java
@@ -897,6 +897,7 @@ public void testDontPreventInsertionOfExactMatch() throws JavaModelException {
this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
assertResults(
+ "toString[METHOD_REF]{toString(), Ljava.lang.Object;, ()Ljava.lang.String;, toString, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED ) + "}\n" +
"put[METHOD_REF]{, Ljava.util.Map<Ljava.lang.String;Ljava.lang.String;>;, (Ljava.lang.String;Ljava.lang.String;)Ljava.lang.String;, put, (key, value), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_NAME + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED ) + "}",
requestor.getResults());
}
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 69695bfe44..3cfe8313cf 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
@@ -844,6 +844,15 @@ public final class CompletionEngine
private int foundConstructorsCount;
private ObjectVector acceptedConstructors;
+ /**
+ * The strictMatchForExtepectedType used to skip all elements found at <code>findVariablesAndMethods</code>
+ * which doesn't match the current expected types in the engine in <code>expectedTypes</code>. Since in this mode
+ * all elements found matches the expected type, the completion proposals will not contains the calculated expected type
+ * relevance. This is done to keep the overloaded method suggestions always on top in this mode as a fix for
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=575149
+ *
+ */
+ private boolean strictMatchForExtepectedType = false;
/**
* The CompletionEngine is responsible for computing source completions.
@@ -1995,6 +2004,10 @@ public final class CompletionEngine
completionOnMemberAccess(astNode, enclosingNode, qualifiedBinding, scope, insideTypeAnnotation);
} else if (astNode instanceof CompletionOnMessageSend) {
completionOnMessageSend(astNode, qualifiedBinding, scope);
+ // rebuild the context with newly found expected types so other completion computers can benifit from it.
+ if(this.expectedTypesPtr > -1) {
+ buildContext(astNode, astNodeParent, compilationUnitDeclaration, qualifiedBinding, scope);
+ }
} else if (astNode instanceof CompletionOnExplicitConstructorCall) {
completionOnExplicitConstructorCall(astNode, qualifiedBinding, scope);
} else if (astNode instanceof CompletionOnQualifiedAllocationExpression) {
@@ -3185,9 +3198,9 @@ public final class CompletionEngine
CompletionOnMessageSend messageSend = (CompletionOnMessageSend) astNode;
TypeBinding[] argTypes = computeTypes(messageSend.arguments);
this.completionToken = messageSend.selector;
+ ObjectVector methodsFound = new ObjectVector();
if (qualifiedBinding == null) {
if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
- ObjectVector methodsFound = new ObjectVector();
findImplicitMessageSends(this.completionToken, argTypes, scope, messageSend, scope, methodsFound);
@@ -3209,7 +3222,7 @@ public final class CompletionEngine
argTypes,
(ReferenceBinding)((ReferenceBinding) qualifiedBinding).capture(scope, messageSend.receiver.sourceStart, messageSend.receiver.sourceEnd),
scope,
- new ObjectVector(),
+ methodsFound,
false,
true,
messageSend,
@@ -3225,6 +3238,40 @@ public final class CompletionEngine
-1,
-1);
}
+
+ findCompletionsForArgumentPosition(methodsFound, argTypes != null ? argTypes.length : 0, scope);
+ }
+
+ private void findCompletionsForArgumentPosition(ObjectVector methodsFound, int completedArgumentLength, Scope scope) {
+ if(methodsFound.size == 0) {
+ return;
+ }
+
+ for(int i = 0; i < methodsFound.size; i++) {
+ MethodBinding method = (MethodBinding) ((Object[])methodsFound.elementAt(i))[0];
+ if(method.parameters.length <= completedArgumentLength) {
+ continue;
+ }
+
+ TypeBinding paramType = method.parameters[completedArgumentLength];
+ addExpectedType(paramType, scope);
+ }
+ this.strictMatchForExtepectedType = true;
+ int filter = this.expectedTypesFilter;
+ this.expectedTypesFilter = SUBTYPE;
+ int start = this.startPosition, end = this.endPosition;
+ int tStart = this.tokenStart, tEnd = this.tokenEnd;
+ try {
+ this.startPosition = this.endPosition = this.tokenStart = this.tokenEnd = this.actualCompletionPosition + 1;
+ findVariablesAndMethods(CharOperation.NO_CHAR, scope, FakeInvocationSite, scope, false, false, false, methodsFound);
+ } finally {
+ this.startPosition = start;
+ this.endPosition = end;
+ this.tokenStart = tStart;
+ this.tokenEnd = tEnd;
+ this.strictMatchForExtepectedType = false;
+ this.expectedTypesFilter = filter;
+ }
}
private void completionOnMessageSendName(ASTNode astNode, Binding qualifiedBinding, Scope scope) {
@@ -6414,7 +6461,13 @@ public final class CompletionEngine
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal(field);
relevance += computeRelevanceForCaseMatching(enumConstantName, field.name);
- relevance += computeRelevanceForExpectingType(field.type);
+ int computeRelevanceForExpectingType = computeRelevanceForExpectingType(field.type);
+ if(this.strictMatchForExtepectedType && computeRelevanceForExpectingType <= 0) {
+ continue;
+ } else if (!this.strictMatchForExtepectedType) {
+ relevance += computeRelevanceForExpectingType;
+ }
+
relevance += computeRelevanceForEnumConstant(field.type);
relevance += computeRelevanceForQualification(needQualification);
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
@@ -7039,7 +7092,13 @@ public final class CompletionEngine
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal(field);
relevance += computeRelevanceForCaseMatching(fieldName, field.name);
- relevance += computeRelevanceForExpectingType(field.type);
+ int computeRelevanceForExpectingType = computeRelevanceForExpectingType(field.type);
+ if(this.strictMatchForExtepectedType && computeRelevanceForExpectingType <= 0) {
+ continue;
+ } else if(!this.strictMatchForExtepectedType) {
+ relevance += computeRelevanceForExpectingType;
+ }
+
relevance += computeRelevanceForEnumConstant(field.type);
relevance += computeRelevanceForStatic(onlyStaticFields, field.isStatic());
relevance += computeRelevanceForFinal(this.assistNodeIsInsideCase, field.isFinal());
@@ -9387,7 +9446,12 @@ public final class CompletionEngine
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal();
relevance += computeRelevanceForCaseMatching(methodName, method.selector);
- relevance += computeRelevanceForExpectingType(method.returnType);
+ int computeRelevanceForExpectingType = computeRelevanceForExpectingType(method.returnType);
+ if(this.strictMatchForExtepectedType && computeRelevanceForExpectingType <= 0) {
+ continue;
+ } else if(!this.strictMatchForExtepectedType) {
+ relevance += computeRelevanceForExpectingType;
+ }
relevance += computeRelevanceForEnumConstant(method.returnType);
relevance += computeRelevanceForStatic(onlyStaticMethods, method.isStatic());
relevance += computeRelevanceForQualification(prefixRequired);
@@ -9648,7 +9712,13 @@ public final class CompletionEngine
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal();
relevance += computeRelevanceForCaseMatching(methodName, method.selector);
- relevance += computeRelevanceForExpectingType(method.returnType);
+ int computeRelevanceForExpectingType = computeRelevanceForExpectingType(method.returnType);
+ if(this.strictMatchForExtepectedType && computeRelevanceForExpectingType <= 0) {
+ continue;
+ } else if(!this.strictMatchForExtepectedType) {
+ relevance += computeRelevanceForExpectingType;
+ }
+
relevance += computeRelevanceForEnumConstant(method.returnType);
relevance += computeRelevanceForStatic(true, method.isStatic());
relevance += computeRelevanceForQualification(true);
@@ -9888,8 +9958,20 @@ public final class CompletionEngine
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal();
relevance += computeRelevanceForCaseMatching(methodName, method.selector);
- relevance += computeRelevanceForExpectingType(method.returnType);
- relevance += computeRelevanceForEnumConstant(method.returnType);
+ int computeRelevanceForExpectingType = computeRelevanceForExpectingType(method.returnType);
+ if(this.strictMatchForExtepectedType && computeRelevanceForExpectingType <= 0) {
+ continue;
+ } else if(!this.strictMatchForExtepectedType) {
+ relevance += computeRelevanceForExpectingType;
+ }
+
+ int computeRelevanceForEnumConstant = computeRelevanceForEnumConstant(method.returnType);
+ if(this.strictMatchForExtepectedType && computeRelevanceForEnumConstant <= 0) {
+ continue;
+ } else if(!this.strictMatchForExtepectedType) {
+ relevance += computeRelevanceForEnumConstant;
+ }
+
relevance += computeRelevanceForStatic(true, method.isStatic());
relevance += computeRelevanceForQualification(false);
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
@@ -12652,6 +12734,17 @@ public final class CompletionEngine
Scope invocationScope,
boolean insideTypeAnnotation,
boolean insideAnnotationAttribute) {
+ findVariablesAndMethods(token, scope, invocationSite, invocationScope, insideTypeAnnotation, insideAnnotationAttribute, true, new ObjectVector());
+ }
+ private void findVariablesAndMethods(
+ char[] token,
+ Scope scope,
+ InvocationSite invocationSite,
+ Scope invocationScope,
+ boolean insideTypeAnnotation,
+ boolean insideAnnotationAttribute,
+ boolean canBePrefixed,
+ ObjectVector methodsFound) {
if (token == null)
return;
@@ -12665,7 +12758,6 @@ public final class CompletionEngine
ObjectVector localsFound = new ObjectVector();
ObjectVector fieldsFound = new ObjectVector();
- ObjectVector methodsFound = new ObjectVector();
Scope currentScope = scope;
@@ -12741,7 +12833,13 @@ public final class CompletionEngine
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal(local);
relevance += computeRelevanceForCaseMatching(token, local.name);
- relevance += computeRelevanceForExpectingType(local.type);
+ int computeRelevanceForExpectingType = computeRelevanceForExpectingType(local.type);
+ if(this.strictMatchForExtepectedType && computeRelevanceForExpectingType <= 0) {
+ continue;
+ } else if(!this.strictMatchForExtepectedType) {
+ relevance += computeRelevanceForExpectingType;
+ }
+
relevance += computeRelevanceForEnumConstant(local.type);
relevance += computeRelevanceForQualification(false);
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for local variable
@@ -12820,7 +12918,7 @@ public final class CompletionEngine
invocationSite,
invocationScope,
true,
- true,
+ canBePrefixed,
null,
null,
null,
@@ -12843,7 +12941,7 @@ public final class CompletionEngine
invocationScope,
true,
false,
- true,
+ canBePrefixed,
null,
null,
null,

Back to the top