Search in sources :

Example 1 with SearchMatch

use of org.eclipse.wst.common.core.search.SearchMatch 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 2 with SearchMatch

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

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

the class PatternMatcher method createSearchMatch.

protected SearchMatch createSearchMatch(IFile file, Attr attributeNode) {
    int start = 0;
    int length = 0;
    if (attributeNode instanceof IDOMAttr) {
        IDOMAttr domAttr = (IDOMAttr) attributeNode;
        start = domAttr.getValueRegionStartOffset();
        length = domAttr.getValueRegionText().length();
    }
    SearchMatch match = new SearchMatch(attributeNode, start, length, file);
    return match;
}
Also used : IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) SearchMatch(org.eclipse.wst.common.core.search.SearchMatch)

Example 4 with SearchMatch

use of org.eclipse.wst.common.core.search.SearchMatch 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 5 with SearchMatch

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

Aggregations

SearchMatch (org.eclipse.wst.common.core.search.SearchMatch)7 QualifiedName (org.eclipse.wst.common.core.search.pattern.QualifiedName)3 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)3 Iterator (java.util.Iterator)2 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 TextChange (org.eclipse.ltk.core.refactoring.TextChange)2 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)2 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Position (org.eclipse.jface.text.Position)1 Image (org.eclipse.swt.graphics.Image)1 SearchEngine (org.eclipse.wst.common.core.search.SearchEngine)1 ComponentDeclarationEntry (org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry)1 Entry (org.eclipse.wst.common.core.search.document.Entry)1