<s> package org . eclipse . jdt . internal . core . search . matching ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . compiler . ast . ASTNode ; import org . eclipse . jdt . internal . compiler . ast . TypeDeclaration ; import org . eclipse . jdt . internal . compiler . lookup . * ; public class TypeDeclarationLocator extends PatternLocator { protected TypeDeclarationPattern pattern ; public TypeDeclarationLocator ( TypeDeclarationPattern pattern ) { super ( pattern ) ; this . pattern = pattern ; } public int match ( TypeDeclaration node , MatchingNodeSet nodeSet ) { if ( this . pattern . simpleName == null || matchesName ( this . pattern . simpleName , node . name ) ) return nodeSet . addMatch ( node , this . pattern . mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH ) ; return IMPOSSIBLE_MATCH ; } public int resolveLevel ( ASTNode node ) { if ( ! ( node instanceof TypeDeclaration ) ) return IMPOSSIBLE_MATCH ; return resolveLevel ( ( ( TypeDeclaration ) node ) . binding ) ; } public int resolveLevel ( Binding binding ) { if ( binding == null ) return INACCURATE_MATCH ; if ( ! ( binding instanceof TypeBinding ) ) return IMPOSSIBLE_MATCH ; TypeBinding type = ( TypeBinding ) binding ; switch ( this . pattern . typeSuffix ) { case CLASS_SUFFIX : if ( ! type . isClass ( ) ) return IMPOSSIBLE_MATCH ; break ; case CLASS_AND_INTERFACE_SUFFIX : if ( ! ( type . isClass ( ) || ( type . isInterface ( ) && ! type . isAnnotationType ( ) ) ) ) return IMPOSSIBLE_MATCH ; break ; case CLASS_AND_ENUM_SUFFIX : if ( ! ( type . isClass ( ) || type . isEnum ( ) ) ) return IMPOSSIBLE_MATCH ; break ; case INTERFACE_SUFFIX : if ( ! type . isInterface ( ) || type . isAnnotationType ( ) ) return IMPOSSIBLE_MATCH ; break ; case INTERFACE_AND_ANNOTATION_SUFFIX : if ( ! ( type . isInterface ( ) || type . isAnnotationType ( ) ) ) return IMPOSSIBLE_MATCH ; break ; case ENUM_SUFFIX : if ( ! type . isEnum ( ) ) return IMPOSSIBLE_MATCH ; break ; case ANNOTATION_TYPE_SUFFIX : if ( ! type . isAnnotationType ( ) ) return IMPOSSIBLE_MATCH ; break ; case TYPE_SUFFIX : } if ( this . pattern instanceof QualifiedTypeDeclarationPattern ) { QualifiedTypeDeclarationPattern qualifiedPattern = ( QualifiedTypeDeclarationPattern ) this . pattern ; return resolveLevelForType ( qualifiedPattern . simpleName , qualifiedPattern . qualification , type ) ; } else { char [ ] enclosingTypeName = this . pattern . enclosingTypeNames == null ? null : CharOperation . concatWith ( this . pattern . enclosingTypeNames , '.' ) ; return resolveLevelForType ( this . pattern . simpleName , this . pattern . pkg , enclosingTypeName , type ) ; } } protected int resolveLevelForType ( char [ ] simpleNamePattern , char [ ] qualificationPattern , char [ ] enclosingNamePattern , TypeBinding type ) { if ( enclosingNamePattern == null ) return resolveLevelForType ( simpleNamePattern , qualificationPattern , type ) ; if ( qualificationPattern == null ) return resolveLevelForType ( simpleNamePattern , enclosingNamePattern , type ) ; if ( type instanceof ProblemReferenceBinding ) return IMPOSSIBLE_MATCH ; char [ ] fullQualificationPattern = CharOperation . concat ( qualificationPattern , enclosingNamePattern , '.' ) ; if ( CharOperation . equals ( this . pattern . pkg , CharOperation . concatWith ( type . getPackage ( ) . compoundName , '.' ) ) ) return resolveLevelForType ( simpleNamePattern , fullQualificationPattern , type ) ; return IMPOSSIBLE_MATCH ; } public String toString ( ) { return "Locator for " + this . pattern . toString ( ) ; } } </s>