Search in sources :

Example 1 with SearchDocument

use of org.eclipse.wst.common.core.search.document.SearchDocument in project webtools.sourceediting by eclipse.

the class XMLSearchParticipant method isLinked.

private boolean isLinked(SearchDocumentSet set, String source, String target, HashMap visited) {
    if (source.equals(target))
        return true;
    // $NON-NLS-1$
    String fileProtocol = "file:///";
    // Fix for bug 204174 - Begin
    if (// $NON-NLS-1$
    target.charAt(fileProtocol.length()) == '/') {
        target = fileProtocol + target.substring(fileProtocol.length() + 1);
    }
    if (source.startsWith(fileProtocol)) {
        SearchDocument document = set._tempGetSearchDocumetn(source.substring(fileProtocol.length()));
        if (document != null) {
            URIResolver uriResolver = URIResolverPlugin.createResolver();
            Entry[] entries = document.getEntries(IXMLSearchConstants.REF, null, 0);
            String[] resolveEntry = new String[entries.length];
            for (int j = 0; j < entries.length; j++) {
                Entry entry = entries[j];
                if (entry instanceof FileReferenceEntry) {
                    FileReferenceEntry fileReferenceEntry = (FileReferenceEntry) entry;
                    // 
                    if (fileReferenceEntry.getRelativeFilePath() != null) {
                        String resolvedURI = uriResolver.resolve(source, null, fileReferenceEntry.getRelativeFilePath());
                        resolveEntry[j] = resolvedURI;
                        if (resolvedURI.equals(target)) {
                            return true;
                        }
                    }
                }
            }
            // we keep track of the nodes we've already visited to avoid cycles
            if (visited.get(source) == null) {
                visited.put(source, Boolean.TRUE);
                for (int j = 0; j < entries.length; j++) {
                    String resolvedURI = resolveEntry[j];
                    if (resolvedURI != null && isLinked(set, resolveEntry[j], target, visited))
                        return true;
                }
            }
        }
    }
    return false;
}
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) FileReferenceEntry(org.eclipse.wst.common.core.search.document.FileReferenceEntry) URIResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver) XMLSearchDocument(org.eclipse.wst.xml.core.internal.search.impl.XMLSearchDocument) SearchDocument(org.eclipse.wst.common.core.search.document.SearchDocument)

Example 2 with SearchDocument

use of org.eclipse.wst.common.core.search.document.SearchDocument 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

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