Search in sources :

Example 1 with XMLComponentDeclarationPattern

use of org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern in project webtools.sourceediting by eclipse.

the class XSDSearchListProvider method findMatches.

protected void findMatches(SearchEngine searchEngine, SearchRequestor requestor, SearchScope scope, QualifiedName metaName) {
    try {
        XMLComponentDeclarationPattern pattern = new XMLComponentDeclarationPattern(new QualifiedName("*", "*"), metaName, SearchPattern.R_PATTERN_MATCH);
        // TODO (cs) revist this... we shouldn't be needing to hard-code partipant id's
        // All we're really doing here is trying to avoid finding matches in
        // wsdl's since we don't  ever want to import/include a wsdl from a schema!
        // Maybe we should just scope out any file types that aren't xsd's using a
        // custom SearchScope?
        // 
        SearchParticipant particpant = SearchPlugin.getDefault().getSearchParticipant("org.eclipse.wst.xsd.search.XSDSearchParticipant");
        Assert.isNotNull(particpant);
        SearchParticipant[] participants = { particpant };
        searchEngine.search(pattern, requestor, participants, scope, null, new NullProgressMonitor());
    } catch (CoreException e) {
        e.printStackTrace();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) XMLComponentDeclarationPattern(org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern) SearchParticipant(org.eclipse.wst.common.core.search.SearchParticipant)

Example 2 with XMLComponentDeclarationPattern

use of org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern in project webtools.sourceediting by eclipse.

the class RenameComponentProcessor method addDeclarationUpdate.

final void addDeclarationUpdate(TextChangeManager manager, IFile file) throws CoreException {
    String componentName = selectedComponent.getName();
    String componentNamespace = selectedComponent.getNamespaceURI();
    QualifiedName elementQName = new QualifiedName(componentNamespace, componentName);
    QualifiedName typeQName = selectedComponent.getTypeQName();
    SearchScope scope = new WorkspaceSearchScope();
    if (file != null) {
        scope = new SelectionSearchScope(new IResource[] { file });
    }
    CollectingSearchRequestor requestor = new CollectingSearchRequestor();
    SearchPattern pattern = new XMLComponentDeclarationPattern(file, elementQName, typeQName);
    SearchEngine searchEngine = new SearchEngine();
    HashMap map = new HashMap();
    if (singleFileOnly) {
        map.put("searchDirtyContent", Boolean.TRUE);
    }
    searchEngine.search(pattern, requestor, scope, map, new NullProgressMonitor());
    List results = requestor.getResults();
    // more than one declaration found, so use offset as additional check
    Position offsetPosition = null;
    if (results.size() > 1) {
        IDOMElement selectedElement = selectedComponent.getElement();
        if (selectedElement != null) {
            int startOffset = selectedElement.getStartOffset();
            offsetPosition = new Position(startOffset, (selectedElement.getEndOffset() - startOffset));
        }
    }
    for (Iterator iter = results.iterator(); iter.hasNext(); ) {
        SearchMatch match = (SearchMatch) iter.next();
        if (match != null) {
            boolean addTextChange = true;
            // additional check to verify correct declaration is changed
            if (offsetPosition != null) {
                addTextChange = offsetPosition.overlapsWith(match.getOffset(), match.getLength());
            }
            if (addTextChange) {
                TextChange textChange = manager.get(match.getFile());
                String newName = getNewElementName();
                newName = quoteString(newName);
                ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(), match.getLength(), newName);
                String editName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_declatation");
                TextChangeCompatibility.addTextEdit(textChange, editName, replaceEdit);
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SearchMatch(org.eclipse.wst.common.core.search.SearchMatch) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) SelectionSearchScope(org.eclipse.wst.common.core.search.scope.SelectionSearchScope) TextChange(org.eclipse.ltk.core.refactoring.TextChange) WorkspaceSearchScope(org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) SearchEngine(org.eclipse.wst.common.core.search.SearchEngine) SearchScope(org.eclipse.wst.common.core.search.scope.SearchScope) SelectionSearchScope(org.eclipse.wst.common.core.search.scope.SelectionSearchScope) WorkspaceSearchScope(org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope) SearchPattern(org.eclipse.wst.common.core.search.pattern.SearchPattern) Iterator(java.util.Iterator) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) ArrayList(java.util.ArrayList) List(java.util.List) CollectingSearchRequestor(org.eclipse.wst.common.core.search.util.CollectingSearchRequestor) XMLComponentDeclarationPattern(org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern) IResource(org.eclipse.core.resources.IResource)

Example 3 with XMLComponentDeclarationPattern

use of org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern in project webtools.sourceediting by eclipse.

the class XMLQuickScanContentHandler method startElement.

public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    // Search for targetNamespace if we haven't encountered it yet.
    if (// $NON-NLS-1$
    targetNamespace.equals("")) {
        int nAttributes = attributes.getLength();
        for (int i = 0; i < nAttributes; i++) {
            if (// $NON-NLS-1$
            "targetNamespace".equals(attributes.getQName(i))) {
                targetNamespace = attributes.getValue(i);
                break;
            }
        }
    }
    if ("import".equals(localName) && namespaceMatches(uri)) {
        // $NON-NLS-1$
        FileReferenceEntry documentEntry = new FileReferenceEntry();
        documentEntry.setCategory(IXMLSearchConstants.REF);
        // $NON-NLS-1$
        documentEntry.setKey("import");
        // $NON-NLS-1$
        String namespace = attributes.getValue("namespace");
        // $NON-NLS-1$
        String location = attributes.getValue(getLocationAttributeName(uri));
        documentEntry.setPublicIdentifier(namespace);
        documentEntry.setRelativeFilePath(location);
        document.putEntry(documentEntry);
    }
    if (// $NON-NLS-1$ //$NON-NLS-2$
    ("redefine".equals(localName) || "include".equals(localName)) && namespaceMatches(uri)) {
        FileReferenceEntry documentEntry = new FileReferenceEntry();
        documentEntry.setCategory(IXMLSearchConstants.REF);
        // $NON-NLS-1$
        documentEntry.setKey("include");
        // $NON-NLS-1$
        String location = attributes.getValue(getLocationAttributeName(uri));
        documentEntry.setPublicIdentifier(uri);
        documentEntry.setRelativeFilePath(location);
        document.putEntry(documentEntry);
    }
    // issue (cs) you may want to try perf measurements to compate reusing the same
    // instance of a SAXSearchElement instead of newing one each time
    // XMLSearchPattern.SAXSearchElement searchElement = new XMLSearchPattern.SAXSearchElement();
    searchElement.setElementName(localName);
    searchElement.setElementNamespace(uri);
    searchElement.setAttributes(attributes);
    searchElement.setNamespaceMap(namespaceMap);
    searchElement.setTargetNamespace(targetNamespace);
    if (currentPath.size() > 0) {
        String parentName = (String) currentPath.peek();
        searchElement.setParentName(parentName);
    }
    if (matcher != null) {
        if (matcher.matches(pattern, searchElement)) {
            hasMatch = true;
            if (pattern instanceof XMLComponentReferencePattern) {
                ComponentReferenceEntry documentEntry = new ComponentReferenceEntry();
                documentEntry.setCategory(IXMLSearchConstants.COMPONENT_REF);
                QualifiedName name = new QualifiedName(uri, localName);
                documentEntry.setKey(name.toString());
                documentEntry.setName(name);
                document.putEntry(documentEntry);
            } else if (pattern instanceof XMLComponentDeclarationPattern) {
                ComponentDeclarationEntry documentEntry = new ComponentDeclarationEntry();
                documentEntry.setCategory(IXMLSearchConstants.COMPONENT_DECL);
                // $NON-NLS-1$
                QualifiedName name = new QualifiedName(targetNamespace, attributes.getValue("name"));
                QualifiedName metaName = new QualifiedName(uri, localName);
                documentEntry.setKey(name.toString());
                documentEntry.setName(name);
                documentEntry.setMetaName(metaName);
                document.putEntry(documentEntry);
            }
        }
    }
    // $NON-NLS-1$
    currentPath.push(localName);
}
Also used : FileReferenceEntry(org.eclipse.wst.common.core.search.document.FileReferenceEntry) XMLComponentReferencePattern(org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) ComponentReferenceEntry(org.eclipse.wst.common.core.search.document.ComponentReferenceEntry) XMLComponentDeclarationPattern(org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern) ComponentDeclarationEntry(org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry)

Aggregations

QualifiedName (org.eclipse.wst.common.core.search.pattern.QualifiedName)3 XMLComponentDeclarationPattern (org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 Position (org.eclipse.jface.text.Position)1 TextChange (org.eclipse.ltk.core.refactoring.TextChange)1 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)1 SearchEngine (org.eclipse.wst.common.core.search.SearchEngine)1 SearchMatch (org.eclipse.wst.common.core.search.SearchMatch)1 SearchParticipant (org.eclipse.wst.common.core.search.SearchParticipant)1 ComponentDeclarationEntry (org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry)1 ComponentReferenceEntry (org.eclipse.wst.common.core.search.document.ComponentReferenceEntry)1 FileReferenceEntry (org.eclipse.wst.common.core.search.document.FileReferenceEntry)1 SearchPattern (org.eclipse.wst.common.core.search.pattern.SearchPattern)1 SearchScope (org.eclipse.wst.common.core.search.scope.SearchScope)1