Search in sources :

Example 36 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange in project webtools.sourceediting by eclipse.

the class JSPRenameParticipant method createChange.

/**
 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(
 * 	org.eclipse.core.runtime.IProgressMonitor)
 */
public Change createChange(IProgressMonitor pm) throws CoreException {
    // $NON-NLS-1$
    this.getTextChange("");
    // create one multi change to contain all new created changes
    CompositeChange multiChange = new CompositeChange(JSPUIMessages.JSP_changes);
    // for each element get the changes for it and add it to the multi change
    Iterator iter = fElementAndArgumentPairs.values().iterator();
    while (iter.hasNext()) {
        ElementAndArgumentsPair elemArgsPair = (ElementAndArgumentsPair) iter.next();
        Change[] changes = createChangesFor(elemArgsPair.fElement, elemArgsPair.fArgs.getNewName(), pm);
        /* add all new text changes to the local list of text changes so that
			 * future iterations through the while loop will be aware of already
			 * existing changes
			 */
        for (int i = 0; i < changes.length; ++i) {
            if (changes[i] instanceof TextChange) {
                fLocalTextChanges.put(((TextChange) changes[i]).getModifiedElement(), changes[i]);
            }
        }
        if (changes.length > 0) {
            multiChange.addAll(changes);
        }
    }
    // unless there are actually new changes return null
    Change result = null;
    if (multiChange.getChildren().length > 0) {
        result = multiChange;
    }
    return result;
}
Also used : Iterator(java.util.Iterator) TextChange(org.eclipse.ltk.core.refactoring.TextChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 37 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange in project webtools.sourceediting by eclipse.

the class RenameComponentProcessor method postCreateChange.

public Change postCreateChange(Change[] participantChanges, IProgressMonitor pm) throws CoreException, OperationCanceledException {
    Assert.isNotNull(pm);
    try {
        String changeName = RefactoringMessages.getString("RenameComponentProcessor.Component_Refactoring_updates");
        TextChange[] changes = changeManager.getAllChanges();
        // };
        if (changes.length > 0) {
            // Arrays.sort(changes, c);
            CompositeChange compositeChange = new CompositeChange("!" + changeName, changes);
            compositeChange.markAsSynthetic();
            return compositeChange;
        } else {
            return null;
        }
    } finally {
        pm.done();
    }
}
Also used : TextChange(org.eclipse.ltk.core.refactoring.TextChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 38 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange 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)

Example 39 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange in project eclipse.jdt.ls by eclipse.

the class CodeActionHandler method getCommandFromProposal.

private Command getCommandFromProposal(CUCorrectionProposal proposal) throws CoreException {
    String name = proposal.getName();
    TextChange textChange = proposal.getTextChange();
    TextEdit edit = textChange.getEdit();
    ICompilationUnit unit = proposal.getCompilationUnit();
    return textEditToCommand(unit, name, edit);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextEdit(org.eclipse.text.edits.TextEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange)

Example 40 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange in project eclipse.jdt.ls by eclipse.

the class CUCorrectionProposal method getAdditionalProposalInfo.

@Override
public String getAdditionalProposalInfo(IProgressMonitor monitor) throws CoreException {
    StringBuffer buf = new StringBuffer();
    TextChange change = getTextChange();
    change.setKeepPreviewEdits(true);
    IDocument previewDocument = change.getPreviewDocument(monitor);
    TextEdit rootEdit = change.getPreviewEdit(change.getEdit());
    EditAnnotator ea = new EditAnnotator(buf, previewDocument);
    rootEdit.accept(ea);
    // Final pre-existing
    ea.unchangedUntil(previewDocument.getLength());
    // region
    return buf.toString();
}
Also used : MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

TextChange (org.eclipse.ltk.core.refactoring.TextChange)44 TextEdit (org.eclipse.text.edits.TextEdit)14 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)13 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)13 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)10 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IFile (org.eclipse.core.resources.IFile)7 IDocument (org.eclipse.jface.text.IDocument)7 ArrayList (java.util.ArrayList)6 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)6 Change (org.eclipse.ltk.core.refactoring.Change)6 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)6 Iterator (java.util.Iterator)5 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)5 HashMap (java.util.HashMap)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)4 EditorDocumentChange (org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange)4 IOException (java.io.IOException)3