<s> package org . eclipse . jdt . internal . core . search . matching ; import org . eclipse . core . runtime . CoreException ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . internal . compiler . ast . * ; import org . eclipse . jdt . internal . compiler . lookup . * ; import org . eclipse . jdt . internal . core . search . indexing . IIndexConstants ; public class SuperTypeReferenceLocator extends PatternLocator { protected SuperTypeReferencePattern pattern ; public SuperTypeReferenceLocator ( SuperTypeReferencePattern pattern ) { super ( pattern ) ; this . pattern = pattern ; } public int match ( TypeReference node , MatchingNodeSet nodeSet ) { if ( this . pattern . superSimpleName == null ) return nodeSet . addMatch ( node , this . pattern . mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH ) ; char [ ] typeRefSimpleName = null ; if ( node instanceof SingleTypeReference ) { typeRefSimpleName = ( ( SingleTypeReference ) node ) . token ; } else { char [ ] [ ] tokens = ( ( QualifiedTypeReference ) node ) . tokens ; typeRefSimpleName = tokens [ tokens . length - 1 ] ; } if ( matchesName ( this . pattern . superSimpleName , typeRefSimpleName ) ) return nodeSet . addMatch ( node , this . pattern . mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH ) ; return IMPOSSIBLE_MATCH ; } protected int matchContainer ( ) { return CLASS_CONTAINER ; } protected void matchReportReference ( ASTNode reference , IJavaElement element , Binding elementBinding , int accuracy , MatchLocator locator ) throws CoreException { if ( elementBinding instanceof ReferenceBinding ) { ReferenceBinding referenceBinding = ( ReferenceBinding ) elementBinding ; if ( referenceBinding . isClass ( ) && this . pattern . typeSuffix == IIndexConstants . INTERFACE_SUFFIX ) { return ; } if ( referenceBinding . isInterface ( ) && this . pattern . typeSuffix == IIndexConstants . CLASS_SUFFIX ) { return ; } } super . matchReportReference ( reference , element , elementBinding , accuracy , locator ) ; } protected int referenceType ( ) { return IJavaElement . TYPE ; } public int resolveLevel ( ASTNode node ) { if ( ! ( node instanceof TypeReference ) ) return IMPOSSIBLE_MATCH ; TypeReference typeRef = ( TypeReference ) node ; TypeBinding typeBinding = typeRef . resolvedType ; if ( typeBinding instanceof ArrayBinding ) typeBinding = ( ( ArrayBinding ) typeBinding ) . leafComponentType ; if ( typeBinding instanceof ProblemReferenceBinding ) typeBinding = ( ( ProblemReferenceBinding ) typeBinding ) . closestMatch ( ) ; if ( typeBinding == null || ! typeBinding . isValidBinding ( ) ) return INACCURATE_MATCH ; return resolveLevelForType ( this . pattern . superSimpleName , this . pattern . superQualification , typeBinding ) ; } public int resolveLevel ( Binding binding ) { if ( binding == null ) return INACCURATE_MATCH ; if ( ! ( binding instanceof ReferenceBinding ) ) return IMPOSSIBLE_MATCH ; ReferenceBinding type = ( ReferenceBinding ) binding ; int level = IMPOSSIBLE_MATCH ; if ( this . pattern . superRefKind != SuperTypeReferencePattern . ONLY_SUPER_INTERFACES ) { level = resolveLevelForType ( this . pattern . superSimpleName , this . pattern . superQualification , type . superclass ( ) ) ; if ( level == ACCURATE_MATCH ) return ACCURATE_MATCH ; } if ( this . pattern . superRefKind != SuperTypeReferencePattern . ONLY_SUPER_CLASSES ) { ReferenceBinding [ ] superInterfaces = type . superInterfaces ( ) ; for ( int i = 0 , max = superInterfaces . length ; i < max ; i ++ ) { int newLevel = resolveLevelForType ( this . pattern . superSimpleName , this . pattern . superQualification , superInterfaces [ i ] ) ; if ( newLevel > level ) { if ( newLevel == ACCURATE_MATCH ) return ACCURATE_MATCH ; level = newLevel ; } } } return level ; } public String toString ( ) { return "Locator for " + this . pattern . toString ( ) ; } } </s>