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;
}
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();
}
}
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;
}
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);
}
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();
}
Aggregations