Search in sources :

Example 6 with SearchMatch

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

the class XSDComponentDescriptionProvider method getFile.

public IFile getFile(Object component) {
    IFile result = null;
    if (component instanceof ComponentSpecification) {
        result = ((ComponentSpecification) component).getFile();
    } else if (component instanceof SearchMatch) {
        result = ((SearchMatch) component).getFile();
    } else if (component instanceof XSDConcreteComponent) {
        XSDConcreteComponent concreteComponent = (XSDConcreteComponent) component;
        XSDSchema schema = concreteComponent.getSchema();
        if (schema != null) {
            // TODO (cs) revisit and test more
            // 
            String location = schema.getSchemaLocation();
            String platformResource = "platform:/resource";
            if (location != null && location.startsWith(platformResource)) {
                Path path = new Path(location.substring(platformResource.length()));
                result = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            }
        }
    }
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) SearchMatch(org.eclipse.wst.common.core.search.SearchMatch) IFile(org.eclipse.core.resources.IFile) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 7 with SearchMatch

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

the class XMLComponentRenameParticipant method createChange.

// private RefactoringStatus createRenameChanges(final IProgressMonitor monitor) throws CoreException {
// Assert.isNotNull(monitor);
// final RefactoringStatus status= new RefactoringStatus();
// try {
// monitor.beginTask("RefactoringMessages.RenameComponentRefactoring_searching", 1);
// createRenameChanges(new SubProgressMonitor(monitor, 1));
// //updateChangeManager(new SubProgressMonitor(monitor, 1), status);
// } finally {
// monitor.done();
// }
// return status;
// }
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    for (Iterator iter = matches.iterator(); iter.hasNext(); ) {
        SearchMatch match = (SearchMatch) iter.next();
        TextChange textChange = getChangeManager().get(match.getFile());
        String newName = getArguments().getNewName();
        String qualifier = "";
        if (getArguments() instanceof ComponentRenameArguments) {
            qualifier = ((ComponentRenameArguments) getArguments()).getQualifier();
        }
        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, qualifier, newName);
            }
            newName = RenameComponentProcessor.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);
    }
    // don't create any change now, all the changes are in changeManger variable and will be combined in RenameComponentProcessor.postCreateChange method
    return null;
}
Also used : SearchMatch(org.eclipse.wst.common.core.search.SearchMatch) IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

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