1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.jdt.core.IJavaElement; 15 import org.eclipse.jdt.internal.compiler.ast.*; 16 import org.eclipse.jdt.internal.compiler.lookup.*; 17 import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; 18 19 public class SuperTypeReferenceLocator extends PatternLocator { 20 21 protected SuperTypeReferencePattern pattern; 22 23 public SuperTypeReferenceLocator(SuperTypeReferencePattern pattern) { 24 super(pattern); 25 26 this.pattern = pattern; 27 } 28 public int match(TypeReference node, MatchingNodeSet nodeSet) { 37 if (this.pattern.superSimpleName == null) 38 return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); 39 40 char[] typeRefSimpleName = null; 41 if (node instanceof SingleTypeReference) { 42 typeRefSimpleName = ((SingleTypeReference) node).token; 43 } else { char[][] tokens = ((QualifiedTypeReference) node).tokens; 45 typeRefSimpleName = tokens[tokens.length-1]; 46 } 47 if (matchesName(this.pattern.superSimpleName, typeRefSimpleName)) 48 return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); 49 50 return IMPOSSIBLE_MATCH; 51 } 52 53 protected int matchContainer() { 54 return CLASS_CONTAINER; 55 } 56 59 protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { 60 if (elementBinding instanceof ReferenceBinding) { 61 ReferenceBinding referenceBinding = (ReferenceBinding) elementBinding; 62 if (referenceBinding.isClass() && this.pattern.typeSuffix == IIndexConstants.INTERFACE_SUFFIX) { 63 return; 65 } 66 if (referenceBinding.isInterface() && this.pattern.typeSuffix == IIndexConstants.CLASS_SUFFIX) { 67 return; 69 } 70 } 71 super.matchReportReference(reference, element, elementBinding, accuracy, locator); 72 } 73 protected int referenceType() { 74 return IJavaElement.TYPE; 75 } 76 public int resolveLevel(ASTNode node) { 77 if (!(node instanceof TypeReference)) return IMPOSSIBLE_MATCH; 78 79 TypeReference typeRef = (TypeReference) node; 80 TypeBinding binding = typeRef.resolvedType; 81 if (binding == null) return INACCURATE_MATCH; 82 return resolveLevelForType(this.pattern.superSimpleName, this.pattern.superQualification, binding); 83 } 84 public int resolveLevel(Binding binding) { 85 if (binding == null) return INACCURATE_MATCH; 86 if (!(binding instanceof ReferenceBinding)) return IMPOSSIBLE_MATCH; 87 88 ReferenceBinding type = (ReferenceBinding) binding; 89 int level = IMPOSSIBLE_MATCH; 90 if (this.pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_INTERFACES) { 91 level = resolveLevelForType(this.pattern.superSimpleName, this.pattern.superQualification, type.superclass()); 92 if (level == ACCURATE_MATCH) return ACCURATE_MATCH; 93 } 94 95 if (this.pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_CLASSES) { 96 ReferenceBinding[] superInterfaces = type.superInterfaces(); 97 for (int i = 0, max = superInterfaces.length; i < max; i++) { 98 int newLevel = resolveLevelForType(this.pattern.superSimpleName, this.pattern.superQualification, superInterfaces[i]); 99 if (newLevel > level) { 100 if (newLevel == ACCURATE_MATCH) return ACCURATE_MATCH; 101 level = newLevel; 102 } 103 } 104 } 105 return level; 106 } 107 public String toString() { 108 return "Locator for " + this.pattern.toString(); } 110 } 111 | Popular Tags |