1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.internal.compiler.ast.ASTNode; 15 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; 16 import org.eclipse.jdt.internal.compiler.lookup.*; 17 18 public class TypeDeclarationLocator extends PatternLocator { 19 20 protected TypeDeclarationPattern pattern; 22 public TypeDeclarationLocator(TypeDeclarationPattern pattern) { 23 super(pattern); 24 25 this.pattern = pattern; 26 } 27 public int match(TypeDeclaration node, MatchingNodeSet nodeSet) { 35 if (this.pattern.simpleName == null || matchesName(this.pattern.simpleName, node.name)) 36 return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); 37 38 return IMPOSSIBLE_MATCH; 39 } 40 42 public int resolveLevel(ASTNode node) { 43 if (!(node instanceof TypeDeclaration)) return IMPOSSIBLE_MATCH; 44 45 return resolveLevel(((TypeDeclaration) node).binding); 46 } 47 public int resolveLevel(Binding binding) { 48 if (binding == null) return INACCURATE_MATCH; 49 if (!(binding instanceof TypeBinding)) return IMPOSSIBLE_MATCH; 50 51 TypeBinding type = (TypeBinding) binding; 52 53 switch (this.pattern.typeSuffix) { 54 case CLASS_SUFFIX: 55 if (!type.isClass()) return IMPOSSIBLE_MATCH; 56 break; 57 case CLASS_AND_INTERFACE_SUFFIX: 58 if (!(type.isClass() || (type.isInterface() && !type.isAnnotationType()))) return IMPOSSIBLE_MATCH; 59 break; 60 case CLASS_AND_ENUM_SUFFIX: 61 if (!(type.isClass() || type.isEnum())) return IMPOSSIBLE_MATCH; 62 break; 63 case INTERFACE_SUFFIX: 64 if (!type.isInterface() || type.isAnnotationType()) return IMPOSSIBLE_MATCH; 65 break; 66 case INTERFACE_AND_ANNOTATION_SUFFIX: 67 if (!(type.isInterface() || type.isAnnotationType())) return IMPOSSIBLE_MATCH; 68 break; 69 case ENUM_SUFFIX: 70 if (!type.isEnum()) return IMPOSSIBLE_MATCH; 71 break; 72 case ANNOTATION_TYPE_SUFFIX: 73 if (!type.isAnnotationType()) return IMPOSSIBLE_MATCH; 74 break; 75 case TYPE_SUFFIX : } 77 78 if (this.pattern instanceof QualifiedTypeDeclarationPattern) { 80 QualifiedTypeDeclarationPattern qualifiedPattern = (QualifiedTypeDeclarationPattern) this.pattern; 81 return resolveLevelForType(qualifiedPattern.simpleName, qualifiedPattern.qualification, type); 82 } else { 83 char[] enclosingTypeName = this.pattern.enclosingTypeNames == null ? null : CharOperation.concatWith(this.pattern.enclosingTypeNames, '.'); 84 return resolveLevelForType(this.pattern.simpleName, this.pattern.pkg, enclosingTypeName, type); 85 } 86 } 87 91 protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, char[] enclosingNamePattern, TypeBinding type) { 92 if (enclosingNamePattern == null) 93 return resolveLevelForType(simpleNamePattern, qualificationPattern, type); 94 if (qualificationPattern == null) 95 return resolveLevelForType(simpleNamePattern, enclosingNamePattern, type); 96 97 if (type instanceof ProblemReferenceBinding) return IMPOSSIBLE_MATCH; 99 100 char[] fullQualificationPattern = CharOperation.concat(qualificationPattern, enclosingNamePattern, '.'); 102 if (CharOperation.equals(this.pattern.pkg, CharOperation.concatWith(type.getPackage().compoundName, '.'))) 103 return resolveLevelForType(simpleNamePattern, fullQualificationPattern, type); 104 return IMPOSSIBLE_MATCH; 105 } 106 public String toString() { 107 return "Locator for " + this.pattern.toString(); } 109 } 110 | Popular Tags |