Search in sources :

Example 1 with XMLComponentReferencePattern

use of org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern 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)

Example 2 with XMLComponentReferencePattern

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

the class RenameComponentProcessor method addOccurrences.

void addOccurrences(TextChangeManager manager, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
    String fileStr = selectedComponent.getElement().getModel().getBaseLocation();
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileStr));
    String componentName = selectedComponent.getName();
    String componentNamespace = selectedComponent.getNamespaceURI();
    QualifiedName elementQName = new QualifiedName(componentNamespace, componentName);
    QualifiedName typeQName = selectedComponent.getTypeQName();
    SearchEngine searchEngine = new SearchEngine();
    SearchScope scope = null;
    HashMap map = new HashMap();
    if (singleFileOnly) {
        map.put("searchDirtyContent", Boolean.TRUE);
        scope = new SelectionSearchScope(new IResource[] { file });
    } else {
        scope = new WorkspaceSearchScope();
    }
    SortingSearchRequestor requestor = new SortingSearchRequestor();
    SearchPattern pattern = new XMLComponentReferencePattern(file, elementQName, typeQName);
    searchEngine.search(pattern, requestor, scope, map, new NullProgressMonitor());
    references = requestor.getResults();
// for (Iterator iter = references.iterator(); iter.hasNext();) {
// SearchMatch match = (SearchMatch) iter.next();
// TextChange textChange = manager.get(match.getFile());
// String newName = getNewElementName();
// if(match.getObject() instanceof Node){
// Node node = (Node)match.getObject();
// if(node instanceof IDOMAttr){
// IDOMAttr attr = (IDOMAttr)node;
// IDOMElement element = (IDOMElement)attr.getOwnerElement() ;
// newName = getNewQName(element, componentNamespace, newName);
// }
// newName = quoteString(newName);
// }
// 
// ReplaceEdit replaceEdit = new ReplaceEdit(match.getOffset(),
// match.getLength(), newName );
// String editName =
// RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_update_reference");
// TextChangeCompatibility.addTextEdit(textChange, editName,
// replaceEdit);
// }
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) SelectionSearchScope(org.eclipse.wst.common.core.search.scope.SelectionSearchScope) XMLComponentReferencePattern(org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern) WorkspaceSearchScope(org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope) 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) IResource(org.eclipse.core.resources.IResource)

Aggregations

QualifiedName (org.eclipse.wst.common.core.search.pattern.QualifiedName)2 XMLComponentReferencePattern (org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern)2 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 SearchEngine (org.eclipse.wst.common.core.search.SearchEngine)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 SelectionSearchScope (org.eclipse.wst.common.core.search.scope.SelectionSearchScope)1 WorkspaceSearchScope (org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope)1 XMLComponentDeclarationPattern (org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern)1