<s> package org . eclipse . jdt . internal . core . search . matching ; import org . eclipse . jdt . core . BindingKey ; import org . eclipse . jdt . core . IJavaElement ; import org . eclipse . jdt . core . IMethod ; import org . eclipse . jdt . core . IType ; import org . eclipse . jdt . core . ITypeParameter ; import org . eclipse . jdt . core . JavaModelException ; import org . eclipse . jdt . core . Signature ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . core . search . IJavaSearchConstants ; import org . eclipse . jdt . core . search . SearchPattern ; import org . eclipse . jdt . internal . core . search . indexing . IIndexConstants ; import org . eclipse . jdt . internal . core . util . Util ; public class JavaSearchPattern extends SearchPattern implements IIndexConstants { boolean isCaseSensitive ; boolean isCamelCase ; int matchMode ; int matchCompatibility ; public int fineGrain = 0 ; public static final int MATCH_MODE_MASK = R_EXACT_MATCH | R_PREFIX_MATCH | R_PATTERN_MATCH | R_REGEXP_MATCH | R_CAMELCASE_MATCH | R_CAMELCASE_SAME_PART_COUNT_MATCH ; public static final int MATCH_COMPATIBILITY_MASK = R_ERASURE_MATCH | R_EQUIVALENT_MATCH | R_FULL_MATCH ; char [ ] [ ] typeSignatures ; private char [ ] [ ] [ ] typeArguments ; private int flags = 0 ; static final int HAS_TYPE_ARGUMENTS = 1 ; protected JavaSearchPattern ( int patternKind , int matchRule ) { super ( matchRule ) ; this . kind = patternKind ; int rule = getMatchRule ( ) ; this . isCaseSensitive = ( rule & R_CASE_SENSITIVE ) != 0 ; this . isCamelCase = ( rule & ( R_CAMELCASE_MATCH | R_CAMELCASE_SAME_PART_COUNT_MATCH ) ) != 0 ; this . matchCompatibility = rule & MATCH_COMPATIBILITY_MASK ; this . matchMode = rule & MATCH_MODE_MASK ; } public static String getFineGrainFlagString ( final int fineGrain ) { if ( fineGrain == 0 ) { return "none" ; } StringBuffer buffer = new StringBuffer ( ) ; for ( int i = 1 ; i <= 32 ; i ++ ) { int bit = fineGrain & ( 1 << ( i - 1 ) ) ; if ( bit != 0 && buffer . length ( ) > 0 ) buffer . append ( " | " ) ; switch ( bit ) { case IJavaSearchConstants . FIELD_DECLARATION_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . LOCAL_VARIABLE_DECLARATION_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . PARAMETER_DECLARATION_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . SUPERTYPE_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . THROWS_CLAUSE_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . CAST_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . CATCH_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . CLASS_INSTANCE_CREATION_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . RETURN_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . IMPORT_DECLARATION_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . ANNOTATION_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . TYPE_ARGUMENT_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . TYPE_VARIABLE_BOUND_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . WILDCARD_BOUND_TYPE_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . SUPER_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . QUALIFIED_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . THIS_REFERENCE : buffer . append ( "" ) ; break ; case IJavaSearchConstants . IMPLICIT_THIS_REFERENCE : buffer . append ( "" ) ; break ; } } return buffer . toString ( ) ; } public SearchPattern getBlankPattern ( ) { return null ; } final int getMatchMode ( ) { return this . matchMode ; } final boolean isCamelCase ( ) { return this . isCamelCase ; } final boolean isCaseSensitive ( ) { return this . isCaseSensitive ; } final boolean isErasureMatch ( ) { return ( this . matchCompatibility & R_ERASURE_MATCH ) != 0 ; } final boolean isEquivalentMatch ( ) { return ( this . matchCompatibility & R_EQUIVALENT_MATCH ) != 0 ; } char [ ] [ ] extractMethodArguments ( IMethod method ) { if ( method . isResolved ( ) ) { BindingKey bindingKey = new BindingKey ( method . getKey ( ) ) ; if ( bindingKey . isParameterizedMethod ( ) ) { String [ ] argumentsSignatures = bindingKey . getTypeArguments ( ) ; int length = argumentsSignatures . length ; if ( length > 0 ) { char [ ] [ ] methodArguments = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) { methodArguments [ i ] = argumentsSignatures [ i ] . toCharArray ( ) ; CharOperation . replace ( methodArguments [ i ] , new char [ ] { '$' , '/' } , '.' ) ; } return methodArguments ; } } return null ; } try { ITypeParameter [ ] parameters = method . getTypeParameters ( ) ; if ( parameters != null ) { int length = parameters . length ; if ( length > 0 ) { char [ ] [ ] arguments = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) { arguments [ i ] = Signature . createTypeSignature ( parameters [ i ] . getElementName ( ) , false ) . toCharArray ( ) ; } return arguments ; } } } catch ( JavaModelException jme ) { } return null ; } final char [ ] [ ] [ ] getTypeArguments ( ) { return this . typeArguments ; } public final boolean hasSignatures ( ) { return this . typeSignatures != null && this . typeSignatures . length > 0 ; } public final boolean hasTypeArguments ( ) { return ( this . flags & HAS_TYPE_ARGUMENTS ) != 0 ; } public final boolean hasTypeParameters ( ) { return ! hasSignatures ( ) && hasTypeArguments ( ) ; } boolean matchDifferentTypeSuffixes ( int typeSuffix , int patternSuffix ) { switch ( typeSuffix ) { case CLASS_SUFFIX : switch ( patternSuffix ) { case CLASS_AND_INTERFACE_SUFFIX : case CLASS_AND_ENUM_SUFFIX : return true ; } return false ; case INTERFACE_SUFFIX : switch ( patternSuffix ) { case CLASS_AND_INTERFACE_SUFFIX : case INTERFACE_AND_ANNOTATION_SUFFIX : return true ; } return false ; case ENUM_SUFFIX : return patternSuffix == CLASS_AND_ENUM_SUFFIX ; case ANNOTATION_TYPE_SUFFIX : return patternSuffix == INTERFACE_AND_ANNOTATION_SUFFIX ; case CLASS_AND_INTERFACE_SUFFIX : switch ( patternSuffix ) { case CLASS_SUFFIX : case INTERFACE_SUFFIX : return true ; } return false ; case CLASS_AND_ENUM_SUFFIX : switch ( patternSuffix ) { case CLASS_SUFFIX : case ENUM_SUFFIX : return true ; } return false ; case INTERFACE_AND_ANNOTATION_SUFFIX : switch ( patternSuffix ) { case INTERFACE_SUFFIX : case ANNOTATION_TYPE_SUFFIX : return true ; } return false ; } return true ; } protected StringBuffer print ( StringBuffer output ) { output . append ( ", " ) ; if ( hasTypeArguments ( ) && hasSignatures ( ) ) { output . append ( "signature:\"" ) ; output . append ( this . typeSignatures [ 0 ] ) ; output . append ( "\", " ) ; } switch ( getMatchMode ( ) ) { case R_EXACT_MATCH : output . append ( "" ) ; break ; case R_PREFIX_MATCH : output . append ( "" ) ; break ; case R_PATTERN_MATCH : output . append ( "" ) ; break ; case R_REGEXP_MATCH : output . append ( "" ) ; break ; case R_CAMELCASE_MATCH : output . append ( "" ) ; break ; case R_CAMELCASE_SAME_PART_COUNT_MATCH : output . append ( "" ) ; break ; } if ( isCaseSensitive ( ) ) output . append ( "" ) ; else output . append ( "" ) ; if ( ( this . matchCompatibility & R_FULL_MATCH ) != 0 ) { output . append ( "" ) ; } if ( ( this . matchCompatibility & R_ERASURE_MATCH ) != 0 ) { output . append ( "" ) ; } if ( ( this . matchCompatibility & R_EQUIVALENT_MATCH ) != 0 ) { output . append ( "" ) ; } output . append ( "fine grain: " ) ; output . append ( getFineGrainFlagString ( this . fineGrain ) ) ; return output ; } final void setTypeArguments ( char [ ] [ ] [ ] typeArguments ) { this . typeArguments = typeArguments ; if ( this . typeArguments != null ) { int length = this . typeArguments . length ; for ( int i = 0 ; i < length ; i ++ ) { if ( this . typeArguments [ i ] != null && this . typeArguments [ i ] . length > 0 ) { this . flags |= HAS_TYPE_ARGUMENTS ; break ; } } } } void storeTypeSignaturesAndArguments ( IType type ) { if ( type . isResolved ( ) ) { BindingKey bindingKey = new BindingKey ( type . getKey ( ) ) ; if ( bindingKey . isParameterizedType ( ) || bindingKey . isRawType ( ) ) { String signature = bindingKey . toSignature ( ) ; this . typeSignatures = Util . splitTypeLevelsSignature ( signature ) ; setTypeArguments ( Util . getAllTypeArguments ( this . typeSignatures ) ) ; } return ; } char [ ] [ ] [ ] typeParameters = new char [ 10 ] [ ] [ ] ; int ptr = - 1 ; boolean hasParameters = false ; try { IJavaElement parent = type ; ITypeParameter [ ] parameters = null ; while ( parent != null && parent . getElementType ( ) == IJavaElement . TYPE ) { if ( ++ ptr > typeParameters . length ) { System . arraycopy ( typeParameters , 0 , typeParameters = new char [ typeParameters . length + 10 ] [ ] [ ] , 0 , ptr ) ; } IType parentType = ( IType ) parent ; parameters = parentType . getTypeParameters ( ) ; if ( parameters != null ) { int length = parameters . length ; if ( length > 0 ) { hasParameters = true ; typeParameters [ ptr ] = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) typeParameters [ ptr ] [ i ] = Signature . createTypeSignature ( parameters [ i ] . getElementName ( ) , false ) . toCharArray ( ) ; } } parent = parent . getParent ( ) ; } } catch ( JavaModelException jme ) { return ; } if ( hasParameters ) { if ( ++ ptr < typeParameters . length ) System . arraycopy ( typeParameters , 0 , typeParameters = new char [ ptr ] [ ] [ ] , 0 , ptr ) ; setTypeArguments ( typeParameters ) ; } } public final String toString ( ) { return print ( new StringBuffer ( 30 ) ) . toString ( ) ; } } </s>