Search in sources :

Example 1 with EditorDocument

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

the class RefactoringDocumentProviderTest method testCleanEditorDocument.

@Test
public void testCleanEditorDocument() throws Exception {
    XtextEditor editor = openEditor(testFile);
    assertFalse(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());
    assertTrue(((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 2 with EditorDocument

use of org.eclipse.xtext.ui.refactoring.impl.DefaultRefactoringDocumentProvider.EditorDocument 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)

Aggregations

Change (org.eclipse.ltk.core.refactoring.Change)2 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)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 EditorDocumentChange (org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange)2 IRefactoringDocument (org.eclipse.xtext.ui.refactoring.impl.IRefactoringDocument)2 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)2 Test (org.junit.Test)2