diff options
Diffstat (limited to 'org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java')
-rw-r--r-- | org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java | 146 |
1 files changed, 73 insertions, 73 deletions
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 fb9b0fae9..acdc1b57b 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 @@ -6,11 +6,14 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: + * Timo Kinnunen - Contributions for bug 377373 - [subwords] known limitations with JDT 3.8 + * Bug 420953 - [subwords] Constructors that don't match prefix not found * IBM Corporation - initial API and implementation * Fraunhofer FIRST - extended API and implementation * Technical University Berlin - extended API and implementation * Stephan Herrmann - Contribution for * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Gábor Kövesdán - Contribution for Bug 350000 - [content assist] Include non-prefix matches in auto-complete suggestions *******************************************************************************/ package org.eclipse.jdt.internal.codeassist; @@ -4247,24 +4250,17 @@ public final class CompletionEngine return 0; } int computeRelevanceForCaseMatching(char[] token, char[] proposalName){ - if (this.options.camelCaseMatch) { - if(CharOperation.equals(token, proposalName, true /* do not ignore case */)) { - return R_CASE + R_EXACT_NAME; - } else if (CharOperation.prefixEquals(token, proposalName, true /* do not ignore case */)) { + if(CharOperation.equals(token, proposalName, true)) { + return R_EXACT_NAME + R_CASE; + } else if(CharOperation.equals(token, proposalName, false)) { + return R_EXACT_NAME; + } else if (CharOperation.prefixEquals(token, proposalName, false)) { + if (CharOperation.prefixEquals(token, proposalName, true)) return R_CASE; - } else if (CharOperation.camelCaseMatch(token, proposalName)){ + } else if (this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, proposalName)){ return R_CAMEL_CASE; - } else if(CharOperation.equals(token, proposalName, false /* ignore case */)) { - return R_EXACT_NAME; - } - } else if (CharOperation.prefixEquals(token, proposalName, true /* do not ignore case */)) { - if(CharOperation.equals(token, proposalName, true /* do not ignore case */)) { - return R_CASE + R_EXACT_NAME; - } else { - return R_CASE; - } - } else if(CharOperation.equals(token, proposalName, false /* ignore case */)) { - return R_EXACT_NAME; + } else if (this.options.substringMatch && CharOperation.substringMatch(token, proposalName)) { + return R_SUBSTRING; } return 0; } @@ -5056,8 +5052,7 @@ public final class CompletionEngine nextAttribute: for (int i = 0; i < methods.length; i++) { MethodBinding method = methods[i]; - if(!CharOperation.prefixEquals(token, method.selector, false) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, method.selector))) continue nextAttribute; + if(isFailedMatch(token, method.selector)) continue nextAttribute; int length = attributesFound == null ? 0 : attributesFound.length; for (int j = 0; j < length; j++) { @@ -5996,8 +5991,7 @@ public final class CompletionEngine 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; + if (isFailedMatch(enumConstantName, field.name)) continue next; char[] fieldName = field.name; @@ -6185,8 +6179,7 @@ public final class CompletionEngine if (typeName.length > exceptionType.sourceName.length) return; - if (!CharOperation.prefixEquals(typeName, exceptionType.sourceName, false/* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(typeName, exceptionType.sourceName))) + if (isFailedMatch(typeName, exceptionType.sourceName)) return; if (this.options.checkDeprecation && @@ -6518,16 +6511,18 @@ public final class CompletionEngine if (fieldBeingCompletedId >= 0 && field.id >= fieldBeingCompletedId) { // Don't propose field which is being declared currently // Don't propose fields declared after the current field declaration statement - // Though, if field is static, then it can be still be proposed - if (!field.isStatic()) { - continue next; - } else if (isFieldBeingCompletedStatic) { - // static fields can't be proposed before they are actually declared if the - // field currently being declared is also static - continue next; + // Though, if field is static or completion happens in Javadoc, then it can be still be proposed + if (this.assistNodeInJavadoc == 0) { + if (!field.isStatic()) { + continue next; + } else if (isFieldBeingCompletedStatic) { + // static fields can't be proposed before they are actually declared if the + // field currently being declared is also static + continue next; + } } } - + //{ObjectTeams: filter out generated fields if (!canBeCompleted(field.name)) continue next; //carp} @@ -6537,8 +6532,7 @@ public final class CompletionEngine if (fieldLength > field.name.length) continue next; - if (!CharOperation.prefixEquals(fieldName, field.name, false /* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(fieldName, field.name))) continue next; + if (isFailedMatch(fieldName, field.name)) continue next; if (this.options.checkDeprecation && field.isViewedAsDeprecated() && @@ -7915,8 +7909,7 @@ public final class CompletionEngine if (fieldLength > field.name.length) continue next; - if (!CharOperation.prefixEquals(fieldName, field.name, false /* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(fieldName, field.name))) continue next; + if (isFailedMatch(fieldName, field.name)) continue next; if (this.options.checkDeprecation && field.isViewedAsDeprecated() && @@ -8156,8 +8149,7 @@ public final class CompletionEngine if (typeLength > memberType.sourceName.length) continue next; - if (!CharOperation.prefixEquals(typeName, memberType.sourceName, false/* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(typeName, memberType.sourceName))) + if (isFailedMatch(typeName, memberType.sourceName)) continue next; if (this.options.checkDeprecation && memberType.isViewedAsDeprecated()) continue next; @@ -8213,8 +8205,7 @@ public final class CompletionEngine if (!field.isStatic()) continue next; - if (!CharOperation.prefixEquals(fieldName, field.name, false/* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(fieldName, field.name))) + if (isFailedMatch(fieldName, field.name)) continue next; if (this.options.checkDeprecation && field.isViewedAsDeprecated()) continue next; @@ -8278,8 +8269,7 @@ public final class CompletionEngine if (methodLength > method.selector.length) continue next; - if (!CharOperation.prefixEquals(methodName, method.selector, false/* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(methodName, method.selector))) + if (isFailedMatch(methodName, method.selector)) continue next; int length = method.parameters.length; @@ -8815,8 +8805,7 @@ public final class CompletionEngine if (methodLength > method.selector.length) continue next; - if (!CharOperation.prefixEquals(methodName, method.selector, false/* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(methodName, method.selector))) + if (isFailedMatch(methodName, method.selector)) continue next; } //{ObjectTeams: different methods may produce different completion kinds @@ -9030,8 +9019,7 @@ public final class CompletionEngine } } else { if (methodLength > method.selector.length) continue next; - if (!CharOperation.prefixEquals(methodName, method.selector, false /* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(methodName, method.selector))) { + if (isFailedMatch(methodName, method.selector)) { continue next; } } @@ -9129,14 +9117,14 @@ public final class CompletionEngine //{ObjectTeams: offset /* orig: - for (int i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { :giro */ - for (int i = offset; i < length; i++) { + for (int i = offset; i < length; i++) { // SH} - TypeBinding type = method.original().parameters[i]; - parameterPackageNames[i] = type.qualifiedPackageName(); - parameterTypeNames[i] = type.qualifiedSourceName(); - } + TypeBinding type = method.original().parameters[i]; + parameterPackageNames[i] = type.qualifiedPackageName(); + parameterTypeNames[i] = type.qualifiedSourceName(); + } //{ObjectTeams: offset: /* orig: char[][] parameterNames = findMethodParameterNames(method,parameterTypeNames); @@ -9433,8 +9421,7 @@ public final class CompletionEngine if (methodLength > method.selector.length) continue next; - if (!CharOperation.prefixEquals(methodName, method.selector, false /* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(methodName, method.selector))) { + if (isFailedMatch(methodName, method.selector)) { continue next; } @@ -9736,11 +9723,11 @@ public final class CompletionEngine char[][] parameterPackageNames = new char[length][]; char[][] parameterTypeNames = new char[length][]; - for (int i = 0; i < length; i++) { - TypeBinding type = method.original().parameters[i]; - parameterPackageNames[i] = type.qualifiedPackageName(); - parameterTypeNames[i] = type.qualifiedSourceName(); - } + for (int i = 0; i < length; i++) { + TypeBinding type = method.original().parameters[i]; + parameterPackageNames[i] = type.qualifiedPackageName(); + parameterTypeNames[i] = type.qualifiedSourceName(); + } char[][] parameterNames = findMethodParameterNames(method,parameterTypeNames); char[] completion = CharOperation.NO_CHAR; @@ -10171,8 +10158,7 @@ public final class CompletionEngine if (typeLength > memberType.sourceName.length) continue next; - if (!CharOperation.prefixEquals(typeName, memberType.sourceName, false/* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(typeName, memberType.sourceName))) + if (isFailedMatch(typeName, memberType.sourceName)) continue next; //{ObjectTeams: don't surface __OT__ names: if (!canTypeBeCompleted(memberType.sourceName)) @@ -10687,6 +10673,7 @@ public final class CompletionEngine boolean hasPotentialDefaultAbstractMethods = true; boolean java8Plus = this.compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8; while (currentType != null) { + //{ObjectTeams: don't let availableMethods() look in the interface part! currentType = currentType.getRealClass(); // SH} @@ -10823,8 +10810,7 @@ public final class CompletionEngine if (typeLength > localType.sourceName.length) continue next; - if (!CharOperation.prefixEquals(typeName, localType.sourceName, false/* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(typeName, localType.sourceName))) + if (isFailedMatch(typeName, localType.sourceName)) continue next; for (int j = typesFound.size; --j >= 0;) { @@ -11209,8 +11195,7 @@ public final class CompletionEngine if (typeLength > typeParameter.name.length) continue; - if (!CharOperation.prefixEquals(token, typeParameter.name, false) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, typeParameter.name))) continue; + if (isFailedMatch(token, typeParameter.name)) continue; int relevance = computeBaseRelevance(); relevance += computeRelevanceForResolution(); @@ -11318,8 +11303,7 @@ public final class CompletionEngine if (typeLength > sourceType.sourceName.length) continue next; - if (!CharOperation.prefixEquals(token, sourceType.sourceName, false) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, sourceType.sourceName))) continue next; + if (isFailedMatch(token, sourceType.sourceName)) continue next; if (this.assistNodeIsAnnotation && !hasPossibleAnnotationTarget(sourceType, scope)) { continue next; @@ -11697,8 +11681,7 @@ public final class CompletionEngine if (typeLength > 0) { if (typeLength > refBinding.sourceName.length) continue next; - if (!CharOperation.prefixEquals(token, refBinding.sourceName, false) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, refBinding.sourceName))) continue next; + if (isFailedMatch(token, refBinding.sourceName)) continue next; } @@ -11864,8 +11847,7 @@ public final class CompletionEngine if (typeLength > typeBinding.sourceName.length) continue next; - if (!CharOperation.prefixEquals(token, typeBinding.sourceName, false) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, typeBinding.sourceName))) continue next; + if (isFailedMatch(token, typeBinding.sourceName)) continue next; int accessibility = IAccessRule.K_ACCESSIBLE; if(typeBinding.hasRestrictedAccess()) { @@ -11989,8 +11971,7 @@ public final class CompletionEngine if (typeLength > typeBinding.sourceName.length) continue; - if (!CharOperation.prefixEquals(token, typeBinding.sourceName, false) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, typeBinding.sourceName))) continue; + if (isFailedMatch(token, typeBinding.sourceName)) continue; if (typesFound.contains(typeBinding)) continue; @@ -12523,8 +12504,7 @@ public final class CompletionEngine if (tokenLength > local.name.length) continue next; - if (!CharOperation.prefixEquals(token, local.name, false /* ignore case */) - && !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, local.name))) + if (isFailedMatch(token, local.name)) continue next; //{ObjectTeams: filter out generated variables @@ -12942,6 +12922,26 @@ public final class CompletionEngine private boolean isAllowingLongComputationProposals() { return this.monitor != null; } + + /** + * Checks whether name matches the token according to the current + * code completion settings (substring match, camel case match etc.) + * and sets whether the current match is a suffix proposal. + * + * @param token the token that is tested + * @param name the name to match + * @return <code>true</code> if the token does not match, + * <code>false</code> otherwise + */ + private boolean isFailedMatch(char[] token, char[] name) { + if ((this.options.substringMatch && CharOperation.substringMatch(token, name)) + || (this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, name)) + || CharOperation.prefixEquals(token, name, false)) { + return false; + } + + return true; + } private boolean isForbidden(ReferenceBinding binding) { for (int i = 0; i <= this.forbbidenBindingsPtr; i++) { if(this.forbbidenBindings[i] == binding) { |