Search in sources :

Example 1 with QualifiedName

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

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

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

the class XSDTypesSearchListProvider method populateComponentList.

public void populateComponentList(IComponentList list, SearchScope scope, IProgressMonitor pm) {
    // first we add the 'built in' types
    // 
    XSDSchema schemaForSchema = XSDSchemaImpl.getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
    for (Iterator i = schemaForSchema.getSimpleTypeIdMap().values().iterator(); i.hasNext(); ) {
        XSDTypeDefinition td = (XSDTypeDefinition) i.next();
        if (builtInFilter == null || !builtInFilter.shouldFilterOut(td)) {
            list.add(td);
        }
    }
    // now we traverse the types already defined within the visible schemas
    // we do this in addition to the component search since this should execute
    // very quickly and there's a good chance the user wants to select a time
    // that's
    // already imported/included
    // TODO (cs) ensure we don't add duplicates when we proceed to use the
    // search list
    // 
    List visitedSchemas = new ArrayList();
    for (int i = 0; i < schemas.length; i++) {
        XSDSchema schema = schemas[i];
        QualifiedName kind = showComplexTypes ? IXSDSearchConstants.TYPE_META_NAME : IXSDSearchConstants.SIMPLE_TYPE_META_NAME;
        ComponentCollectingXSDVisitor visitor = new ComponentCollectingXSDVisitor(list, kind);
        visitor.visitSchema(schema, true);
        visitedSchemas.addAll(visitor.getVisitedSchemas());
    }
    // 
    if (scope != null) {
        populateComponentListUsingSearch(list, scope, pm, createFileMap(visitedSchemas));
    }
}
Also used : QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IComponentList(org.eclipse.wst.common.ui.internal.search.dialogs.IComponentList) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 4 with QualifiedName

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

the class FindReferencesAction method run.

public void run() {
    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());
        SearchScope scope = new WorkspaceSearchScope();
        String scopeDescription = "Workspace";
        XSDSearchQuery searchQuery = new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
        NewSearchUI.activateSearchResultView();
        NewSearchUI.runQueryInBackground(searchQuery);
    }
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) IFile(org.eclipse.core.resources.IFile) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) SearchScope(org.eclipse.wst.common.core.search.scope.SearchScope) WorkspaceSearchScope(org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope) WorkspaceSearchScope(org.eclipse.wst.common.core.search.scope.WorkspaceSearchScope) XSDSearchQuery(org.eclipse.wst.xsd.ui.internal.search.XSDSearchQuery)

Example 5 with QualifiedName

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

the class FindReferencesInProjectAction method run.

public void run() {
    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());
        IPath fullPath = file.getFullPath();
        ProjectSearchScope scope = new ProjectSearchScope(fullPath);
        String scopeDescription = "Project";
        XSDSearchQuery searchQuery = new XSDSearchQuery(pattern, file, elementQName, metaName, XSDSearchQuery.LIMIT_TO_REFERENCES, scope, scopeDescription);
        NewSearchUI.activateSearchResultView();
        NewSearchUI.runQueryInBackground(searchQuery);
    }
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) ProjectSearchScope(org.eclipse.wst.common.core.search.scope.ProjectSearchScope) 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