use of org.eclipse.ltk.core.refactoring.TextFileChange 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.ltk.core.refactoring.TextFileChange in project xtext-eclipse by eclipse.
the class TextChangeCombinerTest method createTextFileChange.
protected Change createTextFileChange(IFile file, int offset, int length, String replacement) {
ReplaceEdit edit = new ReplaceEdit(offset, length, replacement);
TextFileChange textFileChange = new TextFileChange("text change", file);
textFileChange.setEdit(edit);
textFileChange.setTextType(TEXT_TYPE);
return textFileChange;
}
use of org.eclipse.ltk.core.refactoring.TextFileChange in project xtext-eclipse by eclipse.
the class TextChangeCombinerTest method createMultiTextFileChange.
protected Change createMultiTextFileChange(IFile file, int offset0, int length0, String replacement0, int offset1, int length1, String replacement1) {
MultiTextEdit multiTextEdit = createMultiTextEdit(offset0, length0, replacement0, offset1, length1, replacement1);
TextFileChange textFileChange = new TextFileChange("text change", file);
textFileChange.setEdit(multiTextEdit);
textFileChange.setTextType(TEXT_TYPE);
return textFileChange;
}
use of org.eclipse.ltk.core.refactoring.TextFileChange 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.ltk.core.refactoring.TextFileChange in project xtext-eclipse by eclipse.
the class RefactoringDocumentProviderTest method testFileDocument.
@Test
public void testFileDocument() throws Exception {
IRefactoringDocument document = createAndCheckDocument(testFile);
assertTrue(document instanceof FileDocument);
assertEquals(testFile, ((FileDocument) document).getFile());
assertEquals(TEST_FILE_CONTENT, document.getOriginalContents());
Change change = document.createChange(CHANGE_NAME, textEdit);
assertTrue(change instanceof TextFileChange);
assertEquals(CHANGE_NAME, change.getName());
Change undoChange = checkEdit(document, textEdit);
assertNotNull(undoChange);
}
Aggregations