Search in sources :

Example 1 with Entry

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

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

the class XMLSearchParticipant method locateMatches.

private void locateMatches(SearchPattern pattern, SearchDocument document, SearchRequestor requestor, Map searchOptions, IProgressMonitor monitor) {
    // 
    if (pattern.getMatchRule() == SearchPattern.R_PATTERN_MATCH) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(document.getPath()));
        // TODO.. don't assume the category is COMPONENT_DECL... handle any arbitarty category
        Entry[] entries = document.getEntries(IXMLSearchConstants.COMPONENT_DECL, null, 0);
        for (int i = 0; i < entries.length; i++) {
            // TODO.. don't assume this is just a component declaration entry
            ComponentDeclarationEntry entry = (ComponentDeclarationEntry) entries[i];
            SearchMatch searchMatch = new SearchMatch(null, 0, 0, file);
            // $NON-NLS-1$
            searchMatch.map.put("name", entry.getName());
            // $NON-NLS-1$
            searchMatch.map.put("metaName", entry.getMetaName());
            try {
                requestor.acceptSearchMatch(searchMatch);
            } catch (Exception e) {
            }
        }
    } else {
        if (document.getModel() instanceof IDOMModel) {
            IDOMModel domModel = (IDOMModel) document.getModel();
            IDOMElement contextNode = (IDOMElement) domModel.getDocument().getDocumentElement();
            DOMVisitor visitor = new DOMVisitor(document.getPath(), pattern, requestor);
            visitor.visit(contextNode);
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) 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) SearchMatch(org.eclipse.wst.common.core.search.SearchMatch) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ComponentDeclarationEntry(org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry) CoreException(org.eclipse.core.runtime.CoreException) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 3 with Entry

use of org.eclipse.wst.common.core.search.document.Entry 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)3 Entry (org.eclipse.wst.common.core.search.document.Entry)3 FileReferenceEntry (org.eclipse.wst.common.core.search.document.FileReferenceEntry)3 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 SearchDocument (org.eclipse.wst.common.core.search.document.SearchDocument)2 XMLSearchDocument (org.eclipse.wst.xml.core.internal.search.impl.XMLSearchDocument)2 Path (org.eclipse.core.runtime.Path)1 SearchMatch (org.eclipse.wst.common.core.search.SearchMatch)1 ComponentSearchPattern (org.eclipse.wst.common.core.search.pattern.ComponentSearchPattern)1 URIResolver (org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver)1 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1