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() {
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) {
protected int resolveLevel(TypeDeclaration type) { // find default constructor AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { for (int i = 0, length = methods.length; i < length; i++) { AbstractMethodDeclaration method = methods[i]; if (method.isDefaultConstructor() && method.sourceStart < type.bodyStart) // if synthetic return resolveLevel((ConstructorDeclaration) method, false); } } return IMPOSSIBLE_MATCH; } @Override
protected int resolveLevel(TypeDeclaration type) { // find default constructor AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { for (int i = 0, length = methods.length; i < length; i++) { AbstractMethodDeclaration method = methods[i]; if (method.isDefaultConstructor() && method.sourceStart < type.bodyStart) // if synthetic return resolveLevel((ConstructorDeclaration) method, false); } } return IMPOSSIBLE_MATCH; } public String toString() {
protected int resolveLevel(TypeDeclaration type) { // find default constructor AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { for (int i = 0, length = methods.length; i < length; i++) { AbstractMethodDeclaration method = methods[i]; if (method.isDefaultConstructor() && method.sourceStart < type.bodyStart) // if synthetic return resolveLevel((ConstructorDeclaration) method, false); } } return IMPOSSIBLE_MATCH; } public String toString() {
protected int resolveLevel(TypeDeclaration type) { // find default constructor AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { for (int i = 0, length = methods.length; i < length; i++) { AbstractMethodDeclaration method = methods[i]; if (method.isDefaultConstructor() && method.sourceStart < type.bodyStart) // if synthetic return resolveLevel((ConstructorDeclaration) method, false); } } return IMPOSSIBLE_MATCH; } public String toString() {
protected int resolveLevel(TypeDeclaration type) { // find default constructor AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { for (int i = 0, length = methods.length; i < length; i++) { AbstractMethodDeclaration method = methods[i]; if (method.isDefaultConstructor() && method.sourceStart < type.bodyStart) // if synthetic return resolveLevel((ConstructorDeclaration) method, false); } } return IMPOSSIBLE_MATCH; } public String toString() {
protected int resolveLevel(TypeDeclaration type) { // find default constructor AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { for (int i = 0, length = methods.length; i < length; i++) { AbstractMethodDeclaration method = methods[i]; if (method.isDefaultConstructor() && method.sourceStart < type.bodyStart) // if synthetic return resolveLevel((ConstructorDeclaration) method, false); } } return IMPOSSIBLE_MATCH; } public String toString() {
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(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(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(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(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(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(FieldDeclaration field) { // only accept enum constants if (field.type != null || field.binding == null) return IMPOSSIBLE_MATCH; if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, field.binding.type.sourceName())) return IMPOSSIBLE_MATCH; if (!(field.initialization instanceof AllocationExpression) || field.initialization.resolvedType.isLocalType()) return IMPOSSIBLE_MATCH; return resolveLevel(((AllocationExpression)field.initialization).binding); } public int resolveLevel(Binding binding) {
protected int resolveLevel(FieldDeclaration field) { // only accept enum constants if (field.type != null || field.binding == null) return IMPOSSIBLE_MATCH; if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, field.binding.type.sourceName())) return IMPOSSIBLE_MATCH; if (!(field.initialization instanceof AllocationExpression) || field.initialization.resolvedType.isLocalType()) return IMPOSSIBLE_MATCH; return resolveLevel(((AllocationExpression)field.initialization).binding); } public int resolveLevel(Binding binding) {
protected int resolveLevel(FieldDeclaration field) { // only accept enum constants if (field.type != null || field.binding == null) return IMPOSSIBLE_MATCH; if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, field.binding.type.sourceName())) return IMPOSSIBLE_MATCH; if (!(field.initialization instanceof AllocationExpression) || field.initialization.resolvedType.isLocalType()) return IMPOSSIBLE_MATCH; return resolveLevel(((AllocationExpression)field.initialization).binding); } public int resolveLevel(Binding binding) {
protected int resolveLevel(FieldDeclaration field) { // only accept enum constants if (field.type != null || field.binding == null) return IMPOSSIBLE_MATCH; if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, field.binding.type.sourceName())) return IMPOSSIBLE_MATCH; if (!(field.initialization instanceof AllocationExpression) || field.initialization.resolvedType.isLocalType()) return IMPOSSIBLE_MATCH; return resolveLevel(((AllocationExpression)field.initialization).binding); } public int resolveLevel(Binding binding) {
protected int resolveLevel(FieldDeclaration field) { // only accept enum constants if (field.type != null || field.binding == null) return IMPOSSIBLE_MATCH; if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, field.binding.type.sourceName())) return IMPOSSIBLE_MATCH; if (!(field.initialization instanceof AllocationExpression) || field.initialization.resolvedType.isLocalType()) return IMPOSSIBLE_MATCH; return resolveLevel(((AllocationExpression)field.initialization).binding); } @Override
protected int resolveLevel(FieldDeclaration field) { // only accept enum constants if (field.type != null || field.binding == null) return IMPOSSIBLE_MATCH; if (this.pattern.declaringSimpleName != null && !matchesName(this.pattern.declaringSimpleName, field.binding.type.sourceName())) return IMPOSSIBLE_MATCH; if (!(field.initialization instanceof AllocationExpression) || field.initialization.resolvedType.isLocalType()) return IMPOSSIBLE_MATCH; return resolveLevel(((AllocationExpression)field.initialization).binding); } public int resolveLevel(Binding binding) {