Search in sources :

Example 11 with EditorDocumentChange

use of org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange in project xtext-eclipse by eclipse.

the class RefactoringDocumentProviderTest method testDirtyEditorDocument.

@Test
public void testDirtyEditorDocument() throws Exception {
    XtextEditor editor = openEditor(testFile);
    editor.getDocument().replace(0, 0, " ");
    editor.getDocument().replace(0, 1, "");
    assertTrue(editor.isDirty());
    IRefactoringDocument cleanDocument = createAndCheckDocument(testFile);
    assertTrue(cleanDocument instanceof EditorDocument);
    IXtextDocument editorDocument = editor.getDocument();
    assertEquals(editorDocument, ((EditorDocument) cleanDocument).getDocument());
    assertEquals(TEST_FILE_CONTENT, cleanDocument.getOriginalContents());
    Change change = cleanDocument.createChange(CHANGE_NAME, textEdit);
    assertTrue(change instanceof EditorDocumentChange);
    assertEquals(TEST_FILE_NAME + " - " + TEST_PROJECT, change.getName());
    assertEquals(editor, ((EditorDocumentChange) change).getEditor());
    assertFalse(((EditorDocumentChange) change).isDoSave());
    Change undoChange = checkEdit(cleanDocument, textEdit);
    assertNotNull(undoChange);
    IRefactoringDocument dirtyDocument = createAndCheckDocument(testFile);
    assertTrue(cleanDocument instanceof EditorDocument);
    assertEquals(editorDocument, ((EditorDocument) dirtyDocument).getDocument());
}
Also used : EditorDocument(org.eclipse.xtext.ui.refactoring.impl.DefaultRefactoringDocumentProvider.EditorDocument) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IRefactoringDocument(org.eclipse.xtext.ui.refactoring.impl.IRefactoringDocument) Change(org.eclipse.ltk.core.refactoring.Change) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) EditorDocumentChange(org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange) EditorDocumentChange(org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) Test(org.junit.Test)

Example 12 with EditorDocumentChange

use of org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange in project xtext-eclipse by eclipse.

the class ExtractVariableRefactoring method createChange.

@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    TextEdit textEdit = replaceConverter.convertToTextEdit(rewriter.getChanges());
    EditorDocumentChange change = new EditorDocumentChange("Extract local variable", editor, false);
    change.setEdit(textEdit);
    change.setTextType(resourceURI.fileExtension());
    return change;
}
Also used : TextEdit(org.eclipse.text.edits.TextEdit) EditorDocumentChange(org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange)

Aggregations

EditorDocumentChange (org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange)12 Change (org.eclipse.ltk.core.refactoring.Change)6 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)6 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)4 TextChange (org.eclipse.ltk.core.refactoring.TextChange)4 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)4 TextEdit (org.eclipse.text.edits.TextEdit)4 IFile (org.eclipse.core.resources.IFile)3 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)3 IRefactoringDocument (org.eclipse.xtext.ui.refactoring.impl.IRefactoringDocument)3 Test (org.junit.Test)3 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)2 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)2 IEditorPart (org.eclipse.ui.IEditorPart)2 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)2 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)2 EditorDocument (org.eclipse.xtext.ui.refactoring.impl.DefaultRefactoringDocumentProvider.EditorDocument)2 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)2 Predicate (com.google.common.base.Predicate)1 Inject (com.google.inject.Inject)1