Lines 1107-1117
Link Here
|
1107 |
&& switchStatement.expression.resolvedType.isEnum()) { |
1107 |
&& switchStatement.expression.resolvedType.isEnum()) { |
1108 |
if (!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) { |
1108 |
if (!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) { |
1109 |
this.assistNodeIsEnum = true; |
1109 |
this.assistNodeIsEnum = true; |
1110 |
this.findEnumConstant(this.completionToken, (SwitchStatement) astNodeParent); |
1110 |
this.findEnumConstantsFromSwithStatement(this.completionToken, (SwitchStatement) astNodeParent); |
1111 |
} |
1111 |
} |
1112 |
} else if (this.expectedTypesPtr > -1 && this.expectedTypes[0].isAnnotationType()) { |
1112 |
} else if (this.expectedTypesPtr > -1 && this.expectedTypes[0].isAnnotationType()) { |
1113 |
findTypesAndPackages(this.completionToken, scope, false, false, new ObjectVector()); |
1113 |
findTypesAndPackages(this.completionToken, scope, false, false, new ObjectVector()); |
1114 |
} else { |
1114 |
} else { |
|
|
1115 |
if (this.expectedTypesPtr > -1) { |
1116 |
this.assistNodeIsEnum = true; |
1117 |
done : for (int i = 0; i <= this.expectedTypesPtr; i++) { |
1118 |
if (!this.expectedTypes[i].isEnum()) { |
1119 |
this.assistNodeIsEnum = false; |
1120 |
break done; |
1121 |
} |
1122 |
} |
1123 |
|
1124 |
} |
1115 |
if (scope instanceof BlockScope && !this.requestor.isIgnored(CompletionProposal.LOCAL_VARIABLE_REF)) { |
1125 |
if (scope instanceof BlockScope && !this.requestor.isIgnored(CompletionProposal.LOCAL_VARIABLE_REF)) { |
1116 |
char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, singleNameReference); |
1126 |
char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, singleNameReference); |
1117 |
|
1127 |
|
Lines 2781-2787
Link Here
|
2781 |
} |
2791 |
} |
2782 |
} |
2792 |
} |
2783 |
} |
2793 |
} |
2784 |
private void findEnumConstant(char[] enumConstantName, SwitchStatement switchStatement) { |
2794 |
private void findEnumConstantsFromSwithStatement(char[] enumConstantName, SwitchStatement switchStatement) { |
2785 |
TypeBinding expressionType = switchStatement.expression.resolvedType; |
2795 |
TypeBinding expressionType = switchStatement.expression.resolvedType; |
2786 |
if(expressionType != null && expressionType.isEnum()) { |
2796 |
if(expressionType != null && expressionType.isEnum()) { |
2787 |
ReferenceBinding enumType = (ReferenceBinding) expressionType; |
2797 |
ReferenceBinding enumType = (ReferenceBinding) expressionType; |
Lines 2798-2853
Link Here
|
2798 |
} |
2808 |
} |
2799 |
} |
2809 |
} |
2800 |
|
2810 |
|
2801 |
FieldBinding[] fields = enumType.fields(); |
2811 |
findEnumConstants( |
2802 |
|
2812 |
enumConstantName, |
2803 |
int enumConstantLength = enumConstantName.length; |
2813 |
enumType, |
2804 |
next : for (int f = fields.length; --f >= 0;) { |
2814 |
null /* doesn't need invocation scope */, |
2805 |
FieldBinding field = fields[f]; |
2815 |
new ObjectVector(), |
2806 |
|
2816 |
alreadyUsedConstants, |
2807 |
if (field.isSynthetic()) continue next; |
2817 |
alreadyUsedConstantCount, |
2808 |
|
2818 |
false); |
2809 |
if ((field.modifiers & Flags.AccEnum) == 0) continue next; |
|
|
2810 |
|
2811 |
if (enumConstantLength > field.name.length) continue next; |
2812 |
|
2813 |
if (!CharOperation.prefixEquals(enumConstantName, field.name, false /* ignore case */) |
2814 |
&& !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(enumConstantName, field.name))) continue next; |
2815 |
|
2816 |
char[] completion = field.name; |
2817 |
|
2818 |
for (int i = 0; i < alreadyUsedConstantCount; i++) { |
2819 |
if(CharOperation.equals(alreadyUsedConstants[i], completion)) continue next; |
2820 |
} |
2821 |
|
2822 |
int relevance = computeBaseRelevance(); |
2823 |
relevance += computeRelevanceForInterestingProposal(field); |
2824 |
relevance += computeRelevanceForEnum(); |
2825 |
relevance += computeRelevanceForCaseMatching(enumConstantName, field.name); |
2826 |
relevance += computeRelevanceForExpectingType(field.type); |
2827 |
relevance += computeRelevanceForQualification(false); |
2828 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
2829 |
|
2830 |
this.noProposal = false; |
2831 |
if(!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) { |
2832 |
CompletionProposal proposal = this.createProposal(CompletionProposal.FIELD_REF, this.actualCompletionPosition); |
2833 |
proposal.setDeclarationSignature(getSignature(field.declaringClass)); |
2834 |
proposal.setSignature(getSignature(field.type)); |
2835 |
proposal.setDeclarationPackageName(field.declaringClass.qualifiedPackageName()); |
2836 |
proposal.setDeclarationTypeName(field.declaringClass.qualifiedSourceName()); |
2837 |
proposal.setPackageName(field.type.qualifiedPackageName()); |
2838 |
proposal.setTypeName(field.type.qualifiedSourceName()); |
2839 |
proposal.setName(field.name); |
2840 |
proposal.setCompletion(completion); |
2841 |
proposal.setFlags(field.modifiers); |
2842 |
proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); |
2843 |
proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset); |
2844 |
proposal.setRelevance(relevance); |
2845 |
this.requestor.accept(proposal); |
2846 |
if(DEBUG) { |
2847 |
this.printDebug(proposal); |
2848 |
} |
2849 |
} |
2850 |
} |
2851 |
} |
2819 |
} |
2852 |
} |
2820 |
} |
2853 |
|
2821 |
|
Lines 3524-3529
Link Here
|
3524 |
relevance += computeRelevanceForInterestingProposal(field); |
3492 |
relevance += computeRelevanceForInterestingProposal(field); |
3525 |
if (fieldName != null) relevance += computeRelevanceForCaseMatching(fieldName, field.name); |
3493 |
if (fieldName != null) relevance += computeRelevanceForCaseMatching(fieldName, field.name); |
3526 |
relevance += computeRelevanceForExpectingType(field.type); |
3494 |
relevance += computeRelevanceForExpectingType(field.type); |
|
|
3495 |
relevance += computeRelevanceForEnumConstant(field.type); |
3527 |
relevance += computeRelevanceForStatic(onlyStaticFields, field.isStatic()); |
3496 |
relevance += computeRelevanceForStatic(onlyStaticFields, field.isStatic()); |
3528 |
relevance += computeRelevanceForQualification(prefixRequired); |
3497 |
relevance += computeRelevanceForQualification(prefixRequired); |
3529 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
3498 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
Lines 4437-4442
Link Here
|
4437 |
relevance += computeRelevanceForInterestingProposal(field); |
4406 |
relevance += computeRelevanceForInterestingProposal(field); |
4438 |
if (fieldName != null) relevance += computeRelevanceForCaseMatching(fieldName, field.name); |
4407 |
if (fieldName != null) relevance += computeRelevanceForCaseMatching(fieldName, field.name); |
4439 |
relevance += computeRelevanceForExpectingType(field.type); |
4408 |
relevance += computeRelevanceForExpectingType(field.type); |
|
|
4409 |
relevance += computeRelevanceForEnumConstant(field.type); |
4440 |
relevance += computeRelevanceForStatic(true, true); |
4410 |
relevance += computeRelevanceForStatic(true, true); |
4441 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
4411 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
4442 |
|
4412 |
|
Lines 5992-5997
Link Here
|
5992 |
relevance += computeRelevanceForInterestingProposal(); |
5962 |
relevance += computeRelevanceForInterestingProposal(); |
5993 |
if (methodName != null) relevance += computeRelevanceForCaseMatching(methodName, method.selector); |
5963 |
if (methodName != null) relevance += computeRelevanceForCaseMatching(methodName, method.selector); |
5994 |
relevance += computeRelevanceForExpectingType(method.returnType); |
5964 |
relevance += computeRelevanceForExpectingType(method.returnType); |
|
|
5965 |
relevance += computeRelevanceForEnumConstant(method.returnType); |
5995 |
relevance += computeRelevanceForStatic(onlyStaticMethods, method.isStatic()); |
5966 |
relevance += computeRelevanceForStatic(onlyStaticMethods, method.isStatic()); |
5996 |
relevance += computeRelevanceForQualification(prefixRequired); |
5967 |
relevance += computeRelevanceForQualification(prefixRequired); |
5997 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
5968 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
Lines 6251-6256
Link Here
|
6251 |
relevance += computeRelevanceForInterestingProposal(); |
6222 |
relevance += computeRelevanceForInterestingProposal(); |
6252 |
if (methodName != null) relevance += computeRelevanceForCaseMatching(methodName, method.selector); |
6223 |
if (methodName != null) relevance += computeRelevanceForCaseMatching(methodName, method.selector); |
6253 |
relevance += computeRelevanceForExpectingType(method.returnType); |
6224 |
relevance += computeRelevanceForExpectingType(method.returnType); |
|
|
6225 |
relevance += computeRelevanceForEnumConstant(method.returnType); |
6254 |
relevance += computeRelevanceForStatic(true, method.isStatic()); |
6226 |
relevance += computeRelevanceForStatic(true, method.isStatic()); |
6255 |
relevance += computeRelevanceForQualification(true); |
6227 |
relevance += computeRelevanceForQualification(true); |
6256 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
6228 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
Lines 6522-6527
Link Here
|
6522 |
relevance += computeRelevanceForInterestingProposal(); |
6494 |
relevance += computeRelevanceForInterestingProposal(); |
6523 |
relevance += computeRelevanceForCaseMatching(methodName, method.selector); |
6495 |
relevance += computeRelevanceForCaseMatching(methodName, method.selector); |
6524 |
relevance += computeRelevanceForExpectingType(method.returnType); |
6496 |
relevance += computeRelevanceForExpectingType(method.returnType); |
|
|
6497 |
relevance += computeRelevanceForEnumConstant(method.returnType); |
6525 |
relevance += computeRelevanceForStatic(true, method.isStatic()); |
6498 |
relevance += computeRelevanceForStatic(true, method.isStatic()); |
6526 |
relevance += computeRelevanceForQualification(false); |
6499 |
relevance += computeRelevanceForQualification(false); |
6527 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
6500 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
Lines 6643-6648
Link Here
|
6643 |
} |
6616 |
} |
6644 |
return 0; |
6617 |
return 0; |
6645 |
} |
6618 |
} |
|
|
6619 |
private int computeRelevanceForEnumConstant(TypeBinding proposalType){ |
6620 |
if(this.assistNodeIsEnum && |
6621 |
proposalType != null && |
6622 |
this.expectedTypes != null) { |
6623 |
for (int i = 0; i <= this.expectedTypesPtr; i++) { |
6624 |
if (proposalType.isEnum() && |
6625 |
proposalType == this.expectedTypes[i]) { |
6626 |
return R_ENUM + R_ENUM_CONSTANT; |
6627 |
} |
6628 |
|
6629 |
} |
6630 |
} |
6631 |
return 0; |
6632 |
} |
6646 |
private int computeRelevanceForException(){ |
6633 |
private int computeRelevanceForException(){ |
6647 |
if (this.assistNodeIsException) { |
6634 |
if (this.assistNodeIsException) { |
6648 |
return R_EXCEPTION; |
6635 |
return R_EXCEPTION; |
Lines 8186-8191
Link Here
|
8186 |
relevance += computeRelevanceForInterestingProposal(local); |
8173 |
relevance += computeRelevanceForInterestingProposal(local); |
8187 |
relevance += computeRelevanceForCaseMatching(token, local.name); |
8174 |
relevance += computeRelevanceForCaseMatching(token, local.name); |
8188 |
relevance += computeRelevanceForExpectingType(local.type); |
8175 |
relevance += computeRelevanceForExpectingType(local.type); |
|
|
8176 |
relevance += computeRelevanceForEnumConstant(local.type); |
8189 |
relevance += computeRelevanceForQualification(false); |
8177 |
relevance += computeRelevanceForQualification(false); |
8190 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for local variable |
8178 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for local variable |
8191 |
this.noProposal = false; |
8179 |
this.noProposal = false; |
Lines 8329-8334
Link Here
|
8329 |
fieldsFound, |
8317 |
fieldsFound, |
8330 |
methodsFound); |
8318 |
methodsFound); |
8331 |
} |
8319 |
} |
|
|
8320 |
|
8321 |
findEnumConstantsFromExpectedTypes( |
8322 |
token, |
8323 |
invocationScope, |
8324 |
fieldsFound); |
8325 |
} |
8326 |
} |
8327 |
|
8328 |
private void findEnumConstantsFromExpectedTypes( |
8329 |
char[] token, |
8330 |
Scope invocationScope, |
8331 |
ObjectVector fieldsFound) { |
8332 |
int length = this.expectedTypesPtr + 1; |
8333 |
for (int i = 0; i < length; i++) { |
8334 |
if (this.expectedTypes[i].isEnum()) { |
8335 |
findEnumConstants( |
8336 |
token, |
8337 |
(ReferenceBinding)this.expectedTypes[i], |
8338 |
invocationScope, |
8339 |
fieldsFound, |
8340 |
CharOperation.NO_CHAR_CHAR, |
8341 |
0, |
8342 |
true); |
8343 |
} |
8344 |
} |
8345 |
|
8346 |
} |
8347 |
|
8348 |
private void findEnumConstants( |
8349 |
char[] enumConstantName, |
8350 |
ReferenceBinding enumType, |
8351 |
Scope invocationScope, |
8352 |
ObjectVector fieldsFound, |
8353 |
char[][] alreadyUsedConstants, |
8354 |
int alreadyUsedConstantCount, |
8355 |
boolean needQualification) { |
8356 |
|
8357 |
FieldBinding[] fields = enumType.fields(); |
8358 |
|
8359 |
int enumConstantLength = enumConstantName.length; |
8360 |
next : for (int f = fields.length; --f >= 0;) { |
8361 |
FieldBinding field = fields[f]; |
8362 |
|
8363 |
if (field.isSynthetic()) continue next; |
8364 |
|
8365 |
if ((field.modifiers & Flags.AccEnum) == 0) continue next; |
8366 |
|
8367 |
if (enumConstantLength > field.name.length) continue next; |
8368 |
|
8369 |
if (!CharOperation.prefixEquals(enumConstantName, field.name, false /* ignore case */) |
8370 |
&& !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(enumConstantName, field.name))) continue next; |
8371 |
|
8372 |
char[] fieldName = field.name; |
8373 |
|
8374 |
for (int i = 0; i < alreadyUsedConstantCount; i++) { |
8375 |
if(CharOperation.equals(alreadyUsedConstants[i], fieldName)) continue next; |
8376 |
} |
8377 |
|
8378 |
int relevance = computeBaseRelevance(); |
8379 |
relevance += computeRelevanceForResolution(); |
8380 |
relevance += computeRelevanceForInterestingProposal(field); |
8381 |
relevance += computeRelevanceForCaseMatching(enumConstantName, field.name); |
8382 |
relevance += computeRelevanceForExpectingType(field.type); |
8383 |
relevance += computeRelevanceForEnumConstant(field.type); |
8384 |
relevance += computeRelevanceForQualification(needQualification); |
8385 |
relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); |
8386 |
|
8387 |
this.noProposal = false; |
8388 |
if (!needQualification) { |
8389 |
char[] completion = fieldName; |
8390 |
|
8391 |
if(!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) { |
8392 |
CompletionProposal proposal = this.createProposal(CompletionProposal.FIELD_REF, this.actualCompletionPosition); |
8393 |
proposal.setDeclarationSignature(getSignature(field.declaringClass)); |
8394 |
proposal.setSignature(getSignature(field.type)); |
8395 |
proposal.setDeclarationPackageName(field.declaringClass.qualifiedPackageName()); |
8396 |
proposal.setDeclarationTypeName(field.declaringClass.qualifiedSourceName()); |
8397 |
proposal.setPackageName(field.type.qualifiedPackageName()); |
8398 |
proposal.setTypeName(field.type.qualifiedSourceName()); |
8399 |
proposal.setName(field.name); |
8400 |
proposal.setCompletion(completion); |
8401 |
proposal.setFlags(field.modifiers); |
8402 |
proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); |
8403 |
proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset); |
8404 |
proposal.setRelevance(relevance); |
8405 |
this.requestor.accept(proposal); |
8406 |
if(DEBUG) { |
8407 |
this.printDebug(proposal); |
8408 |
} |
8409 |
} |
8410 |
|
8411 |
} else { |
8412 |
TypeBinding visibleType = invocationScope.getType(field.type.sourceName()); |
8413 |
boolean needImport = visibleType == null || !visibleType.isValidBinding(); |
8414 |
|
8415 |
char[] completion = CharOperation.concat(field.type.sourceName(), field.name, '.'); |
8416 |
|
8417 |
if (!needImport) { |
8418 |
if(!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) { |
8419 |
CompletionProposal proposal = this.createProposal(CompletionProposal.FIELD_REF, this.actualCompletionPosition); |
8420 |
proposal.setDeclarationSignature(getSignature(field.declaringClass)); |
8421 |
proposal.setSignature(getSignature(field.type)); |
8422 |
proposal.setDeclarationPackageName(field.declaringClass.qualifiedPackageName()); |
8423 |
proposal.setDeclarationTypeName(field.declaringClass.qualifiedSourceName()); |
8424 |
proposal.setPackageName(field.type.qualifiedPackageName()); |
8425 |
proposal.setTypeName(field.type.qualifiedSourceName()); |
8426 |
proposal.setName(field.name); |
8427 |
proposal.setCompletion(completion); |
8428 |
proposal.setFlags(field.modifiers); |
8429 |
proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); |
8430 |
proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset); |
8431 |
proposal.setRelevance(relevance); |
8432 |
this.requestor.accept(proposal); |
8433 |
if(DEBUG) { |
8434 |
this.printDebug(proposal); |
8435 |
} |
8436 |
} |
8437 |
} else { |
8438 |
if (!this.isIgnored(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT)) { |
8439 |
CompilationUnitDeclaration cu = this.unitScope.referenceContext; |
8440 |
int importStart = cu.types[0].declarationSourceStart; |
8441 |
int importEnd = importStart; |
8442 |
|
8443 |
ReferenceBinding fieldType = (ReferenceBinding)field.type; |
8444 |
|
8445 |
CompletionProposal proposal = this.createProposal(CompletionProposal.FIELD_REF, this.actualCompletionPosition); |
8446 |
proposal.setDeclarationSignature(getSignature(field.declaringClass)); |
8447 |
proposal.setSignature(getSignature(field.type)); |
8448 |
proposal.setDeclarationPackageName(field.declaringClass.qualifiedPackageName()); |
8449 |
proposal.setDeclarationTypeName(field.declaringClass.qualifiedSourceName()); |
8450 |
proposal.setPackageName(field.type.qualifiedPackageName()); |
8451 |
proposal.setTypeName(field.type.qualifiedSourceName()); |
8452 |
proposal.setName(field.name); |
8453 |
proposal.setCompletion(completion); |
8454 |
proposal.setFlags(field.modifiers); |
8455 |
proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); |
8456 |
proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset); |
8457 |
proposal.setRelevance(relevance); |
8458 |
|
8459 |
char[] typeImportCompletion = createImportCharArray(CharOperation.concatWith(fieldType.compoundName, '.'), false, false); |
8460 |
|
8461 |
CompletionProposal typeImportProposal = this.createProposal(CompletionProposal.TYPE_IMPORT, this.actualCompletionPosition); |
8462 |
typeImportProposal.nameLookup = this.nameEnvironment.nameLookup; |
8463 |
typeImportProposal.completionEngine = this; |
8464 |
char[] packageName = fieldType.qualifiedPackageName(); |
8465 |
typeImportProposal.setDeclarationSignature(packageName); |
8466 |
typeImportProposal.setSignature(getSignature(fieldType)); |
8467 |
typeImportProposal.setPackageName(packageName); |
8468 |
typeImportProposal.setTypeName(fieldType.qualifiedSourceName()); |
8469 |
typeImportProposal.setCompletion(typeImportCompletion); |
8470 |
typeImportProposal.setFlags(fieldType.modifiers); |
8471 |
typeImportProposal.setAdditionalFlags(CompletionFlags.Default); |
8472 |
typeImportProposal.setReplaceRange(importStart - this.offset, importEnd - this.offset); |
8473 |
typeImportProposal.setTokenRange(importStart - this.offset, importEnd - this.offset); |
8474 |
typeImportProposal.setRelevance(relevance); |
8475 |
|
8476 |
proposal.setRequiredProposals(new CompletionProposal[]{typeImportProposal}); |
8477 |
|
8478 |
this.requestor.accept(proposal); |
8479 |
if(DEBUG) { |
8480 |
this.printDebug(proposal); |
8481 |
} |
8482 |
} |
8483 |
} |
8484 |
} |
8332 |
} |
8485 |
} |
8333 |
} |
8486 |
} |
8334 |
|
8487 |
|