public int resolveLevel(Binding binding) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof MethodBinding)) return IMPOSSIBLE_MATCH; MethodBinding constructor = (MethodBinding) binding; int level= matchConstructor(constructor); if (level== IMPOSSIBLE_MATCH) { if (constructor != constructor.original()) { level= matchConstructor(constructor.original()); } } return level; } protected int resolveLevel(ConstructorDeclaration constructor, boolean checkDeclarations) {
@Override public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) { if (this.pattern.fineGrain != 0 && !this.pattern.findDeclarations) return IMPOSSIBLE_MATCH; int referencesLevel = this.pattern.findReferences ? matchLevelForReferences(node) : IMPOSSIBLE_MATCH; int declarationsLevel = this.pattern.findDeclarations ? matchLevelForDeclarations(node) : IMPOSSIBLE_MATCH; return nodeSet.addMatch(node, referencesLevel >= declarationsLevel ? referencesLevel : declarationsLevel); // use the stronger match } @Override
public int match(Expression node, MatchingNodeSet nodeSet) { // interested in AllocationExpression if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; if (!(node instanceof AllocationExpression)) return IMPOSSIBLE_MATCH; // constructor name is simple type name AllocationExpression allocation = (AllocationExpression) node; char[][] typeName = allocation.type.getTypeName(); if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, typeName[typeName.length-1])) return IMPOSSIBLE_MATCH; if (!matchParametersCount(node, allocation.arguments)) return IMPOSSIBLE_MATCH; return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } public int match(FieldDeclaration field, MatchingNodeSet nodeSet) {
protected int resolveLevel(AllocationExpression allocation) { // constructor name is simple type name char[][] typeName = allocation.type.getTypeName(); if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, typeName[typeName.length-1])) return IMPOSSIBLE_MATCH; return resolveLevel(allocation.binding); } protected int resolveLevel(FieldDeclaration field) {
public int resolveLevel(ASTNode node) { if (this.pattern.findReferences) { if (node instanceof AllocationExpression) return resolveLevel((AllocationExpression) node); if (node instanceof ExplicitConstructorCall) return resolveLevel(((ExplicitConstructorCall) node).binding); if (node instanceof TypeDeclaration) return resolveLevel((TypeDeclaration) node); if (node instanceof FieldDeclaration) return resolveLevel((FieldDeclaration) node); if (node instanceof JavadocMessageSend) { return resolveLevel(((JavadocMessageSend)node).binding); } } if (node instanceof ConstructorDeclaration) return resolveLevel((ConstructorDeclaration) node, true); return IMPOSSIBLE_MATCH; } protected int referenceType() {
@Override public int match(ASTNode node, MatchingNodeSet nodeSet) { // interested in ExplicitConstructorCall if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; if (!(node instanceof ExplicitConstructorCall)) return IMPOSSIBLE_MATCH; if (!matchParametersCount(node, ((ExplicitConstructorCall) node).arguments)) return IMPOSSIBLE_MATCH; return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } @Override
protected int matchLevelForDeclarations(ConstructorDeclaration constructor) { // constructor name is stored in selector field if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, constructor.selector)) return IMPOSSIBLE_MATCH; if (this.pattern.parameterSimpleNames != null) { int length = this.pattern.parameterSimpleNames.length; Argument[] args = constructor.arguments; int argsLength = args == null ? 0 : args.length; if (length != argsLength) return IMPOSSIBLE_MATCH; } // Verify type arguments (do not reject if pattern has no argument as it can be an erasure match) if (this.pattern.hasConstructorArguments()) { if (constructor.typeParameters == null || constructor.typeParameters.length != this.pattern.constructorArguments.length) return IMPOSSIBLE_MATCH; } return this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH; } boolean matchParametersCount(ASTNode node, Expression[] args) {
protected int matchConstructor(MethodBinding constructor) { if (!constructor.isConstructor()) return IMPOSSIBLE_MATCH; // declaring type, simple name has already been matched by matchIndexEntry() int level = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, constructor.declaringClass); if (level == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; // parameter types int parameterCount = this.pattern.parameterCount; if (parameterCount > -1) { if (constructor.parameters == null) return INACCURATE_MATCH; if (parameterCount != constructor.parameters.length) return IMPOSSIBLE_MATCH; for (int i = 0; i < parameterCount; i++) { // TODO (frederic) use this call to refine accuracy on parameter types // int newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, constructor.parameters[i]); int newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], constructor.parameters[i]); if (level > newLevel) { if (newLevel == IMPOSSIBLE_MATCH) { // if (isErasureMatch) { // return ERASURE_MATCH; // } return IMPOSSIBLE_MATCH; } level = newLevel; // can only be downgraded } } } return level; } protected int matchContainer() {
public static PatternLocator patternLocator(SearchPattern pattern) { switch (pattern.kind) { case IIndexConstants.PKG_REF_PATTERN : return new PackageReferenceLocator((PackageReferencePattern) pattern); case IIndexConstants.PKG_DECL_PATTERN : return new PackageDeclarationLocator((PackageDeclarationPattern) pattern); case IIndexConstants.TYPE_REF_PATTERN : return new TypeReferenceLocator((TypeReferencePattern) pattern); case IIndexConstants.TYPE_DECL_PATTERN : return new TypeDeclarationLocator((TypeDeclarationPattern) pattern); case IIndexConstants.SUPER_REF_PATTERN : return new SuperTypeReferenceLocator((SuperTypeReferencePattern) pattern); case IIndexConstants.CONSTRUCTOR_PATTERN : return new ConstructorLocator((ConstructorPattern) pattern); case IIndexConstants.FIELD_PATTERN : return new FieldLocator((FieldPattern) pattern); case IIndexConstants.METHOD_PATTERN : return new MethodLocator((MethodPattern) pattern); case IIndexConstants.OR_PATTERN : return new OrLocator((OrPattern) pattern); case IIndexConstants.AND_PATTERN : return new AndLocator((AndPattern) pattern); case IIndexConstants.LOCAL_VAR_PATTERN : return new LocalVariableLocator((LocalVariablePattern) pattern); case IIndexConstants.TYPE_PARAM_PATTERN: return new TypeParameterLocator((TypeParameterPattern) pattern); } return null; } public static char[] qualifiedPattern(char[] simpleNamePattern, char[] qualificationPattern) {
this.match.setRaw(parameterizedMethodBinding.isRaw); TypeBinding[] typeBindings = parameterizedMethodBinding.isRaw ? null : parameterizedMethodBinding.typeArguments; updateMatch(typeBindings, locator, this.pattern.constructorArguments, this.pattern.hasConstructorParameters()); updateMatch(parameterizedBinding, this.pattern.getTypeArguments(), this.pattern.hasTypeParameters(), 0, locator); } else { updateMatch(parameterizedBinding, this.pattern.getTypeArguments(), this.pattern.hasTypeParameters(), 0, locator); if (!this.pattern.hasTypeArguments() && this.pattern.hasConstructorArguments()) { updateMatch(parameterizedBinding, new char[][][] {this.pattern.constructorArguments}, this.pattern.hasTypeParameters(), 0, locator); } else if (!parameterizedBinding.isParameterizedWithOwnVariables()) { updateMatch(parameterizedBinding, this.pattern.getTypeArguments(), this.pattern.hasTypeParameters(), 0, locator);
protected int resolveLevel(AllocationExpression allocation) { // constructor name is simple type name char[][] typeName = allocation.type.getTypeName(); if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, typeName[typeName.length-1])) return IMPOSSIBLE_MATCH; return resolveLevel(allocation.binding); } protected int resolveLevel(FieldDeclaration field) {
protected int resolveLevel(ConstructorDeclaration constructor, boolean checkDeclarations) { int referencesLevel = IMPOSSIBLE_MATCH; if (this.pattern.findReferences) { ExplicitConstructorCall constructorCall = constructor.constructorCall; if (constructorCall != null && constructorCall.accessMode == ExplicitConstructorCall.ImplicitSuper) { // eliminate explicit super call as it will be treated with matchLevel(ExplicitConstructorCall, boolean) int callCount = (constructorCall.arguments == null) ? 0 : constructorCall.arguments.length; int patternCount = (this.pattern.parameterSimpleNames == null) ? 0 : this.pattern.parameterSimpleNames.length; if (patternCount != callCount) { referencesLevel = IMPOSSIBLE_MATCH; } else { referencesLevel = resolveLevel(constructorCall.binding); if (referencesLevel == ACCURATE_MATCH) return ACCURATE_MATCH; // cannot get better } } } if (!checkDeclarations) return referencesLevel; int declarationsLevel = this.pattern.findDeclarations ? resolveLevel(constructor.binding) : IMPOSSIBLE_MATCH; return referencesLevel >= declarationsLevel ? referencesLevel : declarationsLevel; // answer the stronger match } protected int resolveLevel(TypeDeclaration type) {
public int match(ASTNode node, MatchingNodeSet nodeSet) { // interested in ExplicitConstructorCall if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; if (!(node instanceof ExplicitConstructorCall)) return IMPOSSIBLE_MATCH; if (!matchParametersCount(node, ((ExplicitConstructorCall) node).arguments)) return IMPOSSIBLE_MATCH; return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) {
protected int matchLevelForDeclarations(ConstructorDeclaration constructor) { // constructor name is stored in selector field if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, constructor.selector)) return IMPOSSIBLE_MATCH; if (this.pattern.parameterSimpleNames != null) { int length = this.pattern.parameterSimpleNames.length; Argument[] args = constructor.arguments; int argsLength = args == null ? 0 : args.length; if (length != argsLength) return IMPOSSIBLE_MATCH; } // Verify type arguments (do not reject if pattern has no argument as it can be an erasure match) if (this.pattern.hasConstructorArguments()) { if (constructor.typeParameters == null || constructor.typeParameters.length != this.pattern.constructorArguments.length) return IMPOSSIBLE_MATCH; } return this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH; } boolean matchParametersCount(ASTNode node, Expression[] args) {
protected int matchConstructor(MethodBinding constructor) { if (!constructor.isConstructor()) return IMPOSSIBLE_MATCH; // declaring type, simple name has already been matched by matchIndexEntry() int level = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, constructor.declaringClass); if (level == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; // parameter types int parameterCount = this.pattern.parameterCount; if (parameterCount > -1) { if (constructor.parameters == null) return INACCURATE_MATCH; if (parameterCount != constructor.parameters.length) return IMPOSSIBLE_MATCH; for (int i = 0; i < parameterCount; i++) { // TODO (frederic) use this call to refine accuracy on parameter types // int newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, constructor.parameters[i]); int newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], constructor.parameters[i]); if (level > newLevel) { if (newLevel == IMPOSSIBLE_MATCH) { // if (isErasureMatch) { // return ERASURE_MATCH; // } return IMPOSSIBLE_MATCH; } level = newLevel; // can only be downgraded } } } return level; } protected int matchContainer() {
public static PatternLocator patternLocator(SearchPattern pattern) { switch (pattern.kind) { case IIndexConstants.PKG_REF_PATTERN : return new PackageReferenceLocator((PackageReferencePattern) pattern); case IIndexConstants.PKG_DECL_PATTERN : return new PackageDeclarationLocator((PackageDeclarationPattern) pattern); case IIndexConstants.TYPE_REF_PATTERN : return new TypeReferenceLocator((TypeReferencePattern) pattern); case IIndexConstants.TYPE_DECL_PATTERN : return new TypeDeclarationLocator((TypeDeclarationPattern) pattern); case IIndexConstants.SUPER_REF_PATTERN : return new SuperTypeReferenceLocator((SuperTypeReferencePattern) pattern); case IIndexConstants.CONSTRUCTOR_PATTERN : return new ConstructorLocator((ConstructorPattern) pattern); case IIndexConstants.FIELD_PATTERN : return new FieldLocator((FieldPattern) pattern); case IIndexConstants.METHOD_PATTERN : return new MethodLocator((MethodPattern) pattern); case IIndexConstants.OR_PATTERN : return new OrLocator((OrPattern) pattern); case IIndexConstants.AND_PATTERN : return new AndLocator((AndPattern) pattern); case IIndexConstants.LOCAL_VAR_PATTERN : return new LocalVariableLocator((LocalVariablePattern) pattern); case IIndexConstants.TYPE_PARAM_PATTERN: return new TypeParameterLocator((TypeParameterPattern) pattern); } return null; } public static char[] qualifiedPattern(char[] simpleNamePattern, char[] qualificationPattern) {
this.match.setRaw(parameterizedMethodBinding.isRaw); TypeBinding[] typeBindings = parameterizedMethodBinding.isRaw ? null : parameterizedMethodBinding.typeArguments; updateMatch(typeBindings, locator, this.pattern.constructorArguments, this.pattern.hasConstructorParameters()); updateMatch(parameterizedBinding, this.pattern.getTypeArguments(), this.pattern.hasTypeParameters(), 0, locator); } else { updateMatch(parameterizedBinding, this.pattern.getTypeArguments(), this.pattern.hasTypeParameters(), 0, locator); if (!this.pattern.hasTypeArguments() && this.pattern.hasConstructorArguments()) { updateMatch(parameterizedBinding, new char[][][] {this.pattern.constructorArguments}, this.pattern.hasTypeParameters(), 0, locator); } else if (!parameterizedBinding.isParameterizedWithOwnVariables()) { updateMatch(parameterizedBinding, this.pattern.getTypeArguments(), this.pattern.hasTypeParameters(), 0, locator);
public int match(Expression node, MatchingNodeSet nodeSet) { // interested in AllocationExpression if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; if (!(node instanceof AllocationExpression)) return IMPOSSIBLE_MATCH; // constructor name is simple type name AllocationExpression allocation = (AllocationExpression) node; char[][] typeName = allocation.type.getTypeName(); if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, typeName[typeName.length-1])) return IMPOSSIBLE_MATCH; if (!matchParametersCount(node, allocation.arguments)) return IMPOSSIBLE_MATCH; return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } public int match(FieldDeclaration field, MatchingNodeSet nodeSet) {
protected int resolveLevel(AllocationExpression allocation) { // constructor name is simple type name char[][] typeName = allocation.type.getTypeName(); if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, typeName[typeName.length-1])) return IMPOSSIBLE_MATCH; return resolveLevel(allocation.binding); } protected int resolveLevel(FieldDeclaration field) {
public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) { if (this.pattern.fineGrain != 0 && !this.pattern.findDeclarations) return IMPOSSIBLE_MATCH; int referencesLevel = this.pattern.findReferences ? matchLevelForReferences(node) : IMPOSSIBLE_MATCH; int declarationsLevel = this.pattern.findDeclarations ? matchLevelForDeclarations(node) : IMPOSSIBLE_MATCH; return nodeSet.addMatch(node, referencesLevel >= declarationsLevel ? referencesLevel : declarationsLevel); // use the stronger match } public int match(Expression node, MatchingNodeSet nodeSet) { // interested in AllocationExpression