<s> package org . eclipse . jdt . internal . core . search ; import java . util . * ; import org . eclipse . core . resources . * ; import org . eclipse . core . runtime . * ; import org . eclipse . jdt . core . * ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . core . search . * ; import org . eclipse . jdt . internal . compiler . * ; import org . eclipse . jdt . internal . compiler . ast . * ; import org . eclipse . jdt . internal . compiler . env . AccessRestriction ; import org . eclipse . jdt . internal . compiler . env . AccessRuleSet ; import org . eclipse . jdt . internal . compiler . impl . CompilerOptions ; import org . eclipse . jdt . internal . compiler . lookup . * ; import org . eclipse . jdt . internal . compiler . parser . Parser ; import org . eclipse . jdt . internal . compiler . problem . DefaultProblemFactory ; import org . eclipse . jdt . internal . compiler . problem . ProblemReporter ; import org . eclipse . jdt . internal . core . * ; import org . eclipse . jdt . internal . core . search . indexing . * ; import org . eclipse . jdt . internal . core . search . matching . * ; import org . eclipse . jdt . internal . core . util . Messages ; import org . eclipse . jdt . internal . core . util . Util ; public class BasicSearchEngine { private Parser parser ; private CompilerOptions compilerOptions ; private ICompilationUnit [ ] workingCopies ; private WorkingCopyOwner workingCopyOwner ; public static boolean VERBOSE = false ; public BasicSearchEngine ( ) { } public BasicSearchEngine ( ICompilationUnit [ ] workingCopies ) { this . workingCopies = workingCopies ; } char convertTypeKind ( int typeDeclarationKind ) { switch ( typeDeclarationKind ) { case TypeDeclaration . CLASS_DECL : return IIndexConstants . CLASS_SUFFIX ; case TypeDeclaration . INTERFACE_DECL : return IIndexConstants . INTERFACE_SUFFIX ; case TypeDeclaration . ENUM_DECL : return IIndexConstants . ENUM_SUFFIX ; case TypeDeclaration . ANNOTATION_TYPE_DECL : return IIndexConstants . ANNOTATION_TYPE_SUFFIX ; default : return IIndexConstants . TYPE_SUFFIX ; } } public BasicSearchEngine ( WorkingCopyOwner workingCopyOwner ) { this . workingCopyOwner = workingCopyOwner ; } public static IJavaSearchScope createHierarchyScope ( IType type ) throws JavaModelException { return createHierarchyScope ( type , DefaultWorkingCopyOwner . PRIMARY ) ; } public static IJavaSearchScope createHierarchyScope ( IType type , WorkingCopyOwner owner ) throws JavaModelException { return new HierarchyScope ( type , owner ) ; } public static IJavaSearchScope createStrictHierarchyScope ( IJavaProject project , IType type , boolean onlySubtypes , boolean includeFocusType , WorkingCopyOwner owner ) throws JavaModelException { return new HierarchyScope ( project , type , owner , onlySubtypes , true , includeFocusType ) ; } public static IJavaSearchScope createJavaSearchScope ( IJavaElement [ ] elements ) { return createJavaSearchScope ( elements , true ) ; } public static IJavaSearchScope createJavaSearchScope ( IJavaElement [ ] elements , boolean includeReferencedProjects ) { int includeMask = IJavaSearchScope . SOURCES | IJavaSearchScope . APPLICATION_LIBRARIES | IJavaSearchScope . SYSTEM_LIBRARIES ; if ( includeReferencedProjects ) { includeMask |= IJavaSearchScope . REFERENCED_PROJECTS ; } return createJavaSearchScope ( elements , includeMask ) ; } public static IJavaSearchScope createJavaSearchScope ( IJavaElement [ ] elements , int includeMask ) { HashSet projectsToBeAdded = new HashSet ( 2 ) ; for ( int i = 0 , length = elements . length ; i < length ; i ++ ) { IJavaElement element = elements [ i ] ; if ( element instanceof JavaProject ) { projectsToBeAdded . add ( element ) ; } } JavaSearchScope scope = new JavaSearchScope ( ) ; for ( int i = 0 , length = elements . length ; i < length ; i ++ ) { IJavaElement element = elements [ i ] ; if ( element != null ) { try { if ( projectsToBeAdded . contains ( element ) ) { scope . add ( ( JavaProject ) element , includeMask , projectsToBeAdded ) ; } else { scope . add ( element ) ; } } catch ( JavaModelException e ) { } } } return scope ; } public static TypeNameMatch createTypeNameMatch ( IType type , int modifiers ) { return new JavaSearchTypeNameMatch ( type , modifiers ) ; } public static IJavaSearchScope createWorkspaceScope ( ) { return JavaModelManager . getJavaModelManager ( ) . getWorkspaceScope ( ) ; } void findMatches ( SearchPattern pattern , SearchParticipant [ ] participants , IJavaSearchScope scope , SearchRequestor requestor , IProgressMonitor monitor ) throws CoreException { if ( monitor != null && monitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; try { if ( VERBOSE ) { Util . verbose ( "" + pattern . toString ( ) ) ; Util . verbose ( scope . toString ( ) ) ; } if ( participants == null ) { if ( VERBOSE ) Util . verbose ( "" ) ; return ; } int length = participants . length ; if ( monitor != null ) monitor . beginTask ( Messages . engine_searching , 100 * length ) ; IndexManager indexManager = JavaModelManager . getIndexManager ( ) ; requestor . beginReporting ( ) ; for ( int i = 0 ; i < length ; i ++ ) { if ( monitor != null && monitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; SearchParticipant participant = participants [ i ] ; try { if ( monitor != null ) monitor . subTask ( Messages . bind ( Messages . engine_searching_indexing , new String [ ] { participant . getDescription ( ) } ) ) ; participant . beginSearching ( ) ; requestor . enterParticipant ( participant ) ; PathCollector pathCollector = new PathCollector ( ) ; indexManager . performConcurrentJob ( new PatternSearchJob ( pattern , participant , scope , pathCollector ) , IJavaSearchConstants . WAIT_UNTIL_READY_TO_SEARCH , monitor == null ? null : new SubProgressMonitor ( monitor , 50 ) ) ; if ( monitor != null && monitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; if ( monitor != null ) monitor . subTask ( Messages . bind ( Messages . engine_searching_matching , new String [ ] { participant . getDescription ( ) } ) ) ; String [ ] indexMatchPaths = pathCollector . getPaths ( ) ; if ( indexMatchPaths != null ) { pathCollector = null ; int indexMatchLength = indexMatchPaths . length ; SearchDocument [ ] indexMatches = new SearchDocument [ indexMatchLength ] ; for ( int j = 0 ; j < indexMatchLength ; j ++ ) { indexMatches [ j ] = participant . getDocument ( indexMatchPaths [ j ] ) ; } SearchDocument [ ] matches = MatchLocator . addWorkingCopies ( pattern , indexMatches , getWorkingCopies ( ) , participant ) ; participant . locateMatches ( matches , pattern , scope , requestor , monitor == null ? null : new SubProgressMonitor ( monitor , 50 ) ) ; } } finally { requestor . exitParticipant ( participant ) ; participant . doneSearching ( ) ; } } } finally { requestor . endReporting ( ) ; if ( monitor != null ) monitor . done ( ) ; } } public static SearchParticipant getDefaultSearchParticipant ( ) { return new JavaSearchParticipant ( ) ; } public static String getMatchRuleString ( final int matchRule ) { if ( matchRule == 0 ) { return "" ; } StringBuffer buffer = new StringBuffer ( ) ; for ( int i = 1 ; i <= 16 ; i ++ ) { int bit = matchRule & ( 1 << ( i - 1 ) ) ; if ( bit != 0 && buffer . length ( ) > 0 ) buffer . append ( " | " ) ; switch ( bit ) { case SearchPattern . R_PREFIX_MATCH : buffer . append ( "" ) ; break ; case SearchPattern . R_CASE_SENSITIVE : buffer . append ( "" ) ; break ; case SearchPattern . R_EQUIVALENT_MATCH : buffer . append ( "" ) ; break ; case SearchPattern . R_ERASURE_MATCH : buffer . append ( "" ) ; break ; case SearchPattern . R_FULL_MATCH : buffer . append ( "R_FULL_MATCH" ) ; break ; case SearchPattern . R_PATTERN_MATCH : buffer . append ( "" ) ; break ; case SearchPattern . R_REGEXP_MATCH : buffer . append ( "" ) ; break ; case SearchPattern . R_CAMELCASE_MATCH : buffer . append ( "" ) ; break ; case SearchPattern . R_CAMELCASE_SAME_PART_COUNT_MATCH : buffer . append ( "" ) ; break ; } } return buffer . toString ( ) ; } public static String getSearchForString ( final int searchFor ) { switch ( searchFor ) { case IJavaSearchConstants . TYPE : return ( "TYPE" ) ; case IJavaSearchConstants . METHOD : return ( "METHOD" ) ; case IJavaSearchConstants . PACKAGE : return ( "PACKAGE" ) ; case IJavaSearchConstants . CONSTRUCTOR : return ( "CONSTRUCTOR" ) ; case IJavaSearchConstants . FIELD : return ( "FIELD" ) ; case IJavaSearchConstants . CLASS : return ( "CLASS" ) ; case IJavaSearchConstants . INTERFACE : return ( "INTERFACE" ) ; case IJavaSearchConstants . ENUM : return ( "ENUM" ) ; case IJavaSearchConstants . ANNOTATION_TYPE : return ( "" ) ; case IJavaSearchConstants . CLASS_AND_ENUM : return ( "" ) ; case IJavaSearchConstants . CLASS_AND_INTERFACE : return ( "" ) ; case IJavaSearchConstants . INTERFACE_AND_ANNOTATION : return ( "" ) ; } return "UNKNOWN" ; } private Parser getParser ( ) { if ( this . parser == null ) { this . compilerOptions = new CompilerOptions ( JavaCore . getOptions ( ) ) ; ProblemReporter problemReporter = new ProblemReporter ( DefaultErrorHandlingPolicies . proceedWithAllProblems ( ) , this . compilerOptions , new DefaultProblemFactory ( ) ) ; this . parser = new Parser ( problemReporter , true ) ; } return this . parser ; } private ICompilationUnit [ ] getWorkingCopies ( ) { ICompilationUnit [ ] copies ; if ( this . workingCopies != null ) { if ( this . workingCopyOwner == null ) { copies = JavaModelManager . getJavaModelManager ( ) . getWorkingCopies ( DefaultWorkingCopyOwner . PRIMARY , false ) ; if ( copies == null ) { copies = this . workingCopies ; } else { HashMap pathToCUs = new HashMap ( ) ; for ( int i = 0 , length = copies . length ; i < length ; i ++ ) { ICompilationUnit unit = copies [ i ] ; pathToCUs . put ( unit . getPath ( ) , unit ) ; } for ( int i = 0 , length = this . workingCopies . length ; i < length ; i ++ ) { ICompilationUnit unit = this . workingCopies [ i ] ; pathToCUs . put ( unit . getPath ( ) , unit ) ; } int length = pathToCUs . size ( ) ; copies = new ICompilationUnit [ length ] ; pathToCUs . values ( ) . toArray ( copies ) ; } } else { copies = this . workingCopies ; } } else if ( this . workingCopyOwner != null ) { copies = JavaModelManager . getJavaModelManager ( ) . getWorkingCopies ( this . workingCopyOwner , true ) ; } else { copies = JavaModelManager . getJavaModelManager ( ) . getWorkingCopies ( DefaultWorkingCopyOwner . PRIMARY , false ) ; } if ( copies == null ) return null ; ICompilationUnit [ ] result = null ; int length = copies . length ; int index = 0 ; for ( int i = 0 ; i < length ; i ++ ) { CompilationUnit copy = ( CompilationUnit ) copies [ i ] ; try { if ( ! copy . isPrimary ( ) || copy . hasUnsavedChanges ( ) || copy . hasResourceChanged ( ) ) { if ( result == null ) { result = new ICompilationUnit [ length ] ; } result [ index ++ ] = copy ; } } catch ( JavaModelException e ) { } } if ( index != length && result != null ) { System . arraycopy ( result , 0 , result = new ICompilationUnit [ index ] , 0 , index ) ; } return result ; } private ICompilationUnit [ ] getWorkingCopies ( IJavaElement element ) { if ( element instanceof IMember ) { ICompilationUnit cu = ( ( IMember ) element ) . getCompilationUnit ( ) ; if ( cu != null && cu . isWorkingCopy ( ) ) { return new ICompilationUnit [ ] { cu } ; } } else if ( element instanceof ICompilationUnit ) { return new ICompilationUnit [ ] { ( ICompilationUnit ) element } ; } return null ; } boolean match ( char patternTypeSuffix , int modifiers ) { switch ( patternTypeSuffix ) { case IIndexConstants . CLASS_SUFFIX : return ( modifiers & ( Flags . AccAnnotation | Flags . AccInterface | Flags . AccEnum ) ) == 0 ; case IIndexConstants . CLASS_AND_INTERFACE_SUFFIX : return ( modifiers & ( Flags . AccAnnotation | Flags . AccEnum ) ) == 0 ; case IIndexConstants . CLASS_AND_ENUM_SUFFIX : return ( modifiers & ( Flags . AccAnnotation | Flags . AccInterface ) ) == 0 ; case IIndexConstants . INTERFACE_SUFFIX : return ( modifiers & Flags . AccInterface ) != 0 ; case IIndexConstants . INTERFACE_AND_ANNOTATION_SUFFIX : return ( modifiers & ( Flags . AccInterface | Flags . AccAnnotation ) ) != 0 ; case IIndexConstants . ENUM_SUFFIX : return ( modifiers & Flags . AccEnum ) != 0 ; case IIndexConstants . ANNOTATION_TYPE_SUFFIX : return ( modifiers & Flags . AccAnnotation ) != 0 ; } return true ; } boolean match ( char patternTypeSuffix , char [ ] patternPkg , int matchRulePkg , char [ ] patternTypeName , int matchRuleType , int typeKind , char [ ] pkg , char [ ] typeName ) { switch ( patternTypeSuffix ) { case IIndexConstants . CLASS_SUFFIX : if ( typeKind != TypeDeclaration . CLASS_DECL ) return false ; break ; case IIndexConstants . CLASS_AND_INTERFACE_SUFFIX : if ( typeKind != TypeDeclaration . CLASS_DECL && typeKind != TypeDeclaration . INTERFACE_DECL ) return false ; break ; case IIndexConstants . CLASS_AND_ENUM_SUFFIX : if ( typeKind != TypeDeclaration . CLASS_DECL && typeKind != TypeDeclaration . ENUM_DECL ) return false ; break ; case IIndexConstants . INTERFACE_SUFFIX : if ( typeKind != TypeDeclaration . INTERFACE_DECL ) return false ; break ; case IIndexConstants . INTERFACE_AND_ANNOTATION_SUFFIX : if ( typeKind != TypeDeclaration . INTERFACE_DECL && typeKind != TypeDeclaration . ANNOTATION_TYPE_DECL ) return false ; break ; case IIndexConstants . ENUM_SUFFIX : if ( typeKind != TypeDeclaration . ENUM_DECL ) return false ; break ; case IIndexConstants . ANNOTATION_TYPE_SUFFIX : if ( typeKind != TypeDeclaration . ANNOTATION_TYPE_DECL ) return false ; break ; case IIndexConstants . TYPE_SUFFIX : } boolean isPkgCaseSensitive = ( matchRulePkg & SearchPattern . R_CASE_SENSITIVE ) != 0 ; if ( patternPkg != null && ! CharOperation . equals ( patternPkg , pkg , isPkgCaseSensitive ) ) return false ; boolean isCaseSensitive = ( matchRuleType & SearchPattern . R_CASE_SENSITIVE ) != 0 ; if ( patternTypeName != null ) { boolean isCamelCase = ( matchRuleType & ( SearchPattern . R_CAMELCASE_MATCH | SearchPattern . R_CAMELCASE_SAME_PART_COUNT_MATCH ) ) != 0 ; int matchMode = matchRuleType & JavaSearchPattern . MATCH_MODE_MASK ; if ( ! isCaseSensitive && ! isCamelCase ) { patternTypeName = CharOperation . toLowerCase ( patternTypeName ) ; } boolean matchFirstChar = ! isCaseSensitive || patternTypeName [ 0 ] == typeName [ 0 ] ; switch ( matchMode ) { case SearchPattern . R_EXACT_MATCH : return matchFirstChar && CharOperation . equals ( patternTypeName , typeName , isCaseSensitive ) ; case SearchPattern . R_PREFIX_MATCH : return matchFirstChar && CharOperation . prefixEquals ( patternTypeName , typeName , isCaseSensitive ) ; case SearchPattern . R_PATTERN_MATCH : return CharOperation . match ( patternTypeName , typeName , isCaseSensitive ) ; case SearchPattern . R_REGEXP_MATCH : break ; case SearchPattern . R_CAMELCASE_MATCH : if ( matchFirstChar && CharOperation . camelCaseMatch ( patternTypeName , typeName , false ) ) { return true ; } return ! isCaseSensitive && matchFirstChar && CharOperation . prefixEquals ( patternTypeName , typeName , false ) ; case SearchPattern . R_CAMELCASE_SAME_PART_COUNT_MATCH : return matchFirstChar && CharOperation . camelCaseMatch ( patternTypeName , typeName , true ) ; } } return true ; } public void search ( SearchPattern pattern , SearchParticipant [ ] participants , IJavaSearchScope scope , SearchRequestor requestor , IProgressMonitor monitor ) throws CoreException { if ( VERBOSE ) { Util . verbose ( "" ) ; } findMatches ( pattern , participants , scope , requestor , monitor ) ; } public void searchAllConstructorDeclarations ( final char [ ] packageName , final char [ ] typeName , final int typeMatchRule , IJavaSearchScope scope , final IRestrictedAccessConstructorRequestor nameRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { final int validatedTypeMatchRule = SearchPattern . validateMatchRule ( typeName == null ? null : new String ( typeName ) , typeMatchRule ) ; final int pkgMatchRule = SearchPattern . R_EXACT_MATCH | SearchPattern . R_CASE_SENSITIVE ; final char NoSuffix = IIndexConstants . TYPE_SUFFIX ; if ( VERBOSE ) { Util . verbose ( "" ) ; Util . verbose ( "" + ( packageName == null ? "null" : new String ( packageName ) ) ) ; Util . verbose ( "" + ( typeName == null ? "null" : new String ( typeName ) ) ) ; Util . verbose ( "" + getMatchRuleString ( typeMatchRule ) ) ; if ( validatedTypeMatchRule != typeMatchRule ) { Util . verbose ( "" + getMatchRuleString ( validatedTypeMatchRule ) ) ; } Util . verbose ( "t- scope: " + scope ) ; } if ( validatedTypeMatchRule == - 1 ) return ; IndexManager indexManager = JavaModelManager . getIndexManager ( ) ; final ConstructorDeclarationPattern pattern = new ConstructorDeclarationPattern ( packageName , typeName , validatedTypeMatchRule ) ; final HashSet workingCopyPaths = new HashSet ( ) ; String workingCopyPath = null ; ICompilationUnit [ ] copies = getWorkingCopies ( ) ; final int copiesLength = copies == null ? 0 : copies . length ; if ( copies != null ) { if ( copiesLength == 1 ) { workingCopyPath = copies [ 0 ] . getPath ( ) . toString ( ) ; } else { for ( int i = 0 ; i < copiesLength ; i ++ ) { ICompilationUnit workingCopy = copies [ i ] ; workingCopyPaths . add ( workingCopy . getPath ( ) . toString ( ) ) ; } } } final String singleWkcpPath = workingCopyPath ; IndexQueryRequestor searchRequestor = new IndexQueryRequestor ( ) { public boolean acceptIndexMatch ( String documentPath , SearchPattern indexRecord , SearchParticipant participant , AccessRuleSet access ) { ConstructorDeclarationPattern record = ( ConstructorDeclarationPattern ) indexRecord ; if ( ( record . extraFlags & ExtraFlags . IsMemberType ) != 0 ) { return true ; } if ( ( record . extraFlags & ExtraFlags . IsLocalType ) != 0 ) { return true ; } switch ( copiesLength ) { case 0 : break ; case 1 : if ( singleWkcpPath . equals ( documentPath ) ) { return true ; } break ; default : if ( workingCopyPaths . contains ( documentPath ) ) { return true ; } break ; } AccessRestriction accessRestriction = null ; if ( access != null ) { int pkgLength = ( record . declaringPackageName == null || record . declaringPackageName . length == 0 ) ? 0 : record . declaringPackageName . length + 1 ; int nameLength = record . declaringSimpleName == null ? 0 : record . declaringSimpleName . length ; char [ ] path = new char [ pkgLength + nameLength ] ; int pos = 0 ; if ( pkgLength > 0 ) { System . arraycopy ( record . declaringPackageName , 0 , path , pos , pkgLength - 1 ) ; CharOperation . replace ( path , '.' , '/' ) ; path [ pkgLength - 1 ] = '/' ; pos += pkgLength ; } if ( nameLength > 0 ) { System . arraycopy ( record . declaringSimpleName , 0 , path , pos , nameLength ) ; pos += nameLength ; } if ( pos > 0 ) { accessRestriction = access . getViolatedRestriction ( path ) ; } } nameRequestor . acceptConstructor ( record . modifiers , record . declaringSimpleName , record . parameterCount , record . signature , record . parameterTypes , record . parameterNames , record . declaringTypeModifiers , record . declaringPackageName , record . extraFlags , documentPath , accessRestriction ) ; return true ; } } ; try { if ( progressMonitor != null ) { progressMonitor . beginTask ( Messages . engine_searching , 1000 ) ; } indexManager . performConcurrentJob ( new PatternSearchJob ( pattern , getDefaultSearchParticipant ( ) , scope , searchRequestor ) , waitingPolicy , progressMonitor == null ? null : new SubProgressMonitor ( progressMonitor , 1000 - copiesLength ) ) ; if ( copies != null ) { for ( int i = 0 ; i < copiesLength ; i ++ ) { final ICompilationUnit workingCopy = copies [ i ] ; if ( scope instanceof HierarchyScope ) { if ( ! ( ( HierarchyScope ) scope ) . encloses ( workingCopy , progressMonitor ) ) continue ; } else { if ( ! scope . encloses ( workingCopy ) ) continue ; } final String path = workingCopy . getPath ( ) . toString ( ) ; if ( workingCopy . isConsistent ( ) ) { IPackageDeclaration [ ] packageDeclarations = workingCopy . getPackageDeclarations ( ) ; char [ ] packageDeclaration = packageDeclarations . length == 0 ? CharOperation . NO_CHAR : packageDeclarations [ 0 ] . getElementName ( ) . toCharArray ( ) ; IType [ ] allTypes = workingCopy . getAllTypes ( ) ; for ( int j = 0 , allTypesLength = allTypes . length ; j < allTypesLength ; j ++ ) { IType type = allTypes [ j ] ; char [ ] simpleName = type . getElementName ( ) . toCharArray ( ) ; if ( match ( NoSuffix , packageName , pkgMatchRule , typeName , validatedTypeMatchRule , 0 , packageDeclaration , simpleName ) && ! type . isMember ( ) ) { int extraFlags = ExtraFlags . getExtraFlags ( type ) ; boolean hasConstructor = false ; IMethod [ ] methods = type . getMethods ( ) ; for ( int k = 0 ; k < methods . length ; k ++ ) { IMethod method = methods [ k ] ; if ( method . isConstructor ( ) ) { hasConstructor = true ; String [ ] stringParameterNames = method . getParameterNames ( ) ; String [ ] stringParameterTypes = method . getParameterTypes ( ) ; int length = stringParameterNames . length ; char [ ] [ ] parameterNames = new char [ length ] [ ] ; char [ ] [ ] parameterTypes = new char [ length ] [ ] ; for ( int l = 0 ; l < length ; l ++ ) { parameterNames [ l ] = stringParameterNames [ l ] . toCharArray ( ) ; parameterTypes [ l ] = Signature . toCharArray ( Signature . getTypeErasure ( stringParameterTypes [ l ] ) . toCharArray ( ) ) ; } nameRequestor . acceptConstructor ( method . getFlags ( ) , simpleName , parameterNames . length , null , parameterTypes , parameterNames , type . getFlags ( ) , packageDeclaration , extraFlags , path , null ) ; } } if ( ! hasConstructor ) { nameRequestor . acceptConstructor ( Flags . AccPublic , simpleName , - 1 , null , CharOperation . NO_CHAR_CHAR , CharOperation . NO_CHAR_CHAR , type . getFlags ( ) , packageDeclaration , extraFlags , path , null ) ; } } } } else { Parser basicParser = getParser ( ) ; org . eclipse . jdt . internal . compiler . env . ICompilationUnit unit = ( org . eclipse . jdt . internal . compiler . env . ICompilationUnit ) workingCopy ; CompilationResult compilationUnitResult = new CompilationResult ( unit , 0 , 0 , this . compilerOptions . maxProblemsPerUnit ) ; CompilationUnitDeclaration parsedUnit = basicParser . dietParse ( unit , compilationUnitResult ) ; if ( parsedUnit != null ) { final char [ ] packageDeclaration = parsedUnit . currentPackage == null ? CharOperation . NO_CHAR : CharOperation . concatWith ( parsedUnit . currentPackage . getImportName ( ) , '.' ) ; class AllConstructorDeclarationsVisitor extends ASTVisitor { private TypeDeclaration [ ] declaringTypes = new TypeDeclaration [ 0 ] ; private int declaringTypesPtr = - 1 ; private void endVisit ( TypeDeclaration typeDeclaration ) { if ( ! hasConstructor ( typeDeclaration ) && typeDeclaration . enclosingType == null ) { if ( match ( NoSuffix , packageName , pkgMatchRule , typeName , validatedTypeMatchRule , 0 , packageDeclaration , typeDeclaration . name ) ) { nameRequestor . acceptConstructor ( Flags . AccPublic , typeName , - 1 , null , CharOperation . NO_CHAR_CHAR , CharOperation . NO_CHAR_CHAR , typeDeclaration . modifiers , packageDeclaration , ExtraFlags . getExtraFlags ( typeDeclaration ) , path , null ) ; } } this . declaringTypes [ this . declaringTypesPtr ] = null ; this . declaringTypesPtr -- ; } public void endVisit ( TypeDeclaration typeDeclaration , CompilationUnitScope s ) { endVisit ( typeDeclaration ) ; } public void endVisit ( TypeDeclaration memberTypeDeclaration , ClassScope s ) { endVisit ( memberTypeDeclaration ) ; } private boolean hasConstructor ( TypeDeclaration typeDeclaration ) { AbstractMethodDeclaration [ ] methods = typeDeclaration . methods ; int length = methods == null ? 0 : methods . length ; for ( int j = 0 ; j < length ; j ++ ) { if ( methods [ j ] . isConstructor ( ) ) { return true ; } } return false ; } public boolean visit ( ConstructorDeclaration constructorDeclaration , ClassScope classScope ) { TypeDeclaration typeDeclaration = this . declaringTypes [ this . declaringTypesPtr ] ; if ( match ( NoSuffix , packageName , pkgMatchRule , typeName , validatedTypeMatchRule , 0 , packageDeclaration , typeDeclaration . name ) ) { Argument [ ] arguments = constructorDeclaration . arguments ; int length = arguments == null ? 0 : arguments . length ; char [ ] [ ] parameterNames = new char [ length ] [ ] ; char [ ] [ ] parameterTypes = new char [ length ] [ ] ; for ( int l = 0 ; l < length ; l ++ ) { Argument argument = arguments [ l ] ; parameterNames [ l ] = argument . name ; if ( argument . type instanceof SingleTypeReference ) { parameterTypes [ l ] = ( ( SingleTypeReference ) argument . type ) . token ; } else { parameterTypes [ l ] = CharOperation . concatWith ( ( ( QualifiedTypeReference ) argument . type ) . tokens , '.' ) ; } } TypeDeclaration enclosing = typeDeclaration . enclosingType ; char [ ] [ ] enclosingTypeNames = CharOperation . NO_CHAR_CHAR ; while ( enclosing != null ) { enclosingTypeNames = CharOperation . arrayConcat ( new char [ ] [ ] { enclosing . name } , enclosingTypeNames ) ; if ( ( enclosing . bits & ASTNode . IsMemberType ) != 0 ) { enclosing = enclosing . enclosingType ; } else { enclosing = null ; } } nameRequestor . acceptConstructor ( constructorDeclaration . modifiers , typeName , parameterNames . length , null , parameterTypes , parameterNames , typeDeclaration . modifiers , packageDeclaration , ExtraFlags . getExtraFlags ( typeDeclaration ) , path , null ) ; } return false ; } public boolean visit ( TypeDeclaration typeDeclaration , BlockScope blockScope ) { return false ; } private boolean visit ( TypeDeclaration typeDeclaration ) { if ( this . declaringTypes . length <= ++ this . declaringTypesPtr ) { int length = this . declaringTypesPtr ; System . arraycopy ( this . declaringTypes , 0 , this . declaringTypes = new TypeDeclaration [ length * 2 + 1 ] , 0 , length ) ; } this . declaringTypes [ this . declaringTypesPtr ] = typeDeclaration ; return true ; } public boolean visit ( TypeDeclaration typeDeclaration , CompilationUnitScope s ) { return visit ( typeDeclaration ) ; } public boolean visit ( TypeDeclaration memberTypeDeclaration , ClassScope s ) { return visit ( memberTypeDeclaration ) ; } } parsedUnit . traverse ( new AllConstructorDeclarationsVisitor ( ) , parsedUnit . scope ) ; } } if ( progressMonitor != null ) { if ( progressMonitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; progressMonitor . worked ( 1 ) ; } } } } finally { if ( progressMonitor != null ) { progressMonitor . done ( ) ; } } } public void searchAllSecondaryTypeNames ( IPackageFragmentRoot [ ] sourceFolders , final IRestrictedAccessTypeRequestor nameRequestor , boolean waitForIndexes , IProgressMonitor progressMonitor ) throws JavaModelException { if ( VERBOSE ) { Util . verbose ( "" ) ; StringBuffer buffer = new StringBuffer ( "" ) ; int length = sourceFolders . length ; for ( int i = 0 ; i < length ; i ++ ) { if ( i == 0 ) { buffer . append ( '[' ) ; } else { buffer . append ( ',' ) ; } buffer . append ( sourceFolders [ i ] . getElementName ( ) ) ; } buffer . append ( "" ) ; buffer . append ( waitForIndexes ) ; Util . verbose ( buffer . toString ( ) ) ; } IndexManager indexManager = JavaModelManager . getIndexManager ( ) ; final TypeDeclarationPattern pattern = new SecondaryTypeDeclarationPattern ( ) ; final HashSet workingCopyPaths = new HashSet ( ) ; String workingCopyPath = null ; ICompilationUnit [ ] copies = getWorkingCopies ( ) ; final int copiesLength = copies == null ? 0 : copies . length ; if ( copies != null ) { if ( copiesLength == 1 ) { workingCopyPath = copies [ 0 ] . getPath ( ) . toString ( ) ; } else { for ( int i = 0 ; i < copiesLength ; i ++ ) { ICompilationUnit workingCopy = copies [ i ] ; workingCopyPaths . add ( workingCopy . getPath ( ) . toString ( ) ) ; } } } final String singleWkcpPath = workingCopyPath ; IndexQueryRequestor searchRequestor = new IndexQueryRequestor ( ) { public boolean acceptIndexMatch ( String documentPath , SearchPattern indexRecord , SearchParticipant participant , AccessRuleSet access ) { TypeDeclarationPattern record = ( TypeDeclarationPattern ) indexRecord ; if ( ! record . secondary ) { return true ; } if ( record . enclosingTypeNames == IIndexConstants . ONE_ZERO_CHAR ) { return true ; } switch ( copiesLength ) { case 0 : break ; case 1 : if ( singleWkcpPath . equals ( documentPath ) ) { return true ; } break ; default : if ( workingCopyPaths . contains ( documentPath ) ) { return true ; } break ; } AccessRestriction accessRestriction = null ; if ( access != null ) { int pkgLength = ( record . pkg == null || record . pkg . length == 0 ) ? 0 : record . pkg . length + 1 ; int nameLength = record . simpleName == null ? 0 : record . simpleName . length ; char [ ] path = new char [ pkgLength + nameLength ] ; int pos = 0 ; if ( pkgLength > 0 ) { System . arraycopy ( record . pkg , 0 , path , pos , pkgLength - 1 ) ; CharOperation . replace ( path , '.' , '/' ) ; path [ pkgLength - 1 ] = '/' ; pos += pkgLength ; } if ( nameLength > 0 ) { System . arraycopy ( record . simpleName , 0 , path , pos , nameLength ) ; pos += nameLength ; } if ( pos > 0 ) { accessRestriction = access . getViolatedRestriction ( path ) ; } } nameRequestor . acceptType ( record . modifiers , record . pkg , record . simpleName , record . enclosingTypeNames , documentPath , accessRestriction ) ; return true ; } } ; try { if ( progressMonitor != null ) { progressMonitor . beginTask ( Messages . engine_searching , 100 ) ; } indexManager . performConcurrentJob ( new PatternSearchJob ( pattern , getDefaultSearchParticipant ( ) , createJavaSearchScope ( sourceFolders ) , searchRequestor ) , waitForIndexes ? IJavaSearchConstants . WAIT_UNTIL_READY_TO_SEARCH : IJavaSearchConstants . FORCE_IMMEDIATE_SEARCH , progressMonitor == null ? null : new SubProgressMonitor ( progressMonitor , 100 ) ) ; } catch ( OperationCanceledException oce ) { } finally { if ( progressMonitor != null ) { progressMonitor . done ( ) ; } } } public void searchAllTypeNames ( final char [ ] packageName , final int packageMatchRule , final char [ ] typeName , final int typeMatchRule , int searchFor , IJavaSearchScope scope , final IRestrictedAccessTypeRequestor nameRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { final int validatedTypeMatchRule = SearchPattern . validateMatchRule ( typeName == null ? null : new String ( typeName ) , typeMatchRule ) ; if ( VERBOSE ) { Util . verbose ( "" ) ; Util . verbose ( "" + ( packageName == null ? "null" : new String ( packageName ) ) ) ; Util . verbose ( "" + getMatchRuleString ( packageMatchRule ) ) ; Util . verbose ( "" + ( typeName == null ? "null" : new String ( typeName ) ) ) ; Util . verbose ( "" + getMatchRuleString ( typeMatchRule ) ) ; if ( validatedTypeMatchRule != typeMatchRule ) { Util . verbose ( "" + getMatchRuleString ( validatedTypeMatchRule ) ) ; } Util . verbose ( "" + searchFor ) ; Util . verbose ( "t- scope: " + scope ) ; } if ( validatedTypeMatchRule == - 1 ) return ; IndexManager indexManager = JavaModelManager . getIndexManager ( ) ; final char typeSuffix ; switch ( searchFor ) { case IJavaSearchConstants . CLASS : typeSuffix = IIndexConstants . CLASS_SUFFIX ; break ; case IJavaSearchConstants . CLASS_AND_INTERFACE : typeSuffix = IIndexConstants . CLASS_AND_INTERFACE_SUFFIX ; break ; case IJavaSearchConstants . CLASS_AND_ENUM : typeSuffix = IIndexConstants . CLASS_AND_ENUM_SUFFIX ; break ; case IJavaSearchConstants . INTERFACE : typeSuffix = IIndexConstants . INTERFACE_SUFFIX ; break ; case IJavaSearchConstants . INTERFACE_AND_ANNOTATION : typeSuffix = IIndexConstants . INTERFACE_AND_ANNOTATION_SUFFIX ; break ; case IJavaSearchConstants . ENUM : typeSuffix = IIndexConstants . ENUM_SUFFIX ; break ; case IJavaSearchConstants . ANNOTATION_TYPE : typeSuffix = IIndexConstants . ANNOTATION_TYPE_SUFFIX ; break ; default : typeSuffix = IIndexConstants . TYPE_SUFFIX ; break ; } final TypeDeclarationPattern pattern = packageMatchRule == SearchPattern . R_EXACT_MATCH ? new TypeDeclarationPattern ( packageName , null , typeName , typeSuffix , validatedTypeMatchRule ) : new QualifiedTypeDeclarationPattern ( packageName , packageMatchRule , typeName , typeSuffix , validatedTypeMatchRule ) ; final HashSet workingCopyPaths = new HashSet ( ) ; String workingCopyPath = null ; ICompilationUnit [ ] copies = getWorkingCopies ( ) ; final int copiesLength = copies == null ? 0 : copies . length ; if ( copies != null ) { if ( copiesLength == 1 ) { workingCopyPath = copies [ 0 ] . getPath ( ) . toString ( ) ; } else { for ( int i = 0 ; i < copiesLength ; i ++ ) { ICompilationUnit workingCopy = copies [ i ] ; workingCopyPaths . add ( workingCopy . getPath ( ) . toString ( ) ) ; } } } final String singleWkcpPath = workingCopyPath ; IndexQueryRequestor searchRequestor = new IndexQueryRequestor ( ) { public boolean acceptIndexMatch ( String documentPath , SearchPattern indexRecord , SearchParticipant participant , AccessRuleSet access ) { TypeDeclarationPattern record = ( TypeDeclarationPattern ) indexRecord ; if ( record . enclosingTypeNames == IIndexConstants . ONE_ZERO_CHAR ) { return true ; } switch ( copiesLength ) { case 0 : break ; case 1 : if ( singleWkcpPath . equals ( documentPath ) ) { return true ; } break ; default : if ( workingCopyPaths . contains ( documentPath ) ) { return true ; } break ; } AccessRestriction accessRestriction = null ; if ( access != null ) { int pkgLength = ( record . pkg == null || record . pkg . length == 0 ) ? 0 : record . pkg . length + 1 ; int nameLength = record . simpleName == null ? 0 : record . simpleName . length ; char [ ] path = new char [ pkgLength + nameLength ] ; int pos = 0 ; if ( pkgLength > 0 ) { System . arraycopy ( record . pkg , 0 , path , pos , pkgLength - 1 ) ; CharOperation . replace ( path , '.' , '/' ) ; path [ pkgLength - 1 ] = '/' ; pos += pkgLength ; } if ( nameLength > 0 ) { System . arraycopy ( record . simpleName , 0 , path , pos , nameLength ) ; pos += nameLength ; } if ( pos > 0 ) { accessRestriction = access . getViolatedRestriction ( path ) ; } } if ( match ( record . typeSuffix , record . modifiers ) ) { nameRequestor . acceptType ( record . modifiers , record . pkg , record . simpleName , record . enclosingTypeNames , documentPath , accessRestriction ) ; } return true ; } } ; try { if ( progressMonitor != null ) { progressMonitor . beginTask ( Messages . engine_searching , 1000 ) ; } indexManager . performConcurrentJob ( new PatternSearchJob ( pattern , getDefaultSearchParticipant ( ) , scope , searchRequestor ) , waitingPolicy , progressMonitor == null ? null : new SubProgressMonitor ( progressMonitor , 1000 - copiesLength ) ) ; if ( copies != null ) { for ( int i = 0 ; i < copiesLength ; i ++ ) { final ICompilationUnit workingCopy = copies [ i ] ; if ( scope instanceof HierarchyScope ) { if ( ! ( ( HierarchyScope ) scope ) . encloses ( workingCopy , progressMonitor ) ) continue ; } else { if ( ! scope . encloses ( workingCopy ) ) continue ; } final String path = workingCopy . getPath ( ) . toString ( ) ; if ( workingCopy . isConsistent ( ) ) { IPackageDeclaration [ ] packageDeclarations = workingCopy . getPackageDeclarations ( ) ; char [ ] packageDeclaration = packageDeclarations . length == 0 ? CharOperation . NO_CHAR : packageDeclarations [ 0 ] . getElementName ( ) . toCharArray ( ) ; IType [ ] allTypes = workingCopy . getAllTypes ( ) ; for ( int j = 0 , allTypesLength = allTypes . length ; j < allTypesLength ; j ++ ) { IType type = allTypes [ j ] ; IJavaElement parent = type . getParent ( ) ; char [ ] [ ] enclosingTypeNames ; if ( parent instanceof IType ) { char [ ] parentQualifiedName = ( ( IType ) parent ) . getTypeQualifiedName ( '.' ) . toCharArray ( ) ; enclosingTypeNames = CharOperation . splitOn ( '.' , parentQualifiedName ) ; } else { enclosingTypeNames = CharOperation . NO_CHAR_CHAR ; } char [ ] simpleName = type . getElementName ( ) . toCharArray ( ) ; int kind ; if ( type . isEnum ( ) ) { kind = TypeDeclaration . ENUM_DECL ; } else if ( type . isAnnotation ( ) ) { kind = TypeDeclaration . ANNOTATION_TYPE_DECL ; } else if ( type . isClass ( ) ) { kind = TypeDeclaration . CLASS_DECL ; } else { kind = TypeDeclaration . INTERFACE_DECL ; } if ( match ( typeSuffix , packageName , packageMatchRule , typeName , validatedTypeMatchRule , kind , packageDeclaration , simpleName ) ) { if ( nameRequestor instanceof TypeNameMatchRequestorWrapper ) { ( ( TypeNameMatchRequestorWrapper ) nameRequestor ) . requestor . acceptTypeNameMatch ( new JavaSearchTypeNameMatch ( type , type . getFlags ( ) ) ) ; } else { nameRequestor . acceptType ( type . getFlags ( ) , packageDeclaration , simpleName , enclosingTypeNames , path , null ) ; } } } } else { Parser basicParser = getParser ( ) ; org . eclipse . jdt . internal . compiler . env . ICompilationUnit unit = ( org . eclipse . jdt . internal . compiler . env . ICompilationUnit ) workingCopy ; CompilationResult compilationUnitResult = new CompilationResult ( unit , 0 , 0 , this . compilerOptions . maxProblemsPerUnit ) ; CompilationUnitDeclaration parsedUnit = basicParser . dietParse ( unit , compilationUnitResult ) ; if ( parsedUnit != null ) { final char [ ] packageDeclaration = parsedUnit . currentPackage == null ? CharOperation . NO_CHAR : CharOperation . concatWith ( parsedUnit . currentPackage . getImportName ( ) , '.' ) ; class AllTypeDeclarationsVisitor extends ASTVisitor { public boolean visit ( TypeDeclaration typeDeclaration , BlockScope blockScope ) { return false ; } public boolean visit ( TypeDeclaration typeDeclaration , CompilationUnitScope compilationUnitScope ) { if ( match ( typeSuffix , packageName , packageMatchRule , typeName , validatedTypeMatchRule , TypeDeclaration . kind ( typeDeclaration . modifiers ) , packageDeclaration , typeDeclaration . name ) ) { if ( nameRequestor instanceof TypeNameMatchRequestorWrapper ) { IType type = workingCopy . getType ( new String ( typeName ) ) ; ( ( TypeNameMatchRequestorWrapper ) nameRequestor ) . requestor . acceptTypeNameMatch ( new JavaSearchTypeNameMatch ( type , typeDeclaration . modifiers ) ) ; } else { nameRequestor . acceptType ( typeDeclaration . modifiers , packageDeclaration , typeDeclaration . name , CharOperation . NO_CHAR_CHAR , path , null ) ; } } return true ; } public boolean visit ( TypeDeclaration memberTypeDeclaration , ClassScope classScope ) { if ( match ( typeSuffix , packageName , packageMatchRule , typeName , validatedTypeMatchRule , TypeDeclaration . kind ( memberTypeDeclaration . modifiers ) , packageDeclaration , memberTypeDeclaration . name ) ) { TypeDeclaration enclosing = memberTypeDeclaration . enclosingType ; char [ ] [ ] enclosingTypeNames = CharOperation . NO_CHAR_CHAR ; while ( enclosing != null ) { enclosingTypeNames = CharOperation . arrayConcat ( new char [ ] [ ] { enclosing . name } , enclosingTypeNames ) ; if ( ( enclosing . bits & ASTNode . IsMemberType ) != 0 ) { enclosing = enclosing . enclosingType ; } else { enclosing = null ; } } if ( nameRequestor instanceof TypeNameMatchRequestorWrapper ) { IType type = workingCopy . getType ( new String ( enclosingTypeNames [ 0 ] ) ) ; for ( int j = 1 , l = enclosingTypeNames . length ; j < l ; j ++ ) { type = type . getType ( new String ( enclosingTypeNames [ j ] ) ) ; } ( ( TypeNameMatchRequestorWrapper ) nameRequestor ) . requestor . acceptTypeNameMatch ( new JavaSearchTypeNameMatch ( type , 0 ) ) ; } else { nameRequestor . acceptType ( memberTypeDeclaration . modifiers , packageDeclaration , memberTypeDeclaration . name , enclosingTypeNames , path , null ) ; } } return true ; } } parsedUnit . traverse ( new AllTypeDeclarationsVisitor ( ) , parsedUnit . scope ) ; } } if ( progressMonitor != null ) { if ( progressMonitor . isCanceled ( ) ) throw new OperationCanceledException ( ) ; progressMonitor . worked ( 1 ) ; } } } } finally { if ( progressMonitor != null ) { progressMonitor . done ( ) ; } } } public void searchAllTypeNames ( final char [ ] [ ] qualifications , final char [ ] [ ] typeNames , final int matchRule , int searchFor , IJavaSearchScope scope , final IRestrictedAccessTypeRequestor nameRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { if ( VERBOSE ) { Util . verbose ( "" ) ; Util . verbose ( "" + ( qualifications == null ? "null" : new String ( CharOperation . concatWith ( qualifications , ',' ) ) ) ) ; Util . verbose ( "" + ( typeNames == null ? "null" : new String ( CharOperation . concatWith ( typeNames , ',' ) ) ) ) ; Util . verbose ( "" + getMatchRuleString ( matchRule ) ) ; Util . verbose ( "" + searchFor ) ; Util . verbose ( "t- scope: " + scope ) ; } IndexManager indexManager = JavaModelManager . getIndexManager ( ) ; final char typeSuffix ; switch ( searchFor ) { case IJavaSearchConstants . CLASS : typeSuffix = IIndexConstants . CLASS_SUFFIX ; break ; case IJavaSearchConstants . CLASS_AND_INTERFACE : typeSuffix = IIndexConstants . CLASS_AND_INTERFACE_SUFFIX ; break ; case IJavaSearchConstants . CLASS_AND_ENUM : typeSuffix = IIndexConstants . CLASS_AND_ENUM_SUFFIX ; break ; case IJavaSearchConstants . INTERFACE : typeSuffix = IIndexConstants . INTERFACE_SUFFIX ; break ; case IJavaSearchConstants . INTERFACE_AND_ANNOTATION : typeSuffix = IIndexConstants . INTERFACE_AND_ANNOTATION_SUFFIX ; break ; case IJavaSearchConstants . ENUM : typeSuffix = IIndexConstants . ENUM_SUFFIX ; break ; case IJavaSearchConstants . ANNOTATION_TYPE : typeSuffix = IIndexConstants . ANNOTATION_TYPE_SUFFIX ; break ; default : typeSuffix = IIndexConstants . TYPE_SUFFIX ; break ; } final MultiTypeDeclarationPattern pattern = new MultiTypeDeclarationPattern ( qualifications , typeNames , typeSuffix , matchRule ) ; final HashSet workingCopyPaths = new HashSet ( ) ; String workingCopyPath = null ; ICompilationUnit [ ] copies = getWorkingCopies ( ) ; final int copiesLength = copies == null ? 0 : copies . length ; if ( copies != null ) { if ( copiesLength == 1 ) { workingCopyPath = copies [ 0 ] . getPath ( ) . toString ( ) ; } else { for ( int i = 0 ; i < copiesLength ; i ++ ) { ICompilationUnit workingCopy = copies [ i ] ; workingCopyPaths . add ( workingCopy . getPath ( ) . toString ( ) ) ; } } } final String singleWkcpPath = workingCopyPath ; IndexQueryRequestor searchRequestor = new IndexQueryRequestor ( ) { public boolean acceptIndexMatch ( String documentPath , SearchPattern indexRecord , SearchParticipant participant , AccessRuleSet access ) { QualifiedTypeDeclarationPattern record = ( QualifiedTypeDeclarationPattern ) indexRecord ; if ( record . enclosingTypeNames == IIndexConstants . ONE_ZERO_CHAR ) { return true ; } switch ( copiesLength ) { case 0 : break ; case 1 : if ( singleWkcpPath . equals ( documentPath ) ) { return true ; } break ; default : if ( workingCopyPaths . contains ( documentPath ) ) { return true ; } break ; } AccessRestriction accessRestriction = null ; if ( access != null ) { int qualificationLength = ( record . qualification == null || record . qualification . length == 0 ) ? 0 : record . qualification . length + 1 ; int nameLength = record . simpleName == null ? 0 : record . simpleName . length ; char [ ] path = new char [ qualificationLength + nameLength ] ; int pos = 0 ; if ( qualificationLength > 0 ) { System . arraycopy ( record . qualification , 0 , path , pos , qualificationLength - 1 ) ; CharOperation . replace ( path , '.' , '/' ) ; path [ qualificationLength - 1 ] = '/' ; pos += qualificationLength ; } if ( nameLength > 0 ) { System . arraycopy ( record . simpleName , 0 , path , pos , nameLength ) ; pos += nameLength ; } if ( pos > 0 ) { accessRestriction = access . getViolatedRestriction ( path ) ; } } nameRequestor . acceptType ( record . modifiers , record . pkg , record . simpleName , record . enclosingTypeNames , documentPath , accessRestriction ) ; return true ; } } ; try { if ( progressMonitor != null ) { progressMonitor . beginTask ( Messages . engine_searching , 100 ) ; } indexManager . performConcurrentJob ( new PatternSearchJob ( pattern , getDefaultSearchParticipant ( ) , scope , searchRequestor ) , waitingPolicy , progressMonitor == null ? null : new SubProgressMonitor ( progressMonitor , 100 ) ) ; if ( copies != null ) { for ( int i = 0 , length = copies . length ; i < length ; i ++ ) { ICompilationUnit workingCopy = copies [ i ] ; final String path = workingCopy . getPath ( ) . toString ( ) ; if ( workingCopy . isConsistent ( ) ) { IPackageDeclaration [ ] packageDeclarations = workingCopy . getPackageDeclarations ( ) ; char [ ] packageDeclaration = packageDeclarations . length == 0 ? CharOperation . NO_CHAR : packageDeclarations [ 0 ] . getElementName ( ) . toCharArray ( ) ; IType [ ] allTypes = workingCopy . getAllTypes ( ) ; for ( int j = 0 , allTypesLength = allTypes . length ; j < allTypesLength ; j ++ ) { IType type = allTypes [ j ] ; IJavaElement parent = type . getParent ( ) ; char [ ] [ ] enclosingTypeNames ; char [ ] qualification = packageDeclaration ; if ( parent instanceof IType ) { char [ ] parentQualifiedName = ( ( IType ) parent ) . getTypeQualifiedName ( '.' ) . toCharArray ( ) ; enclosingTypeNames = CharOperation . splitOn ( '.' , parentQualifiedName ) ; qualification = CharOperation . concat ( qualification , parentQualifiedName ) ; } else { enclosingTypeNames = CharOperation . NO_CHAR_CHAR ; } char [ ] simpleName = type . getElementName ( ) . toCharArray ( ) ; char suffix = IIndexConstants . TYPE_SUFFIX ; if ( type . isClass ( ) ) { suffix = IIndexConstants . CLASS_SUFFIX ; } else if ( type . isInterface ( ) ) { suffix = IIndexConstants . INTERFACE_SUFFIX ; } else if ( type . isEnum ( ) ) { suffix = IIndexConstants . ENUM_SUFFIX ; } else if ( type . isAnnotation ( ) ) { suffix = IIndexConstants . ANNOTATION_TYPE_SUFFIX ; } if ( pattern . matchesDecodedKey ( new QualifiedTypeDeclarationPattern ( qualification , simpleName , suffix , matchRule ) ) ) { nameRequestor . acceptType ( type . getFlags ( ) , packageDeclaration , simpleName , enclosingTypeNames , path , null ) ; } } } else { Parser basicParser = getParser ( ) ; org . eclipse . jdt . internal . compiler . env . ICompilationUnit unit = ( org . eclipse . jdt . internal . compiler . env . ICompilationUnit ) workingCopy ; CompilationResult compilationUnitResult = new CompilationResult ( unit , 0 , 0 , this . compilerOptions . maxProblemsPerUnit ) ; CompilationUnitDeclaration parsedUnit = basicParser . dietParse ( unit , compilationUnitResult ) ; if ( parsedUnit != null ) { final char [ ] packageDeclaration = parsedUnit . currentPackage == null ? CharOperation . NO_CHAR : CharOperation . concatWith ( parsedUnit . currentPackage . getImportName ( ) , '.' ) ; class AllTypeDeclarationsVisitor extends ASTVisitor { public boolean visit ( TypeDeclaration typeDeclaration , BlockScope blockScope ) { return false ; } public boolean visit ( TypeDeclaration typeDeclaration , CompilationUnitScope compilationUnitScope ) { SearchPattern decodedPattern = new QualifiedTypeDeclarationPattern ( packageDeclaration , typeDeclaration . name , convertTypeKind ( TypeDeclaration . kind ( typeDeclaration . modifiers ) ) , matchRule ) ; if ( pattern . matchesDecodedKey ( decodedPattern ) ) { nameRequestor . acceptType ( typeDeclaration . modifiers , packageDeclaration , typeDeclaration . name , CharOperation . NO_CHAR_CHAR , path , null ) ; } return true ; } public boolean visit ( TypeDeclaration memberTypeDeclaration , ClassScope classScope ) { char [ ] qualification = packageDeclaration ; TypeDeclaration enclosing = memberTypeDeclaration . enclosingType ; char [ ] [ ] enclosingTypeNames = CharOperation . NO_CHAR_CHAR ; while ( enclosing != null ) { qualification = CharOperation . concat ( qualification , enclosing . name , '.' ) ; enclosingTypeNames = CharOperation . arrayConcat ( new char [ ] [ ] { enclosing . name } , enclosingTypeNames ) ; if ( ( enclosing . bits & ASTNode . IsMemberType ) != 0 ) { enclosing = enclosing . enclosingType ; } else { enclosing = null ; } } SearchPattern decodedPattern = new QualifiedTypeDeclarationPattern ( qualification , memberTypeDeclaration . name , convertTypeKind ( TypeDeclaration . kind ( memberTypeDeclaration . modifiers ) ) , matchRule ) ; if ( pattern . matchesDecodedKey ( decodedPattern ) ) { nameRequestor . acceptType ( memberTypeDeclaration . modifiers , packageDeclaration , memberTypeDeclaration . name , enclosingTypeNames , path , null ) ; } return true ; } } parsedUnit . traverse ( new AllTypeDeclarationsVisitor ( ) , parsedUnit . scope ) ; } } } } } finally { if ( progressMonitor != null ) { progressMonitor . done ( ) ; } } } public void searchDeclarations ( IJavaElement enclosingElement , SearchRequestor requestor , SearchPattern pattern , IProgressMonitor monitor ) throws JavaModelException { if ( VERBOSE ) { Util . verbose ( "" + enclosingElement ) ; } IJavaSearchScope scope = createJavaSearchScope ( new IJavaElement [ ] { enclosingElement } ) ; IResource resource = ( ( JavaElement ) enclosingElement ) . resource ( ) ; if ( enclosingElement instanceof IMember ) { IMember member = ( IMember ) enclosingElement ; ICompilationUnit cu = member . getCompilationUnit ( ) ; if ( cu != null ) { resource = cu . getResource ( ) ; } else if ( member . isBinary ( ) ) { resource = null ; } } try { if ( resource instanceof IFile ) { try { requestor . beginReporting ( ) ; if ( VERBOSE ) { Util . verbose ( "" + pattern + " in " + resource . getFullPath ( ) ) ; } SearchParticipant participant = getDefaultSearchParticipant ( ) ; SearchDocument [ ] documents = MatchLocator . addWorkingCopies ( pattern , new SearchDocument [ ] { new JavaSearchDocument ( enclosingElement . getPath ( ) . toString ( ) , participant ) } , getWorkingCopies ( enclosingElement ) , participant ) ; participant . locateMatches ( documents , pattern , scope , requestor , monitor ) ; } finally { requestor . endReporting ( ) ; } } else { search ( pattern , new SearchParticipant [ ] { getDefaultSearchParticipant ( ) } , scope , requestor , monitor ) ; } } catch ( CoreException e ) { if ( e instanceof JavaModelException ) throw ( JavaModelException ) e ; throw new JavaModelException ( e ) ; } } public void searchDeclarationsOfAccessedFields ( IJavaElement enclosingElement , SearchRequestor requestor , IProgressMonitor monitor ) throws JavaModelException { if ( VERBOSE ) { Util . verbose ( "" ) ; } switch ( enclosingElement . getElementType ( ) ) { case IJavaElement . FIELD : case IJavaElement . METHOD : case IJavaElement . TYPE : case IJavaElement . COMPILATION_UNIT : break ; default : throw new IllegalArgumentException ( ) ; } SearchPattern pattern = new DeclarationOfAccessedFieldsPattern ( enclosingElement ) ; searchDeclarations ( enclosingElement , requestor , pattern , monitor ) ; } public void searchDeclarationsOfReferencedTypes ( IJavaElement enclosingElement , SearchRequestor requestor , IProgressMonitor monitor ) throws JavaModelException { if ( VERBOSE ) { Util . verbose ( "" ) ; } switch ( enclosingElement . getElementType ( ) ) { case IJavaElement . FIELD : case IJavaElement . METHOD : case IJavaElement . TYPE : case IJavaElement . COMPILATION_UNIT : break ; default : throw new IllegalArgumentException ( ) ; } SearchPattern pattern = new DeclarationOfReferencedTypesPattern ( enclosingElement ) ; searchDeclarations ( enclosingElement , requestor , pattern , monitor ) ; } public void searchDeclarationsOfSentMessages ( IJavaElement enclosingElement , SearchRequestor requestor , IProgressMonitor monitor ) throws JavaModelException { if ( VERBOSE ) { Util . verbose ( "" ) ; } switch ( enclosingElement . getElementType ( ) ) { case IJavaElement . FIELD : case IJavaElement . METHOD : case IJavaElement . TYPE : case IJavaElement . COMPILATION_UNIT : break ; default : throw new IllegalArgumentException ( ) ; } SearchPattern pattern = new DeclarationOfReferencedMethodsPattern ( enclosingElement ) ; searchDeclarations ( enclosingElement , requestor , pattern , monitor ) ; } } </s>