/** * 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()]); }
/** * Searches for all main methods in the given scope. * Valid styles are IJavaElementSearchConstants.CONSIDER_BINARIES and * IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS * @param pm progress monitor * @param scope the search scope * @param style search style constants (see {@link IJavaElementSearchConstants}) * @return the types found * @throws CoreException */ public IType[] searchMainMethods(IProgressMonitor pm, IJavaSearchScope scope, int style) throws CoreException { List<IType> 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 typesFound.toArray(new IType[typesFound.size()]); }
/** * @return all package fragments in <code>scope</code> with same name as <code>fPackage</code>, excluding fPackage */ private IPackageFragment[] getNamesakePackages(IJavaSearchScope scope, IProgressMonitor pm) throws CoreException { SearchPattern pattern= SearchPattern.createPattern(fPackage.getElementName(), IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); final HashSet packageFragments= new HashSet(); SearchRequestor requestor= new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(match); if (enclosingElement instanceof IPackageFragment) { IPackageFragment pack= (IPackageFragment) enclosingElement; if (! fPackage.equals(pack)) packageFragments.add(pack); } } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return (IPackageFragment[]) packageFragments.toArray(new IPackageFragment[packageFragments.size()]); }
/** * Searches for all main methods in the given scope. * Valid styles are IJavaElementSearchConstants.CONSIDER_BINARIES and * IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS * @param pm progress monitor * @param scope the search scope * @param style search style constants (see {@link IJavaElementSearchConstants}) * @return the types found * @throws CoreException */ public IType[] searchMainMethods(IProgressMonitor pm, IJavaSearchScope scope, int style) throws CoreException { List<IType> 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 typesFound.toArray(new IType[typesFound.size()]); }
/** * @param scope search scope * @param pm mrogress monitor * @return all package fragments in <code>scope</code> with same name as <code>fPackage</code>, excluding fPackage * @throws CoreException if search failed */ private IPackageFragment[] getNamesakePackages(IJavaSearchScope scope, IProgressMonitor pm) throws CoreException { SearchPattern pattern= SearchPattern.createPattern(fPackage.getElementName(), IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); final HashSet<IPackageFragment> packageFragments= new HashSet<>(); SearchRequestor requestor= new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(match); if (enclosingElement instanceof IPackageFragment) { IPackageFragment pack= (IPackageFragment) enclosingElement; if (! fPackage.equals(pack)) packageFragments.add(pack); } } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return packageFragments.toArray(new IPackageFragment[packageFragments.size()]); }
/** * @param scope search scope * @param pm mrogress monitor * @return all package fragments in <code>scope</code> with same name as <code>fPackage</code>, excluding fPackage * @throws CoreException if search failed */ private IPackageFragment[] getNamesakePackages(IJavaSearchScope scope, IProgressMonitor pm) throws CoreException { SearchPattern pattern= SearchPattern.createPattern(fPackage.getElementName(), IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); final HashSet<IPackageFragment> packageFragments= new HashSet<>(); SearchRequestor requestor= new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(match); if (enclosingElement instanceof IPackageFragment) { IPackageFragment pack= (IPackageFragment) enclosingElement; if (! fPackage.equals(pack)) packageFragments.add(pack); } } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return packageFragments.toArray(new IPackageFragment[packageFragments.size()]); }
private IMethod[] searchForDeclarationsOfClashingMethods(IProgressMonitor pm) throws CoreException { final List<IMethod> results= new ArrayList<>(); SearchPattern pattern= createNewMethodPattern(); IJavaSearchScope scope= RefactoringScopeFactory.create(getMethod().getJavaProject()); SearchRequestor requestor= new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object method= match.getElement(); if (method instanceof IMethod) // check for bug 90138: [refactoring] [rename] Renaming method throws internal exception results.add((IMethod) method); else JavaPlugin.logErrorMessage("Unexpected element in search match: " + match.toString()); //$NON-NLS-1$ } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return results.toArray(new IMethod[results.size()]); }
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm) throws CoreException { final Set<IType> outerTypesOfReferences= new HashSet<>(); SearchPattern pattern= RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES); IJavaSearchScope scope= createRefactoringScope(getMethod()); SearchRequestor requestor= new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element= match.getElement(); if (!(element instanceof IMember)) return; // e.g. an IImportDeclaration for a static method import IMember member= (IMember) element; IType declaring= member.getDeclaringType(); if (declaring == null) return; IType outer= declaring.getDeclaringType(); if (outer != null) outerTypesOfReferences.add(declaring); } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]); }
private IMethod[] searchForDeclarationsOfClashingMethods(IProgressMonitor pm) throws CoreException { final List results= new ArrayList(); SearchPattern pattern= createNewMethodPattern(); IJavaSearchScope scope= RefactoringScopeFactory.create(getMethod().getJavaProject()); SearchRequestor requestor= new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { Object method= match.getElement(); if (method instanceof IMethod) // check for bug 90138: [refactoring] [rename] Renaming method throws internal exception results.add(method); else JavaPlugin.logErrorMessage("Unexpected element in search match: " + match.toString()); //$NON-NLS-1$ } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return (IMethod[]) results.toArray(new IMethod[results.size()]); }
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm) throws CoreException { final Set<IType> outerTypesOfReferences= new HashSet<>(); SearchPattern pattern= RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES); IJavaSearchScope scope= createRefactoringScope(getMethod()); SearchRequestor requestor= new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element= match.getElement(); if (!(element instanceof IMember)) return; // e.g. an IImportDeclaration for a static method import IMember member= (IMember) element; IType declaring= member.getDeclaringType(); if (declaring == null) return; IType outer= declaring.getDeclaringType(); if (outer != null) outerTypesOfReferences.add(declaring); } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]); }
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); }
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm) throws CoreException { final Set outerTypesOfReferences= new HashSet(); SearchPattern pattern= RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES); IJavaSearchScope scope= createRefactoringScope(getMethod()); SearchRequestor requestor= new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element= match.getElement(); if (!(element instanceof IMember)) return; // e.g. an IImportDeclaration for a static method import IMember member= (IMember) element; IType declaring= member.getDeclaringType(); if (declaring == null) return; IType outer= declaring.getDeclaringType(); if (outer != null) outerTypesOfReferences.add(declaring); } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return (IType[]) outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]); }
private IMethod[] searchForDeclarationsOfClashingMethods(IProgressMonitor pm) throws CoreException { final List<IMethod> results= new ArrayList<>(); SearchPattern pattern= createNewMethodPattern(); IJavaSearchScope scope= RefactoringScopeFactory.create(getMethod().getJavaProject()); SearchRequestor requestor= new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object method= match.getElement(); if (method instanceof IMethod) // check for bug 90138: [refactoring] [rename] Renaming method throws internal exception results.add((IMethod) method); else JavaPlugin.logErrorMessage("Unexpected element in search match: " + match.toString()); //$NON-NLS-1$ } }; new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm); return results.toArray(new IMethod[results.size()]); }
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); }
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); }
/** * Performs the search according to the specified pattern. * * @param monitor the progress monitor, or <code>null</code> * @throws JavaModelException if an error occurs during search */ public final void searchPattern(IProgressMonitor monitor) throws JavaModelException { Assert.isNotNull(fPattern); if (monitor == null) monitor= new NullProgressMonitor(); try { monitor.beginTask("", 1); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_occurrences); try { SearchEngine engine= null; if (fOwner != null) engine= new SearchEngine(fOwner); else engine= new SearchEngine(fWorkingCopies); engine.search(fPattern, SearchUtils.getDefaultSearchParticipants(), fScope, getCollector(), new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); } catch (CoreException exception) { throw new JavaModelException(exception); } } finally { monitor.done(); } }
/** * Performs the search according to the specified pattern. * * @param monitor the progress monitor, or <code>null</code> * @throws JavaModelException if an error occurs during search */ public final void searchPattern(IProgressMonitor monitor) throws JavaModelException { Assert.isNotNull(fPattern); if (monitor == null) monitor= new NullProgressMonitor(); try { monitor.beginTask("", 1); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_occurrences); try { SearchEngine engine= null; if (fOwner != null) engine= new SearchEngine(fOwner); else engine= new SearchEngine(fWorkingCopies); engine.search(fPattern, SearchUtils.getDefaultSearchParticipants(), fScope, getCollector(), new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); } catch (CoreException exception) { throw new JavaModelException(exception); } } finally { monitor.done(); } }
/** * Performs the search according to the specified pattern. * * @param monitor the progress monitor, or <code>null</code> * @throws JavaModelException if an error occurs during search */ public final void searchPattern(final IProgressMonitor monitor) throws JavaModelException { Assert.isNotNull(fPattern); try { monitor.beginTask("", 1); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_occurrences); try { SearchEngine engine= null; if (fOwner != null) engine= new SearchEngine(fOwner); else engine= new SearchEngine(fWorkingCopies); engine.search(fPattern, SearchUtils.getDefaultSearchParticipants(), fScope, getCollector(), new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); } catch (CoreException exception) { throw new JavaModelException(exception); } } finally { monitor.done(); } }
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 (fBinaryRefs != null || ! (fExcludeBinaries && isBinary)) { fDeclarations.add(method); } if (isBinary && fBinaryRefs != null) { fDeclarationToMatch.put(method, match); } } } 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); SearchParticipant[] participants= SearchUtils.getDefaultSearchParticipants(); IJavaSearchScope scope= RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES); MethodRequestor requestor= new MethodRequestor(); SearchEngine searchEngine= owner != null ? new SearchEngine(owner) : new SearchEngine(); searchEngine.search(pattern, participants, scope, requestor, monitor); }
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 isVisible= JavaModelUtil.isVisibleInHierarchy(method, fMethod.getDeclaringType().getPackageFragment()); if (isVisible) { boolean isBinary= method.isBinary(); if (fBinaryRefs != null || ! (fExcludeBinaries && isBinary)) { fDeclarations.add(method); } if (isBinary && fBinaryRefs != null) { fDeclarationToMatch.put(method, match); } } } } 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); SearchParticipant[] participants= SearchUtils.getDefaultSearchParticipants(); IJavaSearchScope scope= RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES); MethodRequestor requestor= new MethodRequestor(); SearchEngine searchEngine= owner != null ? new SearchEngine(owner) : new SearchEngine(); searchEngine.search(pattern, participants, scope, requestor, monitor); }