Example usage for org.eclipse.jdt.internal.core Openable getJavaProject

List of usage examples for org.eclipse.jdt.internal.core Openable getJavaProject

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core Openable getJavaProject.

Prototype

@Override
public IJavaProject getJavaProject() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

/**
 * Locate the matches in the given files and report them using the search requestor.
 *///  w w  w  .j ava2  s  .c om
public void locateMatches(SearchDocument[] searchDocuments) throws CoreException {
    if (this.patternLocator == null)
        return;
    int docsLength = searchDocuments.length;
    int progressLength = docsLength;
    if (BasicSearchEngine.VERBOSE) {
        System.out.println("Locating matches in documents ["); //$NON-NLS-1$
        for (int i = 0; i < docsLength; i++)
            System.out.println("\t" + searchDocuments[i]); //$NON-NLS-1$
        System.out.println("]"); //$NON-NLS-1$
    }
    IJavaProject[] javaModelProjects = null;
    if (this.searchPackageDeclaration) {
        javaModelProjects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
        progressLength += javaModelProjects.length;
    }

    // init infos for progress increasing
    int n = progressLength < 1000 ? Math.min(Math.max(progressLength / 200 + 1, 2), 4)
            : 5 * (progressLength / 1000);
    this.progressStep = progressLength < n ? 1 : progressLength / n; // step should not be 0
    this.progressWorked = 0;

    // extract working copies
    ArrayList copies = new ArrayList();
    for (int i = 0; i < docsLength; i++) {
        SearchDocument document = searchDocuments[i];
        if (document instanceof WorkingCopyDocument) {
            copies.add(((WorkingCopyDocument) document).workingCopy);
        }
    }
    int copiesLength = copies.size();
    this.workingCopies = new org.eclipse.jdt.core.ICompilationUnit[copiesLength];
    copies.toArray(this.workingCopies);

    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    this.bindings = new SimpleLookupTable();
    try {
        // optimize access to zip files during search operation
        manager.cacheZipFiles(this);

        // initialize handle factory (used as a cache of handles so as to optimize space)
        if (this.handleFactory == null)
            this.handleFactory = new HandleFactory();

        if (this.progressMonitor != null) {
            this.progressMonitor.beginTask("", searchDocuments.length); //$NON-NLS-1$
        }

        // initialize pattern for polymorphic search (i.e. method reference pattern)
        this.patternLocator.initializePolymorphicSearch(this);

        JavaProject previousJavaProject = null;
        PossibleMatchSet matchSet = new PossibleMatchSet();
        Util.sort(searchDocuments, new Util.Comparer() {
            public int compare(Object a, Object b) {
                return ((SearchDocument) a).getPath().compareTo(((SearchDocument) b).getPath());
            }
        });
        int displayed = 0; // progress worked displayed
        String previousPath = null;
        SearchParticipant searchParticipant = null;
        for (int i = 0; i < docsLength; i++) {
            if (this.progressMonitor != null && this.progressMonitor.isCanceled()) {
                throw new OperationCanceledException();
            }

            // skip duplicate paths
            SearchDocument searchDocument = searchDocuments[i];
            if (searchParticipant == null) {
                searchParticipant = searchDocument.getParticipant();
            }
            searchDocuments[i] = null; // free current document
            String pathString = searchDocument.getPath();
            if (i > 0 && pathString.equals(previousPath)) {
                if (this.progressMonitor != null) {
                    this.progressWorked++;
                    if ((this.progressWorked % this.progressStep) == 0)
                        this.progressMonitor.worked(this.progressStep);
                }
                displayed++;
                continue;
            }
            previousPath = pathString;

            Openable openable;
            org.eclipse.jdt.core.ICompilationUnit workingCopy = null;
            if (searchDocument instanceof WorkingCopyDocument) {
                workingCopy = ((WorkingCopyDocument) searchDocument).workingCopy;
                openable = (Openable) workingCopy;
            } else {
                openable = this.handleFactory.createOpenable(pathString, this.scope);
            }
            //         if (openable == null) {
            //            if (this.progressMonitor != null) {
            //               this.progressWorked++;
            //               if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep);
            //            }
            //            displayed++;
            //            continue; // match is outside classpath
            //         }

            // create new parser and lookup environment if this is a new project
            IResource resource = null;
            JavaProject javaProject = (JavaProject) openable.getJavaProject();
            resource = workingCopy != null ? workingCopy.getResource() : openable.getResource();
            if (resource == null)
                resource = javaProject.getProject(); // case of a file in an external jar or external folder
            if (!javaProject.equals(previousJavaProject)) {
                // locate matches in previous project
                if (previousJavaProject != null) {
                    try {
                        locateMatches(previousJavaProject, matchSet, i - displayed);
                        displayed = i;
                    } catch (JavaModelException e) {
                        // problem with classpath in this project -> skip it
                    }
                    matchSet.reset();
                }
                previousJavaProject = javaProject;
            }
            matchSet.add(new PossibleMatch(this, resource, openable, searchDocument, this.pattern.mustResolve));
        }

        // last project
        if (previousJavaProject != null) {
            try {
                locateMatches(previousJavaProject, matchSet, docsLength - displayed);
            } catch (JavaModelException e) {
                // problem with classpath in last project -> ignore
            }
        }

        if (this.searchPackageDeclaration) {
            locatePackageDeclarations(searchParticipant, javaModelProjects);
        }

    } finally {
        if (this.progressMonitor != null)
            this.progressMonitor.done();
        if (this.nameEnvironment != null)
            this.nameEnvironment.cleanup();
        manager.flushZipFiles(this);
        this.bindings = null;
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.SuperTypeNamesCollector.java

License:Open Source License

public char[][][] collect() throws JavaModelException {
    if (this.type != null) {
        // Collect the paths of the cus that are in the hierarchy of the given type
        this.result = new char[1][][];
        this.resultIndex = 0;
        JavaProject javaProject = (JavaProject) this.type.getJavaProject();
        this.locator.initialize(javaProject, 0);
        try {//from   w w  w.  ja v a 2 s  .  c om
            if (this.type.isBinary()) {
                BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null);
                if (binding != null)
                    collectSuperTypeNames(binding, null);
            } else {
                ICompilationUnit unit = this.type.getCompilationUnit();
                SourceType sourceType = (SourceType) this.type;
                boolean isTopLevelOrMember = sourceType.getOuterMostLocalContext() == null;
                CompilationUnitDeclaration parsedUnit = buildBindings(unit, isTopLevelOrMember);
                if (parsedUnit != null) {
                    TypeDeclaration typeDecl = new ASTNodeFinder(parsedUnit).findType(this.type);
                    if (typeDecl != null && typeDecl.binding != null)
                        collectSuperTypeNames(typeDecl.binding, null);
                }
            }
        } catch (AbortCompilation e) {
            // problem with classpath: report inaccurate matches
            return null;
        }
        if (this.result.length > this.resultIndex)
            System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex);
        return this.result;
    }

    // Collect the paths of the cus that declare a type which matches declaringQualification + declaringSimpleName
    String[] paths = getPathsOfDeclaringType();
    if (paths == null)
        return null;

    // Create bindings from source types and binary types and collect super type names of the type declaration
    // that match the given declaring type
    Util.sort(paths); // sort by projects
    JavaProject previousProject = null;
    this.result = new char[1][][];
    this.samePackageSuperTypeName = new char[1][][];
    this.resultIndex = 0;
    for (int i = 0, length = paths.length; i < length; i++) {
        try {
            //todo Openable
            Openable openable = null;//this.locator.handleFactory.createOpenable(paths[i], this.locator.scope);
            if (openable == null)
                continue; // outside classpath

            IJavaProject project = openable.getJavaProject();
            if (!project.equals(previousProject)) {
                previousProject = (JavaProject) project;
                this.locator.initialize(previousProject, 0);
            }
            if (openable instanceof ICompilationUnit) {
                ICompilationUnit unit = (ICompilationUnit) openable;
                CompilationUnitDeclaration parsedUnit = buildBindings(unit,
                        true /*only top level and member types are visible to the focus type*/);
                if (parsedUnit != null)
                    parsedUnit.traverse(new TypeDeclarationVisitor(), parsedUnit.scope);
            } else if (openable instanceof IClassFile) {
                IClassFile classFile = (IClassFile) openable;
                BinaryTypeBinding binding = this.locator.cacheBinaryType(classFile.getType(), null);
                if (matches(binding))
                    collectSuperTypeNames(binding, binding.compoundName);
            }
        } catch (AbortCompilation e) {
            // ignore: continue with next element
        } catch (JavaModelException e) {
            // ignore: continue with next element
        }
    }
    if (this.result.length > this.resultIndex)
        System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex);
    return this.result;
}

From source file:org.eclipse.ajdt.internal.core.contentassist.ContentAssistProvider.java

License:Open Source License

public boolean doContentAssist(ICompilationUnit cu, ICompilationUnit unitToSkip, int position,
        CompletionRequestor requestor, WorkingCopyOwner owner,
        /* AJDT 1.7 */
        ITypeRoot typeRoot, Openable target, IProgressMonitor monitor) throws Exception {
    JavaProject project = (JavaProject) target.getJavaProject();
    if (!AspectJPlugin.isAJProject(project.getProject())) {
        return false;
    }//w  w  w  . j a  va 2 s. c  o  m
    if (target instanceof AJCompilationUnit) {
        // already handled by the compilation unit
        return false;
    }
    if (!(target instanceof CompilationUnit)) {
        return false;
    }
    IBuffer buffer = target.getBuffer();
    if (buffer == null) {
        return false;
    }

    if (requestor == null) {
        throw new IllegalArgumentException("Completion requestor cannot be null"); //$NON-NLS-1$
    }

    MockCompilationUnit mcu = new MockCompilationUnit((CompilationUnit) target);
    ProposalRequestorWrapper wrapped = new ProposalRequestorWrapper(requestor, mcu, mcu.insertionTable);
    int transformedPos = mcu.translatePositionToFake(position);
    if (transformedPos < -1 || transformedPos > mcu.getContents().length) {
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS));
    }

    /* AJDT 1.7 */
    ITDAwareNameEnvironment environment = new ITDAwareNameEnvironment(project, owner, monitor);
    environment.setUnitToSkip(unitToSkip);

    // code complete
    /* AJDT 1.7 */
    CompletionEngine engine = new CompletionEngine(environment, wrapped, project.getOptions(true), project,
            owner, monitor);
    engine.lookupEnvironment = new ITDAwareLookupEnvironment(engine.lookupEnvironment, environment);
    engine.complete(mcu, transformedPos, 0, typeRoot);

    return true;
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

/**
* Locate the matches in the given files and report them using the search requestor.
*//*from ww w. ja  v a2s .  c om*/
public void locateMatches(SearchDocument[] searchDocuments) throws CoreException {
    if (this.patternLocator == null)
        return;
    int docsLength = searchDocuments.length;
    int progressLength = docsLength;
    if (BasicSearchEngine.VERBOSE) {
        System.out.println("Locating matches in documents ["); //$NON-NLS-1$
        for (int i = 0; i < docsLength; i++)
            System.out.println("\t" + searchDocuments[i]); //$NON-NLS-1$
        System.out.println("]"); //$NON-NLS-1$
    }
    IJavaProject[] javaModelProjects = null;
    if (this.searchPackageDeclaration) {
        javaModelProjects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
        progressLength += javaModelProjects.length;
    }

    // init infos for progress increasing
    int n = progressLength < 1000 ? Math.min(Math.max(progressLength / 200 + 1, 2), 4)
            : 5 * (progressLength / 1000);
    this.progressStep = progressLength < n ? 1 : progressLength / n; // step should not be 0
    this.progressWorked = 0;

    // extract working copies
    ArrayList copies = new ArrayList();
    for (int i = 0; i < docsLength; i++) {
        SearchDocument document = searchDocuments[i];
        if (document instanceof WorkingCopyDocument) {
            copies.add(((WorkingCopyDocument) document).workingCopy);
        }
    }
    int copiesLength = copies.size();
    this.workingCopies = new org.eclipse.jdt.core.ICompilationUnit[copiesLength];
    copies.toArray(this.workingCopies);

    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    this.bindings = new SimpleLookupTable();
    try {
        // optimize access to zip files during search operation
        manager.cacheZipFiles(this);

        // initialize handle factory (used as a cache of handles so as to optimize space)
        if (this.handleFactory == null)
            this.handleFactory = new HandleFactory();

        if (this.progressMonitor != null) {
            this.progressMonitor.beginTask("", searchDocuments.length); //$NON-NLS-1$
        }

        // initialize pattern for polymorphic search (i.e. method reference pattern)
        this.patternLocator.initializePolymorphicSearch(this);

        JavaProject previousJavaProject = null;
        PossibleMatchSet matchSet = new PossibleMatchSet();
        Util.sort(searchDocuments, new Util.Comparer() {
            public int compare(Object a, Object b) {
                return ((SearchDocument) a).getPath().compareTo(((SearchDocument) b).getPath());
            }
        });
        int displayed = 0; // progress worked displayed
        String previousPath = null;
        SearchParticipant searchParticipant = null;
        for (int i = 0; i < docsLength; i++) {
            if (this.progressMonitor != null && this.progressMonitor.isCanceled()) {
                throw new OperationCanceledException();
            }

            // skip duplicate paths
            SearchDocument searchDocument = searchDocuments[i];
            if (searchParticipant == null) {
                searchParticipant = searchDocument.getParticipant();
            }
            searchDocuments[i] = null; // free current document
            String pathString = searchDocument.getPath();
            if (i > 0 && pathString.equals(previousPath)) {
                if (this.progressMonitor != null) {
                    this.progressWorked++;
                    if ((this.progressWorked % this.progressStep) == 0)
                        this.progressMonitor.worked(this.progressStep);
                }
                displayed++;
                continue;
            }
            previousPath = pathString;

            Openable openable;
            org.eclipse.jdt.core.ICompilationUnit workingCopy = null;
            if (searchDocument instanceof WorkingCopyDocument) {
                workingCopy = ((WorkingCopyDocument) searchDocument).workingCopy;
                openable = (Openable) workingCopy;
            } else {
                openable = this.handleFactory.createOpenable(pathString, this.scope);
            }
            if (openable == null) {
                if (this.progressMonitor != null) {
                    this.progressWorked++;
                    if ((this.progressWorked % this.progressStep) == 0)
                        this.progressMonitor.worked(this.progressStep);
                }
                displayed++;
                continue; // match is outside classpath
            }

            // create new parser and lookup environment if this is a new project
            IResource resource = null;
            JavaProject javaProject = (JavaProject) openable.getJavaProject();
            resource = workingCopy != null ? workingCopy.getResource() : openable.getResource();
            if (resource == null)
                resource = javaProject.getProject(); // case of a file in an external jar or external folder
            if (!javaProject.equals(previousJavaProject)) {
                // locate matches in previous project
                if (previousJavaProject != null) {
                    try {
                        locateMatches(previousJavaProject, matchSet, i - displayed);
                        displayed = i;
                    } catch (JavaModelException e) {
                        // problem with classpath in this project -> skip it
                    }
                    matchSet.reset();
                }
                previousJavaProject = javaProject;
            }
            matchSet.add(new PossibleMatch(this, resource, openable, searchDocument, this.pattern.mustResolve));
        }

        // last project
        if (previousJavaProject != null) {
            try {
                locateMatches(previousJavaProject, matchSet, docsLength - displayed);
            } catch (JavaModelException e) {
                // problem with classpath in last project -> ignore
            }
        }

        if (this.searchPackageDeclaration) {
            locatePackageDeclarations(searchParticipant, javaModelProjects);
        }

    } finally {
        if (this.progressMonitor != null)
            this.progressMonitor.done();
        if (this.nameEnvironment != null)
            this.nameEnvironment.cleanup();
        this.unitScope = null;
        manager.flushZipFiles(this);
        this.bindings = null;
    }
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.SuperTypeNamesCollector.java

License:Open Source License

public char[][][] collect() throws JavaModelException {
    if (this.type != null) {
        // Collect the paths of the cus that are in the hierarchy of the given type
        this.result = new char[1][][];
        this.resultIndex = 0;
        JavaProject javaProject = (JavaProject) this.type.getJavaProject();
        this.locator.initialize(javaProject, 0);
        try {/*from   w w  w  . j  a v  a2  s .  c o m*/
            if (this.type.isBinary()) {
                BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null);
                if (binding != null)
                    collectSuperTypeNames(binding, null);
            } else {
                ICompilationUnit unit = this.type.getCompilationUnit();
                SourceType sourceType = (SourceType) this.type;
                boolean isTopLevelOrMember = sourceType.getOuterMostLocalContext() == null;
                CompilationUnitDeclaration parsedUnit = buildBindings(unit, isTopLevelOrMember);
                if (parsedUnit != null) {
                    TypeDeclaration typeDecl = new ASTNodeFinder(parsedUnit).findType(this.type);
                    if (typeDecl != null && typeDecl.binding != null)
                        collectSuperTypeNames(typeDecl.binding, null);
                }
            }
        } catch (AbortCompilation e) {
            // problem with classpath: report inaccurate matches
            return null;
        }
        if (this.result.length > this.resultIndex)
            System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex);
        return this.result;
    }

    // Collect the paths of the cus that declare a type which matches declaringQualification + declaringSimpleName
    String[] paths = getPathsOfDeclaringType();
    if (paths == null)
        return null;

    // Create bindings from source types and binary types and collect super type names of the type declaration
    // that match the given declaring type
    Util.sort(paths); // sort by projects
    JavaProject previousProject = null;
    this.result = new char[1][][];
    this.samePackageSuperTypeName = new char[1][][];
    this.resultIndex = 0;
    for (int i = 0, length = paths.length; i < length; i++) {
        try {
            Openable openable = this.locator.handleFactory.createOpenable(paths[i], this.locator.scope);
            if (openable == null)
                continue; // outside classpath

            IJavaProject project = openable.getJavaProject();
            if (!project.equals(previousProject)) {
                previousProject = (JavaProject) project;
                this.locator.initialize(previousProject, 0);
            }
            if (openable instanceof ICompilationUnit) {
                ICompilationUnit unit = (ICompilationUnit) openable;
                CompilationUnitDeclaration parsedUnit = buildBindings(unit,
                        true /*only top level and member types are visible to the focus type*/);
                if (parsedUnit != null)
                    parsedUnit.traverse(new TypeDeclarationVisitor(), parsedUnit.scope);
            } else if (openable instanceof IClassFile) {
                IClassFile classFile = (IClassFile) openable;
                BinaryTypeBinding binding = this.locator.cacheBinaryType(classFile.getType(), null);
                if (matches(binding))
                    collectSuperTypeNames(binding, binding.compoundName);
            }
        } catch (AbortCompilation e) {
            // ignore: continue with next element
        } catch (JavaModelException e) {
            // ignore: continue with next element
        }
    }
    if (this.result.length > this.resultIndex)
        System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex);
    return this.result;
}

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

/**
 * Locate the matches in the given files and report them using the search requestor.
 *//*from w  w w  .  ja v a 2s  . c  o m*/
public void locateMatches(SearchDocument[] searchDocuments) throws CoreException {
    if (this.patternLocator == null)
        return;
    int docsLength = searchDocuments.length;
    int progressLength = docsLength;
    if (BasicSearchEngine.VERBOSE) {
        System.out.println("Locating matches in documents ["); //$NON-NLS-1$
        for (int i = 0; i < docsLength; i++)
            System.out.println("\t" + searchDocuments[i]); //$NON-NLS-1$
        System.out.println("]"); //$NON-NLS-1$
    }
    IJavaProject[] javaModelProjects = null;
    if (this.searchPackageDeclaration) {
        javaModelProjects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
        progressLength += javaModelProjects.length;
    }

    // init infos for progress increasing
    int n = progressLength < 1000 ? Math.min(Math.max(progressLength / 200 + 1, 2), 4)
            : 5 * (progressLength / 1000);
    this.progressStep = progressLength < n ? 1 : progressLength / n; // step should not be 0
    this.progressWorked = 0;

    // extract working copies
    ArrayList copies = new ArrayList();
    for (int i = 0; i < docsLength; i++) {
        SearchDocument document = searchDocuments[i];
        if (document instanceof WorkingCopyDocument) {
            copies.add(((WorkingCopyDocument) document).workingCopy);
        }
    }
    int copiesLength = copies.size();
    this.workingCopies = new org.eclipse.jdt.core.ICompilationUnit[copiesLength];
    copies.toArray(this.workingCopies);

    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    this.bindings = new SimpleLookupTable();
    try {
        // optimize access to zip files during search operation
        manager.cacheZipFiles(this);

        // initialize handle factory (used as a cache of handles so as to optimize space)
        if (this.handleFactory == null)
            this.handleFactory = new HandleFactory();

        if (this.progressMonitor != null) {
            this.progressMonitor.beginTask("", searchDocuments.length); //$NON-NLS-1$
        }

        // initialize pattern for polymorphic search (i.e. method reference pattern)
        this.patternLocator.initializePolymorphicSearch(this);

        JavaProject previousJavaProject = null;
        PossibleMatchSet matchSet = new PossibleMatchSet();
        Util.sort(searchDocuments, new Util.Comparer() {
            public int compare(Object a, Object b) {
                return ((SearchDocument) a).getPath().compareTo(((SearchDocument) b).getPath());
            }
        });
        int displayed = 0; // progress worked displayed
        String previousPath = null;
        SearchParticipant searchParticipant = null;
        for (int i = 0; i < docsLength; i++) {
            if (this.progressMonitor != null && this.progressMonitor.isCanceled()) {
                throw new OperationCanceledException();
            }

            // skip duplicate paths
            SearchDocument searchDocument = searchDocuments[i];
            if (searchParticipant == null) {
                searchParticipant = searchDocument.getParticipant();
            }
            searchDocuments[i] = null; // free current document
            String pathString = searchDocument.getPath();
            if (i > 0 && pathString.equals(previousPath)) {
                if (this.progressMonitor != null) {
                    this.progressWorked++;
                    if ((this.progressWorked % this.progressStep) == 0)
                        this.progressMonitor.worked(this.progressStep);
                }
                displayed++;
                continue;
            }
            previousPath = pathString;

            Openable openable;
            org.eclipse.jdt.core.ICompilationUnit workingCopy = null;
            if (searchDocument instanceof WorkingCopyDocument) {
                workingCopy = ((WorkingCopyDocument) searchDocument).workingCopy;
                openable = (Openable) workingCopy;
            } else {
                openable = this.handleFactory.createOpenable(pathString, this.scope);
            }
            if (openable == null) {
                if (this.progressMonitor != null) {
                    this.progressWorked++;
                    if ((this.progressWorked % this.progressStep) == 0)
                        this.progressMonitor.worked(this.progressStep);
                }
                displayed++;
                continue; // match is outside classpath
            }

            // create new parser and lookup environment if this is a new project
            IResource resource = null;
            JavaProject javaProject = (JavaProject) openable.getJavaProject();
            resource = workingCopy != null ? workingCopy.getResource() : openable.getResource();
            if (resource == null)
                resource = javaProject.getProject(); // case of a file in an external jar or external folder
            if (!javaProject.equals(previousJavaProject)) {
                // locate matches in previous project
                if (previousJavaProject != null) {
                    try {
                        locateMatches(previousJavaProject, matchSet, i - displayed);
                        displayed = i;
                    } catch (JavaModelException e) {
                        // problem with classpath in this project -> skip it
                    }
                    matchSet.reset();
                }
                previousJavaProject = javaProject;
            }
            matchSet.add(new PossibleMatch(this, resource, openable, searchDocument, this.pattern.mustResolve));
        }

        // last project
        if (previousJavaProject != null) {
            try {
                locateMatches(previousJavaProject, matchSet, docsLength - displayed);
            } catch (JavaModelException e) {
                // problem with classpath in last project -> ignore
            }
        }

        if (this.searchPackageDeclaration) {
            locatePackageDeclarations(searchParticipant, javaModelProjects);
        }

    } finally {
        if (this.progressMonitor != null)
            this.progressMonitor.done();
        if (this.nameEnvironment != null)
            this.nameEnvironment.cleanup();
        manager.flushZipFiles(this);
        this.bindings = null;
    }
}