use of org.eclipse.xtext.ui.refactoring.impl.IRefactoringDocument 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);
}
use of org.eclipse.xtext.ui.refactoring.impl.IRefactoringDocument in project xtext-eclipse by eclipse.
the class RefactoringDocumentProviderTest method createAndCheckDocument.
protected IRefactoringDocument createAndCheckDocument(IFile testFile) {
IRefactoringDocument document = documentFactory.get(URI.createPlatformResourceURI(testFile.getFullPath().toString(), true), status);
assertTrue(status.getRefactoringStatus().isOK());
assertNotNull(document);
return document;
}
use of org.eclipse.xtext.ui.refactoring.impl.IRefactoringDocument 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;
}
use of org.eclipse.xtext.ui.refactoring.impl.IRefactoringDocument 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());
}
use of org.eclipse.xtext.ui.refactoring.impl.IRefactoringDocument 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());
}
Aggregations