public static void findSuiteMethods(IJavaElement element, Set<IType> result, IProgressMonitor pm) throws CoreException { // fix for bug 36449 JUnit should constrain tests to selected project // [JUnit] IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] { element }, IJavaSearchScope.SOURCES); SearchRequestor requestor= new SuiteMethodTypesCollector(result); int matchRule= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH; SearchPattern suitePattern= SearchPattern.createPattern("suite() Test", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, matchRule); //$NON-NLS-1$ SearchParticipant[] participants= new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; new SearchEngine().search(suitePattern, participants, scope, requestor, pm); }
private static IType[] findTypes(String typeName, IProgressMonitor monitor) throws CoreException { final List results= new ArrayList(); SearchRequestor collector= new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element= match.getElement(); if (element instanceof IType) results.add(element); } }; SearchEngine engine= new SearchEngine(); SearchPattern pattern= SearchPattern.createPattern(typeName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), collector, monitor); return (IType[]) results.toArray(new IType[results.size()]); }
private void refreshSearchIndices(IProgressMonitor monitor) throws InvocationTargetException { try { new SearchEngine().searchAllTypeNames( null, 0, // make sure we search a concrete name. This is faster according to Kent "_______________".toCharArray(), //$NON-NLS-1$ SearchPattern.RULE_EXACT_MATCH | SearchPattern.RULE_CASE_SENSITIVE, IJavaSearchConstants.ENUM, SearchEngine.createWorkspaceScope(), new TypeNameRequestor() {}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); } catch (JavaModelException e) { throw new InvocationTargetException(e); } } }
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { yourProject }); //IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); // Use this if you dont have the IProject in hand SearchPattern searchPattern = SearchPattern.createPattern(field, IJavaSearchConstants.REFERENCES); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) { System.out.println(match.getElement()); } }; SearchEngine searchEngine = new SearchEngine(); searchEngine.search(searchParttern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor());
/** * Creates a TypeHierarchy on the given type. */ public TypeHierarchy(IType type, ICompilationUnit[] workingCopies, IJavaProject project, boolean computeSubtypes) { this(type, workingCopies, SearchEngine.createJavaSearchScope(new IJavaElement[] {project}), computeSubtypes); this.project = project; } /**
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException { fDeclarations = new ArrayList<>(); class MethodRequestor extends SearchRequestor { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { IMethod method = (IMethod) match.getElement(); boolean isBinary = method.isBinary(); if (!isBinary) { fDeclarations.add(method); } } } int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE; int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule); MethodRequestor requestor = new MethodRequestor(); SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine(); searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), requestor, monitor); }
private TypeReference(IJavaElement enclosingElement, int accuracy, int start, int length, boolean insideDocComment, IResource resource, int simpleNameStart, String simpleName) { super(enclosingElement, accuracy, start, length, insideDocComment, SearchEngine.getDefaultSearchParticipant(), resource); fSimpleNameStart= simpleNameStart; fSimpleTypeName= simpleName; }
private void searchForTypesUsed(SearchEngine engine, IJavaElement parent, IType[] types, IJavaSearchScope scope) throws CoreException { for (IType type : types) { if (type.isAnonymous()) continue; TypeReferenceSearchRequestor requestor = new TypeReferenceSearchRequestor(); engine.search(SearchPattern.createPattern(type, IJavaSearchConstants.REFERENCES), new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, scope, requestor, null); if (requestor.containMatches()) { TypeDeclarationSearchRequestor decRequestor = new TypeDeclarationSearchRequestor(); engine.search(SearchPattern.createPattern(type, IJavaSearchConstants.DECLARATIONS), new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, SearchEngine.createJavaSearchScope(new IJavaElement[] {parent}), decRequestor, null); Match match = decRequestor.getMatch(); if (match != null) fSearchResult.addMatch(match); } } }
public IJavaSearchScope createWorkspaceScope(int includeMask) { if ((includeMask & NO_PROJ) != NO_PROJ) { try { IJavaProject[] projects= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects(); return SearchEngine.createJavaSearchScope(projects, getSearchFlags(includeMask)); } catch (JavaModelException e) { // ignore, use workspace scope instead } } return SearchEngine.createWorkspaceScope(); }
@Override public Set<String> findConflictingSimpleNames( Set<String> simpleNames, Set<String> onDemandAndImplicitContainerNames, IProgressMonitor monitor) throws JavaModelException { IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { this.javaProject }); ConflictAccumulatingTypeRequestor requestor = new ConflictAccumulatingTypeRequestor(); this.searchEngine.searchAllTypeNames( stringsToCharArrays(onDemandAndImplicitContainerNames), stringsToCharArrays(simpleNames), scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); return requestor.getNamesFoundInMultipleContainers(); } }
public IJavaSearchScope getSearchScope() { if (fSearchScope == null) { fSearchScope= SearchEngine.createWorkspaceScope(); } return fSearchScope; }
private static List<SearchMatch> getTypeReferencesIn(IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException { CollectingSearchRequestor requestor= new CollectingSearchRequestor(); SearchEngine engine= owner != null ? new SearchEngine(owner) : new SearchEngine(); engine.searchDeclarationsOfReferencedTypes(element, requestor, pm); return requestor.getResults(); }
private static List<SearchMatch> getMethodReferencesIn(IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException { CollectingSearchRequestor requestor= new CollectingSearchRequestor(); SearchEngine engine= owner != null ? new SearchEngine(owner) : new SearchEngine(); engine.searchDeclarationsOfSentMessages(element, requestor, pm); return requestor.getResults(); }
private static List<SearchMatch> getFieldReferencesIn(IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException { CollectingSearchRequestor requestor= new CollectingSearchRequestor(); SearchEngine engine= owner != null ? new SearchEngine(owner) : new SearchEngine(); engine.searchDeclarationsOfAccessedFields(element, requestor, pm); return requestor.getResults(); }
public static SearchResultGroup[] search(SearchPattern pattern, WorkingCopyOwner owner, IJavaSearchScope scope, CollectingSearchRequestor requestor, IProgressMonitor monitor, RefactoringStatus status) throws JavaModelException { return internalSearch(owner != null ? new SearchEngine(owner) : new SearchEngine(), pattern, scope, requestor, monitor, status); }
private static SearchResultGroup[] internalSearch(SearchEngine searchEngine, SearchPattern pattern, IJavaSearchScope scope, CollectingSearchRequestor requestor, IProgressMonitor monitor, RefactoringStatus status) throws JavaModelException { try { searchEngine.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, monitor); } catch (CoreException e) { throw new JavaModelException(e); } return groupByCu(requestor.getResults(), status); }
/** * Internal adapter class. * @deprecated marking deprecated as it uses deprecated ITypeNameRequestor */ 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); } } }
/** * Searches for all main methods in the given scope. * Valid styles are IJavaElementSearchConstants.CONSIDER_BINARIES and * IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS */ public IType[] searchMainMethods(IProgressMonitor pm, IJavaSearchScope scope, int style) throws CoreException { List typesFound= new ArrayList(200); SearchPattern pattern= SearchPattern.createPattern("main(String[]) void", //$NON-NLS-1$ IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); SearchRequestor requestor= new MethodCollector(typesFound, style); new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return (IType[]) typesFound.toArray(new IType[typesFound.size()]); }
/** * Returns a Java search scope limited to the given Java elements. The Java elements resulting from a search with this * scope will be children of the given elements. * <p> * If an element is an {@link IJavaProject}, then only project's source folders will be included. * </p> * * @see SearchEngine#createJavaSearchScope(IJavaElement[], int) */ public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements) { return SearchEngine.createJavaSearchScope(elements, IJavaSearchScope.SOURCES); }
private TypeReference(IJavaElement enclosingElement, int accuracy, int start, int length, boolean insideDocComment, IResource resource, int simpleNameStart, String simpleName) { super(enclosingElement, accuracy, start, length, insideDocComment, SearchEngine.getDefaultSearchParticipant(), resource); fSimpleNameStart= simpleNameStart; fSimpleTypeName= simpleName; }