use of org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method createChange.
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
EditorDocumentChange change = new EditorDocumentChange("Extract Method", editor, doSave);
change.setEdit(textEdit);
change.setTextType(resourceURI.fileExtension());
return change;
}
use of org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange in project xtext-eclipse by eclipse.
the class TextChangeCombiner method createTextChange.
protected TextChange createTextChange(Object key, String textType) {
TextChange change = null;
if (key instanceof ICompilationUnit)
change = new CompilationUnitChange("Combined CompilationUnitChange", (ICompilationUnit) key);
else if (key instanceof IFile)
change = new TextFileChange("Combined TextFileChange", (IFile) key);
else if (key instanceof ITextEditor)
change = new EditorDocumentChange("Combined DocumentChange", (ITextEditor) key, false);
else
LOG.error("Error creating change for " + key.getClass().getName());
if (change != null) {
MultiTextEdit edits = new MultiTextEdit();
change.setEdit(edits);
change.setTextType(textType);
}
return change;
}
use of org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange in project xtext-eclipse by eclipse.
the class TextChangeCombinerTest method createMultiEditorDocumentChange.
protected Change createMultiEditorDocumentChange(ITextEditor editor, int offset0, int length0, String replacement0, int offset1, int length1, String replacement1) {
MultiTextEdit multiTextEdit = createMultiTextEdit(offset0, length0, replacement0, offset1, length1, replacement1);
EditorDocumentChange documentChange = new EditorDocumentChange("document change", editor, false);
documentChange.setEdit(multiTextEdit);
documentChange.setTextType(TEXT_TYPE);
return documentChange;
}
use of org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange in project xtext-eclipse by eclipse.
the class ChangeConverter method _handleReplacements.
protected void _handleReplacements(ITextDocumentChange change) {
if (!change.getReplacements().isEmpty()) {
IFile file = resourceUriConverter.toFile(change.getOldURI());
if (!canWrite(file)) {
issues.add(RefactoringIssueAcceptor.Severity.FATAL, "Affected file '" + file.getFullPath() + "' is read-only");
}
checkDerived(file);
List<ReplaceEdit> textEdits = change.getReplacements().stream().map(replacement -> {
return new ReplaceEdit(replacement.getOffset(), replacement.getLength(), replacement.getReplacementText());
}).collect(Collectors.toList());
MultiTextEdit textEdit = new MultiTextEdit();
textEdit.addChildren(textEdits.toArray(new TextEdit[textEdits.size()]));
ITextEditor openEditor = findOpenEditor(file);
final TextChange ltkChange;
if (openEditor == null) {
TextFileChange textFileChange = new TextFileChange(change.getOldURI().lastSegment(), file);
textFileChange.setSaveMode(TextFileChange.FORCE_SAVE);
ltkChange = textFileChange;
} else {
ltkChange = new EditorDocumentChange(currentChange.getName(), openEditor, false);
}
ltkChange.setEdit(textEdit);
ltkChange.setTextType(change.getOldURI().fileExtension());
addChange(ltkChange);
}
}
use of org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange in project xtext-eclipse by eclipse.
the class MultiImportOrganizer method organizeImports.
/**
* @param files
* ordered by corresponding {@link IProject}
* @param mon
* @return Creates {@link Change}s for each {@link IFile} using {@link ImportOrganizer}
* @throws InterruptedException
*/
public List<Change> organizeImports(Multimap<IProject, IFile> files, IProgressMonitor mon) throws InterruptedException {
List<Change> result = Lists.newArrayList();
for (IProject project : files.keySet()) {
ResourceSet resSet = resSetProvider.get(project);
for (IFile file : files.get(project)) {
mon.subTask("Calculating imports in - " + file.getName());
URI uri = storageMapper.getUri(file);
if (uri != null) {
XtextResource resource = (XtextResource) resSet.getResource(uri, true);
List<ReplaceRegion> replace = importOrganizer.getOrganizedImportChanges(resource);
// TODO - find out why \n\n changes are produced, even if there are any unused imports
if (replace == null || replace.isEmpty()) {
continue;
}
TextEdit textEdit = replaceConverter.convertToTextEdit(replace);
IRefactoringDocument iRefactoringDocument = provider.get(uri, status);
if (iRefactoringDocument != null) {
Change change = iRefactoringDocument.createChange(Messages.OrganizeImports, textEdit);
if (change instanceof EditorDocumentChange) {
if (((EditorDocument) iRefactoringDocument).getEditor().isDirty()) {
((EditorDocumentChange) change).setDoSave(false);
}
}
result.add(change);
}
}
mon.worked(1);
if (mon.isCanceled()) {
throw new InterruptedException();
}
}
}
return result;
}
Aggregations