### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/core/CompletionProposal.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/CompletionProposal.java,v retrieving revision 1.46 diff -u -r1.46 CompletionProposal.java --- model/org/eclipse/jdt/core/CompletionProposal.java 18 Sep 2008 14:06:39 -0000 1.46 +++ model/org/eclipse/jdt/core/CompletionProposal.java 12 Jan 2009 15:07:33 -0000 @@ -1463,6 +1463,11 @@ *
TYPE_REF
ANONYMOUS_CLASS_DECLARATION
- The allowed required proposals for this kind are:
+ * TYPE_REF
Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java,v
retrieving revision 1.383
diff -u -r1.383 CompletionEngine.java
--- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 8 Jan 2009 20:51:06 -0000 1.383
+++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 12 Jan 2009 15:07:32 -0000
@@ -1540,6 +1540,10 @@
argTypes,
scope,
constructorCall,
+ false,
+ null,
+ null,
+ null,
false);
}
}
@@ -1618,7 +1622,7 @@
ReferenceBinding ref = (ReferenceBinding) qualifiedBinding;
if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF) && ref.isClass()) {
- findConstructors(ref, argTypes, scope, allocExpression, false);
+ findConstructors(ref, argTypes, scope, allocExpression, false, null, null, null, false);
}
}
//TODO
@@ -1690,7 +1694,7 @@
if (this.completionToken == null
|| CharOperation.prefixEquals(this.completionToken, refBinding.sourceName)
|| (this.options.camelCaseMatch && CharOperation.camelCaseMatch(this.completionToken, refBinding.sourceName))) {
- findConstructors(refBinding, null, scope, fieldRef, false);
+ findConstructors(refBinding, null, scope, fieldRef, false, null, null, null, false);
}
}
}
@@ -2277,27 +2281,44 @@
TypeBinding[] argTypes = computeTypes(allocExpression.arguments);
ReferenceBinding ref = (ReferenceBinding) qualifiedBinding;
- if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)
- && ref.isClass()
- && !ref.isAbstract()) {
- findConstructors(
+
+ if (ref.problemId() == ProblemReasons.NotFound) {
+ findConstructorsFromMissingType(
+ allocExpression.type,
+ argTypes,
+ scope,
+ allocExpression);
+ } else {
+ if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)
+ && ref.isClass()
+ && !ref.isAbstract()) {
+ findConstructors(
+ ref,
+ argTypes,
+ scope,
+ allocExpression,
+ false,
+ null,
+ null,
+ null,
+ false);
+ }
+
+ checkCancel();
+
+ if (!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION)
+ && !ref.isFinal()
+ && !ref.isEnum()){
+ findAnonymousType(
ref,
argTypes,
scope,
allocExpression,
+ null,
+ null,
+ null,
false);
- }
-
- checkCancel();
-
- if (!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION)
- && !ref.isFinal()
- && !ref.isEnum()){
- findAnonymousType(
- ref,
- argTypes,
- scope,
- allocExpression);
+ }
}
}
@@ -3942,11 +3963,15 @@
}
}
}
- private void findAnonymousType(
+ void findAnonymousType(
ReferenceBinding currentType,
TypeBinding[] argTypes,
Scope scope,
- InvocationSite invocationSite) {
+ InvocationSite invocationSite,
+ Binding[] missingElements,
+ int[] missingElementsStarts,
+ int[] missingElementsEnds,
+ boolean missingElementsHaveProblems) {
if (currentType.isInterface()) {
char[] completion = CharOperation.NO_CHAR;
@@ -3954,9 +3979,13 @@
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal();
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
+
+ if (missingElements != null) {
+ relevance += computeRelevanceForMissingElements(missingElementsHaveProblems);
+ }
this.noProposal = false;
- if(!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION)) {
+ if(!isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, missingElements != null)) {
InternalCompletionProposal proposal = createProposal(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, this.actualCompletionPosition);
proposal.setDeclarationSignature(getSignature(currentType));
proposal.setDeclarationKey(currentType.computeUniqueKey());
@@ -3974,6 +4003,18 @@
//proposal.setParameterTypeNames(null);
//proposal.setPackageName(null);
//proposal.setTypeName(null);
+ if (missingElements != null) {
+ CompletionProposal[] subProposals = new CompletionProposal[missingElements.length];
+ for (int i = 0; i < missingElements.length; i++) {
+ subProposals[i] =
+ createRequiredTypeProposal(
+ missingElements[i],
+ missingElementsStarts[i],
+ missingElementsEnds[i],
+ relevance);
+ }
+ proposal.setRequiredProposals(subProposals);
+ }
proposal.setCompletion(completion);
proposal.setFlags(Flags.AccPublic);
proposal.setReplaceRange(this.endPosition - this.offset, this.endPosition - this.offset);
@@ -3990,7 +4031,11 @@
argTypes,
scope,
invocationSite,
- true);
+ true,
+ missingElements,
+ missingElementsStarts,
+ missingElementsEnds,
+ missingElementsHaveProblems);
}
}
private void findClassField(
@@ -4069,12 +4114,16 @@
}
}
}
- private void findConstructors(
+ void findConstructors(
ReferenceBinding currentType,
TypeBinding[] argTypes,
Scope scope,
InvocationSite invocationSite,
- boolean forAnonymousType) {
+ boolean forAnonymousType,
+ Binding[] missingElements,
+ int[] missingElementsStarts,
+ int[] missingElementsEnds,
+ boolean missingElementsHaveProblems) {
// No visibility checks can be performed without the scope & invocationSite
MethodBinding[] methods = currentType.availableMethods();
@@ -4122,9 +4171,13 @@
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal();
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
+
+ if (missingElements != null) {
+ relevance += computeRelevanceForMissingElements(missingElementsHaveProblems);
+ }
this.noProposal = false;
- if(!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION)) {
+ if(!this.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, missingElements != null)) {
InternalCompletionProposal proposal = createProposal(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, this.actualCompletionPosition);
proposal.setDeclarationSignature(getSignature(currentType));
proposal.setDeclarationKey(currentType.computeUniqueKey());
@@ -4140,6 +4193,18 @@
proposal.setParameterTypeNames(parameterTypeNames);
//proposal.setPackageName(null);
//proposal.setTypeName(null);
+ if (missingElements != null) {
+ CompletionProposal[] subProposals = new CompletionProposal[missingElements.length];
+ for (int i = 0; i < missingElements.length; i++) {
+ subProposals[i] =
+ createRequiredTypeProposal(
+ missingElements[i],
+ missingElementsStarts[i],
+ missingElementsEnds[i],
+ relevance);
+ }
+ proposal.setRequiredProposals(subProposals);
+ }
proposal.setCompletion(completion);
proposal.setFlags(constructor.modifiers);
proposal.setReplaceRange(this.endPosition - this.offset, this.endPosition - this.offset);
@@ -4156,6 +4221,10 @@
relevance += computeRelevanceForResolution();
relevance += computeRelevanceForInterestingProposal();
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
+
+ if (missingElements != null) {
+ relevance += computeRelevanceForMissingElements(missingElementsHaveProblems);
+ }
// Special case for completion in javadoc
if (this.assistNodeInJavadoc > 0) {
@@ -4212,7 +4281,7 @@
// Create standard proposal
this.noProposal = false;
- if(!this.requestor.isIgnored(CompletionProposal.METHOD_REF) && (this.assistNodeInJavadoc & CompletionOnJavadoc.ONLY_INLINE_TAG) == 0) {
+ if(!this.isIgnored(CompletionProposal.METHOD_REF, missingElements != null) && (this.assistNodeInJavadoc & CompletionOnJavadoc.ONLY_INLINE_TAG) == 0) {
InternalCompletionProposal proposal = createProposal(CompletionProposal.METHOD_REF, this.actualCompletionPosition);
proposal.setDeclarationSignature(getSignature(currentType));
proposal.setSignature(getSignature(constructor));
@@ -4227,6 +4296,18 @@
//proposal.setPackageName(null);
//proposal.setTypeName(null);
proposal.setName(currentType.sourceName());
+ if (missingElements != null) {
+ CompletionProposal[] subProposals = new CompletionProposal[missingElements.length];
+ for (int i = 0; i < missingElements.length; i++) {
+ subProposals[i] =
+ createRequiredTypeProposal(
+ missingElements[i],
+ missingElementsStarts[i],
+ missingElementsEnds[i],
+ relevance);
+ }
+ proposal.setRequiredProposals(subProposals);
+ }
proposal.setIsContructor(true);
proposal.setCompletion(completion);
proposal.setFlags(constructor.modifiers);
@@ -5925,6 +6006,58 @@
};
missingTypesConverter.guess(typeRef, scope, substitutionRequestor);
}
+
+ private void findConstructorsFromMissingType(
+ TypeReference typeRef,
+ final TypeBinding[] argTypes,
+ final Scope scope,
+ final InvocationSite invocationSite) {
+ MissingTypesGuesser missingTypesConverter = new MissingTypesGuesser(this);
+ MissingTypesGuesser.GuessedTypeRequestor substitutionRequestor =
+ new MissingTypesGuesser.GuessedTypeRequestor() {
+ public void accept(
+ TypeBinding guessedType,
+ Binding[] missingElements,
+ int[] missingElementsStarts,
+ int[] missingElementsEnds,
+ boolean hasProblems) {
+ if (guessedType instanceof ReferenceBinding) {
+ ReferenceBinding ref = (ReferenceBinding) guessedType;
+ if (!isIgnored(CompletionProposal.METHOD_REF, missingElements != null)
+ && ref.isClass()
+ && !ref.isAbstract()) {
+ findConstructors(
+ ref,
+ argTypes,
+ scope,
+ invocationSite,
+ false,
+ missingElements,
+ missingElementsStarts,
+ missingElementsEnds,
+ hasProblems);
+ }
+
+ checkCancel();
+
+ if (!isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, missingElements != null)
+ && !ref.isFinal()
+ && !ref.isEnum()){
+ findAnonymousType(
+ ref,
+ argTypes,
+ scope,
+ invocationSite,
+ missingElements,
+ missingElementsStarts,
+ missingElementsEnds,
+ hasProblems);
+ }
+ }
+ }
+ };
+ missingTypesConverter.guess(typeRef, scope, substitutionRequestor);
+ }
private void findFieldsAndMethodsFromStaticImports(
char[] token,
@@ -10275,7 +10408,7 @@
private boolean isIgnored(int kind) {
return this.requestor.isIgnored(kind);
}
- private boolean isIgnored(int kind, boolean missingTypes) {
+ boolean isIgnored(int kind, boolean missingTypes) {
return this.requestor.isIgnored(kind) ||
(missingTypes && !this.requestor.isAllowingRequiredProposals(kind, CompletionProposal.TYPE_REF));
}
#P org.eclipse.jdt.core.tests.model
Index: src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests.java,v
retrieving revision 1.11
diff -u -r1.11 CompletionWithMissingTypesTests.java
--- src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests.java 9 Sep 2008 12:43:37 -0000 1.11
+++ src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests.java 12 Jan 2009 15:07:34 -0000
@@ -1667,4 +1667,209 @@
" MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
requestor.getResults());
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=260717
+public void test0041() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "package test;"+
+ "public class Test {\n" +
+ " void foo() {\n" +
+ " new MissingType(\n" +
+ " }\n" +
+ "}\n");
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Completion/src/missing/MissingType.java",
+ "package missing;"+
+ "public class MissingType {\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "new MissingType(";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED + R_NO_PROBLEMS;
+ int start1 = str.lastIndexOf("new MissingType(") + "new MissingType(".length();
+ int end1 = start1 + "".length();
+ int start2 = str.indexOf("MissingType");
+ int end2 = start2 + "MissingType".length();
+ assertResults(
+ "MissingType[ANONYMOUS_CLASS_DECLARATION]{, Lmissing.MissingType;, ()V, null, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
+ " MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}\n" +
+ "MissingType[METHOD_REF