Search in sources :

Example 1 with ComponentSearchPattern

use of org.eclipse.wst.common.core.search.pattern.ComponentSearchPattern in project webtools.sourceediting by eclipse.

the class XMLSearchParticipant method locateMatches.

public void locateMatches(SearchDocumentSet documentSet, SearchPattern pattern, SearchScope scope, SearchRequestor requestor, Map searchOptions, IProgressMonitor monitor) throws CoreException {
    long time = System.currentTimeMillis();
    // TODO: use the file reference entries in the documents to reduce the scope to the referenced files only
    // SearchDocument[] documents = documentSet.getSearchDocuments(id);
    // check to see if the search pattern is qualified by a file location
    // if this is the case then we can use file scoping rules to prune the matches
    IFile targetFile = null;
    if (pattern instanceof ComponentSearchPattern) {
        ComponentSearchPattern componentSearchPattern = (ComponentSearchPattern) pattern;
        targetFile = componentSearchPattern.getFile();
    }
    // here we should have in scope only referenced files
    IFile[] files = scope.enclosingFiles();
    for (int i = 0; i < files.length; i++) {
        IFile file = files[i];
        String path = file.getLocation().toString();
        SearchDocument document = documentSet.getSearchDocument(path, id);
        if (document != null) {
            Entry[] entries = document.getEntries(getSearchEntryCategory(pattern), null, 0);
            if ((entries != null && entries.length > 0) || (searchOptions != null && searchOptions.get("searchDirtyContent") != null)) {
                // for (int j = 0; j < entries.length; j++)
                // {
                // Entry entry = entries[j];
                // System.out.println("entry " + entry.getCategory() + " " + entry.getKey() + " " + entry.getClass().getName());
                // }
                boolean isInScope = true;
                if (targetFile != null) {
                    try {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        isInScope = isLinked(documentSet, "file:///" + path, "file:///" + targetFile.getLocation().toString());
                    // if (path.endsWith("CancelSelection.wsdl")  && path.indexOf("clone1") != -1)
                    // {
                    // fileReferenceTable.debug(qualifiedPath, 0, 5);
                    // }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (isInScope) {
                    this.locateMatches(pattern, document, requestor, searchOptions, monitor);
                }
            }
        }
    }
    if (debugPerf) {
        System.out.println(// $NON-NLS-1$
        "" + getDescription() + ": " + (System.currentTimeMillis() - time) + // $NON-NLS-1$ //$NON-NLS-2$
        "ms for locateMatches");
    }
}
Also used : Entry(org.eclipse.wst.common.core.search.document.Entry) ComponentDeclarationEntry(org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry) FileReferenceEntry(org.eclipse.wst.common.core.search.document.FileReferenceEntry) IFile(org.eclipse.core.resources.IFile) ComponentSearchPattern(org.eclipse.wst.common.core.search.pattern.ComponentSearchPattern) CoreException(org.eclipse.core.runtime.CoreException) XMLSearchDocument(org.eclipse.wst.xml.core.internal.search.impl.XMLSearchDocument) SearchDocument(org.eclipse.wst.common.core.search.document.SearchDocument)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 ComponentDeclarationEntry (org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry)1 Entry (org.eclipse.wst.common.core.search.document.Entry)1 FileReferenceEntry (org.eclipse.wst.common.core.search.document.FileReferenceEntry)1 SearchDocument (org.eclipse.wst.common.core.search.document.SearchDocument)1 ComponentSearchPattern (org.eclipse.wst.common.core.search.pattern.ComponentSearchPattern)1 XMLSearchDocument (org.eclipse.wst.xml.core.internal.search.impl.XMLSearchDocument)1