Search in sources :

Example 6 with IJavaSearchScope

use of org.eclipse.jdt.core.search.IJavaSearchScope in project che by eclipse.

the class IndexManager method cleanUpIndexes.

/*
     * Removes unused indexes from disk.
     */
public void cleanUpIndexes() {
    SimpleSet knownPaths = new SimpleSet();
    IJavaSearchScope scope = BasicSearchEngine.createWorkspaceScope();
    PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null);
    Index[] selectedIndexes = job.getIndexes(null);
    for (int i = 0, l = selectedIndexes.length; i < l; i++) {
        IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation();
        knownPaths.add(IndexLocation);
    }
    if (this.indexStates != null) {
        Object[] keys = this.indexStates.keyTable;
        IndexLocation[] locations = new IndexLocation[this.indexStates.elementSize];
        int count = 0;
        for (int i = 0, l = keys.length; i < l; i++) {
            IndexLocation key = (IndexLocation) keys[i];
            if (key != null && !knownPaths.includes(key))
                locations[count++] = key;
        }
        if (count > 0)
            removeIndexesState(locations);
    }
    deleteIndexFiles(knownPaths);
}
Also used : SimpleSet(org.eclipse.jdt.internal.compiler.util.SimpleSet) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) PatternSearchJob(org.eclipse.jdt.internal.core.search.PatternSearchJob) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) DiskIndex(org.eclipse.jdt.internal.core.index.DiskIndex) Index(org.eclipse.jdt.internal.core.index.Index)

Example 7 with IJavaSearchScope

use of org.eclipse.jdt.core.search.IJavaSearchScope in project che by eclipse.

the class IntroduceIndirectionRefactoring method getReferences.

private SearchResultGroup[] getReferences(IMethod[] methods, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
    SearchPattern pattern = RefactoringSearchEngine.createOrPattern(methods, IJavaSearchConstants.REFERENCES);
    IJavaSearchScope scope = RefactoringScopeFactory.create(fIntermediaryType, false);
    return RefactoringSearchEngine.search(pattern, scope, pm, status);
}
Also used : IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern)

Example 8 with IJavaSearchScope

use of org.eclipse.jdt.core.search.IJavaSearchScope in project che by eclipse.

the class CreateCopyOfCompilationUnitChange method getReferences.

private static SearchResultGroup getReferences(final ICompilationUnit copy, IProgressMonitor monitor) throws JavaModelException {
    final ICompilationUnit[] copies = new ICompilationUnit[] { copy };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(copies);
    final IType type = copy.findPrimaryType();
    if (type == null)
        return null;
    SearchPattern pattern = createSearchPattern(type);
    final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(pattern);
    engine.setScope(scope);
    engine.setWorkingCopies(copies);
    engine.setRequestor(new IRefactoringSearchRequestor() {

        TypeOccurrenceCollector fTypeOccurrenceCollector = new TypeOccurrenceCollector(type);

        public SearchMatch acceptSearchMatch(SearchMatch match) {
            try {
                return fTypeOccurrenceCollector.acceptSearchMatch2(copy, match);
            } catch (CoreException e) {
                JavaPlugin.log(e);
                return null;
            }
        }
    });
    engine.searchPattern(monitor);
    final Object[] results = engine.getResults();
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106127)
    for (int index = 0; index < results.length; index++) {
        SearchResultGroup group = (SearchResultGroup) results[index];
        if (group.getCompilationUnit().equals(copy))
            return group;
    }
    return null;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup) IType(org.eclipse.jdt.core.IType) IRefactoringSearchRequestor(org.eclipse.jdt.internal.corext.refactoring.IRefactoringSearchRequestor) CoreException(org.eclipse.core.runtime.CoreException) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) TypeOccurrenceCollector(org.eclipse.jdt.internal.corext.refactoring.rename.TypeOccurrenceCollector) RefactoringSearchEngine2(org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine2)

Example 9 with IJavaSearchScope

use of org.eclipse.jdt.core.search.IJavaSearchScope in project bndtools by bndtools.

the class ExportPatternsListPart method selectPackagesToAdd.

protected List<ExportedPackage> selectPackagesToAdd() {
    List<ExportedPackage> added = null;
    final IPackageFilter filter = new IPackageFilter() {

        @Override
        public boolean select(String packageName) {
            if (packageName.equals("java") || packageName.startsWith("java."))
                return false;
            return true;
        }
    };
    IFormPage page = (IFormPage) getManagedForm().getContainer();
    IWorkbenchWindow window = page.getEditorSite().getWorkbenchWindow();
    // Prepare the package lister from the Java project
    IProject project = ResourceUtil.getResource(page.getEditorInput()).getProject();
    IJavaProject javaProject = JavaCore.create(project);
    IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
    JavaSearchScopePackageLister packageLister = new JavaSearchScopePackageLister(searchScope, window);
    // Create and open the dialog
    PackageSelectionDialog dialog = new PackageSelectionDialog(window.getShell(), packageLister, filter, "Select new packages to export from the bundle.");
    dialog.setSourceOnly(true);
    dialog.setMultipleSelection(true);
    if (dialog.open() == Window.OK) {
        Object[] results = dialog.getResult();
        added = new LinkedList<ExportedPackage>();
        // Select the results
        for (Object result : results) {
            String newPackageName = (String) result;
            ExportedPackage newPackage = new ExportedPackage(newPackageName, new Attrs());
            added.add(newPackage);
        }
    }
    return added;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Attrs(aQute.bnd.header.Attrs) IFormPage(org.eclipse.ui.forms.editor.IFormPage) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) JavaSearchScopePackageLister(bndtools.internal.pkgselection.JavaSearchScopePackageLister) IPackageFilter(bndtools.internal.pkgselection.IPackageFilter) PackageSelectionDialog(bndtools.internal.pkgselection.PackageSelectionDialog)

Example 10 with IJavaSearchScope

use of org.eclipse.jdt.core.search.IJavaSearchScope in project bndtools by bndtools.

the class NewTypeWizardPage method chooseSuperClass.

/**
     * Opens a selection dialog that allows to select a super class.
     *
     * @return returns the selected type or <code>null</code> if the dialog has been canceled. The caller typically sets
     *         the result to the super class input field.
     *         <p>
     *         Clients can override this method if they want to offer a different dialog.
     *         </p>
     * @since 3.2
     */
protected IType chooseSuperClass() {
    IJavaProject project = getJavaProject();
    if (project == null) {
        return null;
    }
    IJavaElement[] elements = new IJavaElement[] { project };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);
    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false, getWizard().getContainer(), scope, IJavaSearchConstants.CLASS);
    dialog.setTitle(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_title);
    dialog.setMessage(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_message);
    dialog.setInitialPattern(getSuperClass());
    if (dialog.open() == Window.OK) {
        return (IType) dialog.getFirstResult();
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) FilteredTypesSelectionDialog(org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog) IType(org.eclipse.jdt.core.IType)

Aggregations

IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)20 SearchPattern (org.eclipse.jdt.core.search.SearchPattern)12 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)8 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)6 IJavaProject (org.eclipse.jdt.core.IJavaProject)5 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)5 SearchResultGroup (org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)5 HashSet (java.util.HashSet)4 CoreException (org.eclipse.core.runtime.CoreException)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 IType (org.eclipse.jdt.core.IType)4 ArrayList (java.util.ArrayList)3 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)3 SearchRequestor (org.eclipse.jdt.core.search.SearchRequestor)3 RefactoringSearchEngine (org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine)3 IPackageFilter (bndtools.internal.pkgselection.IPackageFilter)2 JavaSearchScopePackageLister (bndtools.internal.pkgselection.JavaSearchScopePackageLister)2 PackageSelectionDialog (bndtools.internal.pkgselection.PackageSelectionDialog)2 LinkedList (java.util.LinkedList)2 IMethod (org.eclipse.jdt.core.IMethod)2