### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java,v retrieving revision 1.100 diff -u -r1.100 CompletionTests_1_5.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java 14 Apr 2008 09:28:01 -0000 1.100 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java 16 Apr 2008 10:56:12 -0000 @@ -3596,7 +3596,7 @@ result.context); assertResults( - "RED[FIELD_REF]{RED, Ltest0136.Colors;, Ltest0136.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM_CONSTANT) + "}", + "RED[FIELD_REF]{RED, Ltest0136.Colors;, Ltest0136.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM + R_ENUM_CONSTANT + R_RESOLVED) + "}", result.proposals); } finally { if(enumeration != null) { @@ -3635,7 +3635,7 @@ result.context); assertResults( - "RED[FIELD_REF]{RED, Ltest0137.Colors;, Ltest0137.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM_CONSTANT) + "}", + "RED[FIELD_REF]{RED, Ltest0137.Colors;, Ltest0137.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM + R_ENUM_CONSTANT + R_RESOLVED) + "}", result.proposals); } finally { if(enumeration != null) { @@ -3675,7 +3675,7 @@ result.context); assertResults( - "RED[FIELD_REF]{RED, Ltest0138.Colors;, Ltest0138.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM_CONSTANT) + "}", + "RED[FIELD_REF]{RED, Ltest0138.Colors;, Ltest0138.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM + R_ENUM_CONSTANT + R_RESOLVED) + "}", result.proposals); } finally { if(enumeration != null) { @@ -3714,7 +3714,7 @@ result.context); assertResults( - "RED[FIELD_REF]{RED, Ltest0139.Colors;, Ltest0139.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM_CONSTANT) + "}", + "RED[FIELD_REF]{RED, Ltest0139.Colors;, Ltest0139.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM + R_ENUM_CONSTANT + R_RESOLVED) + "}", result.proposals); } finally { if(enumeration != null) { @@ -3753,7 +3753,7 @@ result.context); assertResults( - "RED[FIELD_REF]{RED, Ltest0140.Colors;, Ltest0140.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM_CONSTANT) + "}", + "RED[FIELD_REF]{RED, Ltest0140.Colors;, Ltest0140.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM + R_ENUM_CONSTANT + R_RESOLVED) + "}", result.proposals); } finally { if(enumeration != null) { @@ -3835,7 +3835,7 @@ result.context); assertResults( - "RED[FIELD_REF]{RED, Ltest0142.Colors;, Ltest0142.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM_CONSTANT) + "}", + "RED[FIELD_REF]{RED, Ltest0142.Colors;, Ltest0142.Colors;, RED, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_NAME + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED + R_ENUM + R_ENUM_CONSTANT + R_RESOLVED) + "}", result.proposals); } finally { if(enumeration != null) { @@ -6713,8 +6713,8 @@ result.context); assertResults( - "BLACK[FIELD_REF]{BLACK, Lp.Colors;, Lp.Colors;, BLACK, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_ENUM + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + - "WHITE[FIELD_REF]{WHITE, Lp.Colors;, Lp.Colors;, WHITE, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_ENUM + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", + "BLACK[FIELD_REF]{BLACK, Lp.Colors;, Lp.Colors;, BLACK, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_ENUM + R_ENUM_CONSTANT + R_UNQUALIFIED + R_NON_RESTRICTED + R_RESOLVED) + "}\n" + + "WHITE[FIELD_REF]{WHITE, Lp.Colors;, Lp.Colors;, WHITE, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_ENUM + R_ENUM_CONSTANT + R_UNQUALIFIED + R_NON_RESTRICTED + R_RESOLVED) + "}", result.proposals); } finally { if(aType != null) { @@ -8244,9 +8244,9 @@ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); assertResults( - "bar[FIELD_REF]{bar, Lenumbug.EnumBug$Foo;, Lenumbug.EnumBug$Foo;, bar, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + - "baz[FIELD_REF]{baz, Lenumbug.EnumBug$Foo;, Lenumbug.EnumBug$Foo;, baz, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + - "foo[FIELD_REF]{foo, Lenumbug.EnumBug$Foo;, Lenumbug.EnumBug$Foo;, foo, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_EXPECTED_TYPE + R_NON_RESTRICTED) + "}", + "bar[FIELD_REF]{bar, Lenumbug.EnumBug$Foo;, Lenumbug.EnumBug$Foo;, bar, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_ENUM + R_ENUM_CONSTANT + R_NON_RESTRICTED + R_RESOLVED) + "}\n" + + "baz[FIELD_REF]{baz, Lenumbug.EnumBug$Foo;, Lenumbug.EnumBug$Foo;, baz, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_ENUM + R_ENUM_CONSTANT + R_NON_RESTRICTED + R_RESOLVED) + "}\n" + + "foo[FIELD_REF]{foo, Lenumbug.EnumBug$Foo;, Lenumbug.EnumBug$Foo;, foo, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_ENUM + R_ENUM_CONSTANT + R_NON_RESTRICTED + R_RESOLVED) + "}", requestor.getResults()); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=128169 @@ -11689,6 +11689,105 @@ "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()); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=161030 +public void test0364() throws JavaModelException { + this.workingCopies = new ICompilationUnit[2]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "import test.p.MyEnum;\n"+ + "public class Test {\n"+ + " void foo(MyEnum myEnumVar) {\n"+ + " foo(MyEnu\n"+ + " }\n"+ + "}\n"); + + this.workingCopies[1] = getWorkingCopy( + "/Completion/src/test/p/Math.java", + "package test.p;\n"+ + "public enum MyEnum {\n"+ + " MyEnum1, MyEnum2;\n"+ + "}n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "MyEnu"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "myEnumVar[LOCAL_VARIABLE_REF]{myEnumVar, null, Ltest.p.MyEnum;, myEnumVar, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_ENUM + R_ENUM_CONSTANT + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + + "MyEnum[TYPE_REF]{MyEnum, test.p, Ltest.p.MyEnum;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ENUM + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + + "MyEnum1[FIELD_REF]{MyEnum.MyEnum1, Ltest.p.MyEnum;, Ltest.p.MyEnum;, MyEnum1, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ENUM + R_ENUM_CONSTANT + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "MyEnum2[FIELD_REF]{MyEnum.MyEnum2, Ltest.p.MyEnum;, Ltest.p.MyEnum;, MyEnum2, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ENUM + R_ENUM_CONSTANT + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=161030 +public void test0365() throws JavaModelException { + this.workingCopies = new ICompilationUnit[2]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "import test.p.MyEnum;\n"+ + "public class Test {\n"+ + " void foo(MyEnum myEnumVar) {\n"+ + " foo(myEnu\n"+ + " }\n"+ + "}\n"); + + this.workingCopies[1] = getWorkingCopy( + "/Completion/src/test/p/Math.java", + "package test.p;\n"+ + "public enum MyEnum {\n"+ + " MyEnum1, MyEnum2;\n"+ + "}n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "myEnu"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "MyEnum[TYPE_REF]{MyEnum, test.p, Ltest.p.MyEnum;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_ENUM + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + + "MyEnum1[FIELD_REF]{MyEnum.MyEnum1, Ltest.p.MyEnum;, Ltest.p.MyEnum;, MyEnum1, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_ENUM + R_ENUM_CONSTANT + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "MyEnum2[FIELD_REF]{MyEnum.MyEnum2, Ltest.p.MyEnum;, Ltest.p.MyEnum;, MyEnum2, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_ENUM + R_ENUM_CONSTANT + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "myEnumVar[LOCAL_VARIABLE_REF]{myEnumVar, null, Ltest.p.MyEnum;, myEnumVar, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ENUM + R_ENUM_CONSTANT + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", + requestor.getResults()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=161030 +public void test0366() throws JavaModelException { + this.workingCopies = new ICompilationUnit[2]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test.java", + "package test;\n"+ + "import test.p.MyEnum;\n"+ + "public class Test {\n"+ + " void foo(MyEnum MyEnumVar) {\n"+ + " foo(MyEnu\n"+ + " }\n"+ + "}\n"); + + this.workingCopies[1] = getWorkingCopy( + "/Completion/src/test/p/Math.java", + "package test.p;\n"+ + "public enum MyEnum {\n"+ + " MyEnum1, MyEnum2;\n"+ + "}n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true); + String str = this.workingCopies[0].getSource(); + String completeBehind = "MyEnu"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + + assertResults( + "MyEnum[TYPE_REF]{MyEnum, test.p, Ltest.p.MyEnum;, null, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ENUM + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + + "MyEnum1[FIELD_REF]{MyEnum.MyEnum1, Ltest.p.MyEnum;, Ltest.p.MyEnum;, MyEnum1, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ENUM + R_ENUM_CONSTANT + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "MyEnum2[FIELD_REF]{MyEnum.MyEnum2, Ltest.p.MyEnum;, Ltest.p.MyEnum;, MyEnum2, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ENUM + R_ENUM_CONSTANT + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "MyEnumVar[LOCAL_VARIABLE_REF]{MyEnumVar, null, Ltest.p.MyEnum;, MyEnumVar, null, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_ENUM + R_ENUM_CONSTANT + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", + requestor.getResults()); +} //https://bugs.eclipse.org/bugs/show_bug.cgi?id=153130 public void testEC001() throws JavaModelException { this.workingCopies = new ICompilationUnit[1]; #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/RelevanceConstants.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/RelevanceConstants.java,v retrieving revision 1.33 diff -u -r1.33 RelevanceConstants.java --- codeassist/org/eclipse/jdt/internal/codeassist/RelevanceConstants.java 26 Apr 2007 11:27:48 -0000 1.33 +++ codeassist/org/eclipse/jdt/internal/codeassist/RelevanceConstants.java 16 Apr 2008 10:56:27 -0000 @@ -24,7 +24,7 @@ int R_ENUM = 20; int R_ANNOTATION = 20; int R_EXCEPTION = 20; - int R_ENUM_CONSTANT = 20; + int R_ENUM_CONSTANT = 5; int R_ABSTRACT_METHOD = 20; int R_NON_STATIC = 11; int R_UNQUALIFIED = 3; 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.364 diff -u -r1.364 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 14 Apr 2008 09:28:05 -0000 1.364 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 16 Apr 2008 10:56:27 -0000 @@ -1107,11 +1107,21 @@ && switchStatement.expression.resolvedType.isEnum()) { if (!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) { this.assistNodeIsEnum = true; - this.findEnumConstant(this.completionToken, (SwitchStatement) astNodeParent); + this.findEnumConstantsFromSwithStatement(this.completionToken, (SwitchStatement) astNodeParent); } } else if (this.expectedTypesPtr > -1 && this.expectedTypes[0].isAnnotationType()) { findTypesAndPackages(this.completionToken, scope, false, false, new ObjectVector()); } else { + if (this.expectedTypesPtr > -1) { + this.assistNodeIsEnum = true; + done : for (int i = 0; i <= this.expectedTypesPtr; i++) { + if (!this.expectedTypes[i].isEnum()) { + this.assistNodeIsEnum = false; + break done; + } + } + + } if (scope instanceof BlockScope && !this.requestor.isIgnored(CompletionProposal.LOCAL_VARIABLE_REF)) { char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, singleNameReference); @@ -2781,7 +2791,7 @@ } } } - private void findEnumConstant(char[] enumConstantName, SwitchStatement switchStatement) { + private void findEnumConstantsFromSwithStatement(char[] enumConstantName, SwitchStatement switchStatement) { TypeBinding expressionType = switchStatement.expression.resolvedType; if(expressionType != null && expressionType.isEnum()) { ReferenceBinding enumType = (ReferenceBinding) expressionType; @@ -2798,56 +2808,14 @@ } } - FieldBinding[] fields = enumType.fields(); - - int enumConstantLength = enumConstantName.length; - next : for (int f = fields.length; --f >= 0;) { - FieldBinding field = fields[f]; - - if (field.isSynthetic()) continue next; - - if ((field.modifiers & Flags.AccEnum) == 0) continue next; - - if (enumConstantLength > field.name.length) continue next; - - if (!CharOperation.prefixEquals(enumConstantName, field.name, false /* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(enumConstantName, field.name))) continue next; - - char[] completion = field.name; - - for (int i = 0; i < alreadyUsedConstantCount; i++) { - if(CharOperation.equals(alreadyUsedConstants[i], completion)) continue next; - } - - int relevance = computeBaseRelevance(); - relevance += computeRelevanceForInterestingProposal(field); - relevance += computeRelevanceForEnum(); - relevance += computeRelevanceForCaseMatching(enumConstantName, field.name); - relevance += computeRelevanceForExpectingType(field.type); - relevance += computeRelevanceForQualification(false); - relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); - - this.noProposal = false; - if(!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) { - CompletionProposal proposal = this.createProposal(CompletionProposal.FIELD_REF, this.actualCompletionPosition); - proposal.setDeclarationSignature(getSignature(field.declaringClass)); - proposal.setSignature(getSignature(field.type)); - proposal.setDeclarationPackageName(field.declaringClass.qualifiedPackageName()); - proposal.setDeclarationTypeName(field.declaringClass.qualifiedSourceName()); - proposal.setPackageName(field.type.qualifiedPackageName()); - proposal.setTypeName(field.type.qualifiedSourceName()); - proposal.setName(field.name); - proposal.setCompletion(completion); - proposal.setFlags(field.modifiers); - proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); - proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset); - proposal.setRelevance(relevance); - this.requestor.accept(proposal); - if(DEBUG) { - this.printDebug(proposal); - } - } - } + findEnumConstants( + enumConstantName, + enumType, + null /* doesn't need invocation scope */, + new ObjectVector(), + alreadyUsedConstants, + alreadyUsedConstantCount, + false); } } @@ -3524,6 +3492,7 @@ relevance += computeRelevanceForInterestingProposal(field); if (fieldName != null) relevance += computeRelevanceForCaseMatching(fieldName, field.name); relevance += computeRelevanceForExpectingType(field.type); + relevance += computeRelevanceForEnumConstant(field.type); relevance += computeRelevanceForStatic(onlyStaticFields, field.isStatic()); relevance += computeRelevanceForQualification(prefixRequired); relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); @@ -4437,6 +4406,7 @@ relevance += computeRelevanceForInterestingProposal(field); if (fieldName != null) relevance += computeRelevanceForCaseMatching(fieldName, field.name); relevance += computeRelevanceForExpectingType(field.type); + relevance += computeRelevanceForEnumConstant(field.type); relevance += computeRelevanceForStatic(true, true); relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); @@ -5992,6 +5962,7 @@ relevance += computeRelevanceForInterestingProposal(); if (methodName != null) relevance += computeRelevanceForCaseMatching(methodName, method.selector); relevance += computeRelevanceForExpectingType(method.returnType); + relevance += computeRelevanceForEnumConstant(method.returnType); relevance += computeRelevanceForStatic(onlyStaticMethods, method.isStatic()); relevance += computeRelevanceForQualification(prefixRequired); relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); @@ -6251,6 +6222,7 @@ relevance += computeRelevanceForInterestingProposal(); if (methodName != null) relevance += computeRelevanceForCaseMatching(methodName, method.selector); relevance += computeRelevanceForExpectingType(method.returnType); + relevance += computeRelevanceForEnumConstant(method.returnType); relevance += computeRelevanceForStatic(true, method.isStatic()); relevance += computeRelevanceForQualification(true); relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); @@ -6522,6 +6494,7 @@ relevance += computeRelevanceForInterestingProposal(); relevance += computeRelevanceForCaseMatching(methodName, method.selector); relevance += computeRelevanceForExpectingType(method.returnType); + relevance += computeRelevanceForEnumConstant(method.returnType); relevance += computeRelevanceForStatic(true, method.isStatic()); relevance += computeRelevanceForQualification(false); relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); @@ -6643,6 +6616,20 @@ } return 0; } + private int computeRelevanceForEnumConstant(TypeBinding proposalType){ + if(this.assistNodeIsEnum && + proposalType != null && + this.expectedTypes != null) { + for (int i = 0; i <= this.expectedTypesPtr; i++) { + if (proposalType.isEnum() && + proposalType == this.expectedTypes[i]) { + return R_ENUM + R_ENUM_CONSTANT; + } + + } + } + return 0; + } private int computeRelevanceForException(){ if (this.assistNodeIsException) { return R_EXCEPTION; @@ -8186,6 +8173,7 @@ relevance += computeRelevanceForInterestingProposal(local); relevance += computeRelevanceForCaseMatching(token, local.name); relevance += computeRelevanceForExpectingType(local.type); + relevance += computeRelevanceForEnumConstant(local.type); relevance += computeRelevanceForQualification(false); relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for local variable this.noProposal = false; @@ -8329,6 +8317,171 @@ fieldsFound, methodsFound); } + + findEnumConstantsFromExpectedTypes( + token, + invocationScope, + fieldsFound); + } + } + + private void findEnumConstantsFromExpectedTypes( + char[] token, + Scope invocationScope, + ObjectVector fieldsFound) { + int length = this.expectedTypesPtr + 1; + for (int i = 0; i < length; i++) { + if (this.expectedTypes[i].isEnum()) { + findEnumConstants( + token, + (ReferenceBinding)this.expectedTypes[i], + invocationScope, + fieldsFound, + CharOperation.NO_CHAR_CHAR, + 0, + true); + } + } + + } + + private void findEnumConstants( + char[] enumConstantName, + ReferenceBinding enumType, + Scope invocationScope, + ObjectVector fieldsFound, + char[][] alreadyUsedConstants, + int alreadyUsedConstantCount, + boolean needQualification) { + + FieldBinding[] fields = enumType.fields(); + + int enumConstantLength = enumConstantName.length; + next : for (int f = fields.length; --f >= 0;) { + FieldBinding field = fields[f]; + + if (field.isSynthetic()) continue next; + + if ((field.modifiers & Flags.AccEnum) == 0) continue next; + + if (enumConstantLength > field.name.length) continue next; + + if (!CharOperation.prefixEquals(enumConstantName, field.name, false /* ignore case */) + && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(enumConstantName, field.name))) continue next; + + char[] fieldName = field.name; + + for (int i = 0; i < alreadyUsedConstantCount; i++) { + if(CharOperation.equals(alreadyUsedConstants[i], fieldName)) continue next; + } + + int relevance = computeBaseRelevance(); + relevance += computeRelevanceForResolution(); + relevance += computeRelevanceForInterestingProposal(field); + relevance += computeRelevanceForCaseMatching(enumConstantName, field.name); + relevance += computeRelevanceForExpectingType(field.type); + relevance += computeRelevanceForEnumConstant(field.type); + relevance += computeRelevanceForQualification(needQualification); + relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); + + this.noProposal = false; + if (!needQualification) { + char[] completion = fieldName; + + if(!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) { + CompletionProposal proposal = this.createProposal(CompletionProposal.FIELD_REF, this.actualCompletionPosition); + proposal.setDeclarationSignature(getSignature(field.declaringClass)); + proposal.setSignature(getSignature(field.type)); + proposal.setDeclarationPackageName(field.declaringClass.qualifiedPackageName()); + proposal.setDeclarationTypeName(field.declaringClass.qualifiedSourceName()); + proposal.setPackageName(field.type.qualifiedPackageName()); + proposal.setTypeName(field.type.qualifiedSourceName()); + proposal.setName(field.name); + proposal.setCompletion(completion); + proposal.setFlags(field.modifiers); + proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); + proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset); + proposal.setRelevance(relevance); + this.requestor.accept(proposal); + if(DEBUG) { + this.printDebug(proposal); + } + } + + } else { + TypeBinding visibleType = invocationScope.getType(field.type.sourceName()); + boolean needImport = visibleType == null || !visibleType.isValidBinding(); + + char[] completion = CharOperation.concat(field.type.sourceName(), field.name, '.'); + + if (!needImport) { + if(!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) { + CompletionProposal proposal = this.createProposal(CompletionProposal.FIELD_REF, this.actualCompletionPosition); + proposal.setDeclarationSignature(getSignature(field.declaringClass)); + proposal.setSignature(getSignature(field.type)); + proposal.setDeclarationPackageName(field.declaringClass.qualifiedPackageName()); + proposal.setDeclarationTypeName(field.declaringClass.qualifiedSourceName()); + proposal.setPackageName(field.type.qualifiedPackageName()); + proposal.setTypeName(field.type.qualifiedSourceName()); + proposal.setName(field.name); + proposal.setCompletion(completion); + proposal.setFlags(field.modifiers); + proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); + proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset); + proposal.setRelevance(relevance); + this.requestor.accept(proposal); + if(DEBUG) { + this.printDebug(proposal); + } + } + } else { + if (!this.isIgnored(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT)) { + CompilationUnitDeclaration cu = this.unitScope.referenceContext; + int importStart = cu.types[0].declarationSourceStart; + int importEnd = importStart; + + ReferenceBinding fieldType = (ReferenceBinding)field.type; + + CompletionProposal proposal = this.createProposal(CompletionProposal.FIELD_REF, this.actualCompletionPosition); + proposal.setDeclarationSignature(getSignature(field.declaringClass)); + proposal.setSignature(getSignature(field.type)); + proposal.setDeclarationPackageName(field.declaringClass.qualifiedPackageName()); + proposal.setDeclarationTypeName(field.declaringClass.qualifiedSourceName()); + proposal.setPackageName(field.type.qualifiedPackageName()); + proposal.setTypeName(field.type.qualifiedSourceName()); + proposal.setName(field.name); + proposal.setCompletion(completion); + proposal.setFlags(field.modifiers); + proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); + proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset); + proposal.setRelevance(relevance); + + char[] typeImportCompletion = createImportCharArray(CharOperation.concatWith(fieldType.compoundName, '.'), false, false); + + CompletionProposal typeImportProposal = this.createProposal(CompletionProposal.TYPE_IMPORT, this.actualCompletionPosition); + typeImportProposal.nameLookup = this.nameEnvironment.nameLookup; + typeImportProposal.completionEngine = this; + char[] packageName = fieldType.qualifiedPackageName(); + typeImportProposal.setDeclarationSignature(packageName); + typeImportProposal.setSignature(getSignature(fieldType)); + typeImportProposal.setPackageName(packageName); + typeImportProposal.setTypeName(fieldType.qualifiedSourceName()); + typeImportProposal.setCompletion(typeImportCompletion); + typeImportProposal.setFlags(fieldType.modifiers); + typeImportProposal.setAdditionalFlags(CompletionFlags.Default); + typeImportProposal.setReplaceRange(importStart - this.offset, importEnd - this.offset); + typeImportProposal.setTokenRange(importStart - this.offset, importEnd - this.offset); + typeImportProposal.setRelevance(relevance); + + proposal.setRequiredProposals(new CompletionProposal[]{typeImportProposal}); + + this.requestor.accept(proposal); + if(DEBUG) { + this.printDebug(proposal); + } + } + } + } } }