<s> package org . eclipse . jdt . core . search ; import org . codehaus . jdt . groovy . integration . LanguageSupportFactory ; import org . eclipse . core . resources . * ; import org . eclipse . core . runtime . * ; import org . eclipse . jdt . core . * ; import org . eclipse . jdt . internal . compiler . env . AccessRestriction ; import org . eclipse . jdt . internal . core . search . * ; import org . eclipse . jdt . internal . core . search . matching . * ; public class SearchEngine { static class SearchPatternAdapter implements ISearchPattern { SearchPattern pattern ; SearchPatternAdapter ( SearchPattern pattern ) { this . pattern = pattern ; } } static class ResultCollectorAdapter extends SearchRequestor { IJavaSearchResultCollector resultCollector ; ResultCollectorAdapter ( IJavaSearchResultCollector resultCollector ) { this . resultCollector = resultCollector ; } public void acceptSearchMatch ( SearchMatch match ) throws CoreException { this . resultCollector . accept ( match . getResource ( ) , match . getOffset ( ) , match . getOffset ( ) + match . getLength ( ) , ( IJavaElement ) match . getElement ( ) , match . getAccuracy ( ) ) ; } public void beginReporting ( ) { this . resultCollector . aboutToStart ( ) ; } public void endReporting ( ) { this . resultCollector . done ( ) ; } } static class TypeNameRequestorAdapter implements IRestrictedAccessTypeRequestor { ITypeNameRequestor nameRequestor ; TypeNameRequestorAdapter ( ITypeNameRequestor requestor ) { this . nameRequestor = requestor ; } public void acceptType ( int modifiers , char [ ] packageName , char [ ] simpleTypeName , char [ ] [ ] enclosingTypeNames , String path , AccessRestriction access ) { if ( Flags . isInterface ( modifiers ) ) { this . nameRequestor . acceptInterface ( packageName , simpleTypeName , enclosingTypeNames , path ) ; } else { this . nameRequestor . acceptClass ( packageName , simpleTypeName , enclosingTypeNames , path ) ; } } } private BasicSearchEngine basicEngine ; public SearchEngine ( ) { this . basicEngine = new BasicSearchEngine ( ) ; } public SearchEngine ( ICompilationUnit [ ] workingCopies ) { this . basicEngine = new BasicSearchEngine ( workingCopies ) ; } public SearchEngine ( IWorkingCopy [ ] workingCopies ) { int length = workingCopies . length ; ICompilationUnit [ ] units = new ICompilationUnit [ length ] ; System . arraycopy ( workingCopies , 0 , units , 0 , length ) ; this . basicEngine = new BasicSearchEngine ( units ) ; } public SearchEngine ( WorkingCopyOwner workingCopyOwner ) { this . basicEngine = new BasicSearchEngine ( workingCopyOwner ) ; } public static IJavaSearchScope createHierarchyScope ( IType type ) throws JavaModelException { return BasicSearchEngine . createHierarchyScope ( type ) ; } public static IJavaSearchScope createHierarchyScope ( IType type , WorkingCopyOwner owner ) throws JavaModelException { return BasicSearchEngine . createHierarchyScope ( type , owner ) ; } public static IJavaSearchScope createStrictHierarchyScope ( IJavaProject project , IType type , boolean onlySubtypes , boolean includeFocusType , WorkingCopyOwner owner ) throws JavaModelException { return BasicSearchEngine . createStrictHierarchyScope ( project , type , onlySubtypes , includeFocusType , owner ) ; } public static IJavaSearchScope createJavaSearchScope ( IResource [ ] resources ) { int length = resources . length ; IJavaElement [ ] elements = new IJavaElement [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { elements [ i ] = JavaCore . create ( resources [ i ] ) ; } return createJavaSearchScope ( elements ) ; } public static IJavaSearchScope createJavaSearchScope ( IJavaElement [ ] elements ) { return BasicSearchEngine . createJavaSearchScope ( elements ) ; } public static IJavaSearchScope createJavaSearchScope ( IJavaElement [ ] elements , boolean includeReferencedProjects ) { return BasicSearchEngine . createJavaSearchScope ( elements , includeReferencedProjects ) ; } public static IJavaSearchScope createJavaSearchScope ( IJavaElement [ ] elements , int includeMask ) { return BasicSearchEngine . createJavaSearchScope ( elements , includeMask ) ; } public static ISearchPattern createOrSearchPattern ( ISearchPattern leftPattern , ISearchPattern rightPattern ) { SearchPattern left = ( ( SearchPatternAdapter ) leftPattern ) . pattern ; SearchPattern right = ( ( SearchPatternAdapter ) rightPattern ) . pattern ; SearchPattern pattern = SearchPattern . createOrPattern ( left , right ) ; return new SearchPatternAdapter ( pattern ) ; } public static ISearchPattern createSearchPattern ( String stringPattern , int searchFor , int limitTo , boolean isCaseSensitive ) { int matchMode = stringPattern . indexOf ( '*' ) != - 1 || stringPattern . indexOf ( '?' ) != - 1 ? SearchPattern . R_PATTERN_MATCH : SearchPattern . R_EXACT_MATCH ; int matchRule = isCaseSensitive ? matchMode | SearchPattern . R_CASE_SENSITIVE : matchMode ; return new SearchPatternAdapter ( SearchPattern . createPattern ( stringPattern , searchFor , limitTo , matchRule ) ) ; } public static ISearchPattern createSearchPattern ( IJavaElement element , int limitTo ) { return new SearchPatternAdapter ( SearchPattern . createPattern ( element , limitTo ) ) ; } public static TypeNameMatch createTypeNameMatch ( IType type , int modifiers ) { return BasicSearchEngine . createTypeNameMatch ( type , modifiers ) ; } public static IJavaSearchScope createWorkspaceScope ( ) { return BasicSearchEngine . createWorkspaceScope ( ) ; } public static SearchParticipant getDefaultSearchParticipant ( ) { return BasicSearchEngine . getDefaultSearchParticipant ( ) ; } public void search ( IWorkspace workspace , String patternString , int searchFor , int limitTo , IJavaSearchScope scope , IJavaSearchResultCollector resultCollector ) throws JavaModelException { try { int matchMode = patternString . indexOf ( '*' ) != - 1 || patternString . indexOf ( '?' ) != - 1 ? SearchPattern . R_PATTERN_MATCH : SearchPattern . R_EXACT_MATCH ; search ( SearchPattern . createPattern ( patternString , searchFor , limitTo , matchMode | SearchPattern . R_CASE_SENSITIVE ) , new SearchParticipant [ ] { getDefaultSearchParticipant ( ) } , scope , new ResultCollectorAdapter ( resultCollector ) , resultCollector . getProgressMonitor ( ) ) ; } catch ( CoreException e ) { if ( e instanceof JavaModelException ) throw ( JavaModelException ) e ; throw new JavaModelException ( e ) ; } } public void search ( IWorkspace workspace , IJavaElement element , int limitTo , IJavaSearchScope scope , IJavaSearchResultCollector resultCollector ) throws JavaModelException { search ( workspace , createSearchPattern ( element , limitTo ) , scope , resultCollector ) ; } public void search ( IWorkspace workspace , ISearchPattern searchPattern , IJavaSearchScope scope , IJavaSearchResultCollector resultCollector ) throws JavaModelException { try { search ( ( ( SearchPatternAdapter ) searchPattern ) . pattern , new SearchParticipant [ ] { getDefaultSearchParticipant ( ) } , scope , new ResultCollectorAdapter ( resultCollector ) , resultCollector . getProgressMonitor ( ) ) ; } catch ( CoreException e ) { if ( e instanceof JavaModelException ) throw ( JavaModelException ) e ; throw new JavaModelException ( e ) ; } } public void search ( SearchPattern pattern , SearchParticipant [ ] participants , IJavaSearchScope scope , SearchRequestor requestor , IProgressMonitor monitor ) throws CoreException { if ( pattern . focus != null && LanguageSupportFactory . isInterestingProject ( pattern . focus . getJavaProject ( ) . getProject ( ) ) ) { scope = LanguageSupportFactory . expandSearchScope ( scope , pattern , requestor ) ; } this . basicEngine . search ( pattern , participants , scope , requestor , monitor ) ; } public void searchAllTypeNames ( final char [ ] packageExactName , final char [ ] typeName , final int matchRule , int searchFor , IJavaSearchScope scope , final TypeNameRequestor nameRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { searchAllTypeNames ( packageExactName , SearchPattern . R_EXACT_MATCH , typeName , matchRule , searchFor , scope , nameRequestor , waitingPolicy , progressMonitor ) ; } public void searchAllTypeNames ( final char [ ] packageName , final int packageMatchRule , final char [ ] typeName , final int typeMatchRule , int searchFor , IJavaSearchScope scope , final TypeNameRequestor nameRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { TypeNameRequestorWrapper requestorWrapper = new TypeNameRequestorWrapper ( nameRequestor ) ; this . basicEngine . searchAllTypeNames ( packageName , packageMatchRule , typeName , typeMatchRule , searchFor , scope , requestorWrapper , waitingPolicy , progressMonitor ) ; } public void searchAllTypeNames ( final char [ ] packageName , final int packageMatchRule , final char [ ] typeName , final int typeMatchRule , int searchFor , IJavaSearchScope scope , final TypeNameMatchRequestor nameMatchRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper ( nameMatchRequestor , scope ) ; this . basicEngine . searchAllTypeNames ( packageName , packageMatchRule , typeName , typeMatchRule , searchFor , scope , requestorWrapper , waitingPolicy , progressMonitor ) ; } public void searchAllTypeNames ( final char [ ] [ ] qualifications , final char [ ] [ ] typeNames , IJavaSearchScope scope , final TypeNameRequestor nameRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { TypeNameRequestorWrapper requestorWrapper = new TypeNameRequestorWrapper ( nameRequestor ) ; this . basicEngine . searchAllTypeNames ( qualifications , typeNames , SearchPattern . R_EXACT_MATCH | SearchPattern . R_CASE_SENSITIVE , IJavaSearchConstants . TYPE , scope , requestorWrapper , waitingPolicy , progressMonitor ) ; } public void searchAllTypeNames ( final char [ ] [ ] qualifications , final char [ ] [ ] typeNames , IJavaSearchScope scope , final TypeNameMatchRequestor nameMatchRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { TypeNameMatchRequestorWrapper requestorWrapper = new TypeNameMatchRequestorWrapper ( nameMatchRequestor , scope ) ; this . basicEngine . searchAllTypeNames ( qualifications , typeNames , SearchPattern . R_EXACT_MATCH | SearchPattern . R_CASE_SENSITIVE , IJavaSearchConstants . TYPE , scope , requestorWrapper , waitingPolicy , progressMonitor ) ; } public void searchAllTypeNames ( final char [ ] packageName , final char [ ] typeName , final int matchRule , int searchFor , IJavaSearchScope scope , final ITypeNameRequestor nameRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { TypeNameRequestorAdapter requestorAdapter = new TypeNameRequestorAdapter ( nameRequestor ) ; this . basicEngine . searchAllTypeNames ( packageName , SearchPattern . R_EXACT_MATCH , typeName , matchRule , searchFor , scope , requestorAdapter , waitingPolicy , progressMonitor ) ; } public void searchAllTypeNames ( IWorkspace workspace , final char [ ] packageName , final char [ ] typeName , final int matchMode , final boolean isCaseSensitive , int searchFor , IJavaSearchScope scope , final ITypeNameRequestor nameRequestor , int waitingPolicy , IProgressMonitor progressMonitor ) throws JavaModelException { searchAllTypeNames ( packageName , typeName , isCaseSensitive ? matchMode | SearchPattern . R_CASE_SENSITIVE : matchMode , searchFor , scope , nameRequestor , waitingPolicy , progressMonitor ) ; } public void searchDeclarationsOfAccessedFields ( IJavaElement enclosingElement , SearchRequestor requestor , IProgressMonitor monitor ) throws JavaModelException { this . basicEngine . searchDeclarationsOfAccessedFields ( enclosingElement , requestor , monitor ) ; } public void searchDeclarationsOfAccessedFields ( IWorkspace workspace , IJavaElement enclosingElement , IJavaSearchResultCollector resultCollector ) throws JavaModelException { SearchPattern pattern = new DeclarationOfAccessedFieldsPattern ( enclosingElement ) ; this . basicEngine . searchDeclarations ( enclosingElement , new ResultCollectorAdapter ( resultCollector ) , pattern , resultCollector . getProgressMonitor ( ) ) ; } public void searchDeclarationsOfReferencedTypes ( IJavaElement enclosingElement , SearchRequestor requestor , IProgressMonitor monitor ) throws JavaModelException { this . basicEngine . searchDeclarationsOfReferencedTypes ( enclosingElement , requestor , monitor ) ; } public void searchDeclarationsOfReferencedTypes ( IWorkspace workspace , IJavaElement enclosingElement , IJavaSearchResultCollector resultCollector ) throws JavaModelException { SearchPattern pattern = new DeclarationOfReferencedTypesPattern ( enclosingElement ) ; this . basicEngine . searchDeclarations ( enclosingElement , new ResultCollectorAdapter ( resultCollector ) , pattern , resultCollector . getProgressMonitor ( ) ) ; } public void searchDeclarationsOfSentMessages ( IJavaElement enclosingElement , SearchRequestor requestor , IProgressMonitor monitor ) throws JavaModelException { this . basicEngine . searchDeclarationsOfSentMessages ( enclosingElement , requestor , monitor ) ; } public void searchDeclarationsOfSentMessages ( IWorkspace workspace , IJavaElement enclosingElement , IJavaSearchResultCollector resultCollector ) throws JavaModelException { SearchPattern pattern = new DeclarationOfReferencedMethodsPattern ( enclosingElement ) ; this . basicEngine . searchDeclarations ( enclosingElement , new ResultCollectorAdapter ( resultCollector ) , pattern , resultCollector . getProgressMonitor ( ) ) ; } } </s>