Search in sources :

Example 6 with QualifiedName

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

the class XMLSearchPatternMatcher method createSearchMatch.

protected SearchMatch createSearchMatch(IFile file, Attr attributeNode) {
    SearchMatch match = super.createSearchMatch(file, attributeNode);
    // todo... remove this ugly hack!!
    if (// $NON-NLS-1$
    "name".equals(attributeNode.getName())) {
        // $NON-NLS-1$
        QualifiedName qualifiedName = new QualifiedName("todo-compute-targetNamespace", attributeNode.getValue());
        // $NON-NLS-1$
        match.map.put("name", qualifiedName);
    }
    // }
    return match;
}
Also used : SearchMatch(org.eclipse.wst.common.core.search.SearchMatch) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName)

Example 7 with QualifiedName

use of org.eclipse.wst.common.core.search.pattern.QualifiedName 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 8 with QualifiedName

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

the class XSDComponentDescriptionProvider method getQualifiedNameForSearchMatch.

// TODO... this will be much easier with Hiroshi's proposed SearchMatch changes
// 
private QualifiedName getQualifiedNameForSearchMatch(SearchMatch match) {
    QualifiedName qualifiedName = null;
    Object o = match.map.get("name");
    if (o != null && o instanceof QualifiedName) {
        qualifiedName = (QualifiedName) o;
    }
    return qualifiedName;
}
Also used : QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName)

Example 9 with QualifiedName

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

the class XSDComponentDescriptionProvider method getImage.

public Image getImage(Object component) {
    Image result = null;
    if (component instanceof SearchMatch) {
        SearchMatch searchMatch = (SearchMatch) component;
        QualifiedName qualifiedName = (QualifiedName) searchMatch.map.get("metaName");
        if (qualifiedName != null) {
            if (qualifiedName.equals(IXSDSearchConstants.SIMPLE_TYPE_META_NAME))
                result = SIMPLE_TYPE_IMAGE;
            else if (qualifiedName.equals(IXSDSearchConstants.COMPLEX_TYPE_META_NAME))
                result = COMPLEX_TYPE_IMAGE;
            else if (qualifiedName.equals(IXSDSearchConstants.ELEMENT_META_NAME))
                result = ELEMENT_IMAGE;
            else if (qualifiedName.equals(IXSDSearchConstants.ATTRIBUTE_META_NAME))
                result = ATTRIBUTE_IMAGE;
        }
    } else if (component instanceof XSDComplexTypeDefinition)
        result = COMPLEX_TYPE_IMAGE;
    else if (component instanceof XSDSimpleTypeDefinition)
        result = SIMPLE_TYPE_IMAGE;
    else if (component instanceof XSDElementDeclaration)
        result = ELEMENT_IMAGE;
    else if (component instanceof XSDAttributeDeclaration)
        result = ATTRIBUTE_IMAGE;
    return result;
}
Also used : SearchMatch(org.eclipse.wst.common.core.search.SearchMatch) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Image(org.eclipse.swt.graphics.Image) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 10 with QualifiedName

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

the class FindReferencesInWorkingSetAction method run.

public void run() {
    IWorkingSet[] workingSets = queryWorkingSets();
    if (workingSets == null || workingSets.length == 0)
        // The user chooses nothing, no point to continue.
        return;
    String pattern = "";
    XSDNamedComponent component = getXSDNamedComponent();
    IFile file = getCurrentFile();
    if (file != null && component != null) {
        QualifiedName metaName = determineMetaName(component);
        QualifiedName elementQName = new QualifiedName(component.getTargetNamespace(), component.getName());
        // Create a scope from the selected working sets
        WorkingSetSearchScope scope = new WorkingSetSearchScope();
        for (int i = 0; i < workingSets.length; i++) {
            IAdaptable[] elements = workingSets[i].getElements();
            scope.addAWorkingSetToScope(elements);
        }
        String scopeDescription = "Working Set";
        XSDSearchQuery searchQuery = new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
        NewSearchUI.activateSearchResultView();
        NewSearchUI.runQueryInBackground(searchQuery);
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) IFile(org.eclipse.core.resources.IFile) WorkingSetSearchScope(org.eclipse.wst.common.core.search.scope.WorkingSetSearchScope) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) IWorkingSet(org.eclipse.ui.IWorkingSet) XSDSearchQuery(org.eclipse.wst.xsd.ui.internal.search.XSDSearchQuery)

Aggregations

QualifiedName (org.eclipse.wst.common.core.search.pattern.QualifiedName)11 IFile (org.eclipse.core.resources.IFile)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 SearchMatch (org.eclipse.wst.common.core.search.SearchMatch)3 SearchScope (org.eclipse.wst.common.core.search.scope.SearchScope)3 WorkspaceSearchScope (org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope)3 XMLComponentDeclarationPattern (org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern)3 XSDSearchQuery (org.eclipse.wst.xsd.ui.internal.search.XSDSearchQuery)3 XSDNamedComponent (org.eclipse.xsd.XSDNamedComponent)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 IResource (org.eclipse.core.resources.IResource)2 SearchEngine (org.eclipse.wst.common.core.search.SearchEngine)2 SearchPattern (org.eclipse.wst.common.core.search.pattern.SearchPattern)2 SelectionSearchScope (org.eclipse.wst.common.core.search.scope.SelectionSearchScope)2 XMLComponentReferencePattern (org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern)2 CoreException (org.eclipse.core.runtime.CoreException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1