Search in sources :

Example 16 with TextFileChange

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;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TextChange(org.eclipse.ltk.core.refactoring.TextChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) EditorDocumentChange(org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 17 with TextFileChange

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;
}
Also used : ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange)

Example 18 with 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;
}
Also used : TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Example 19 with 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);
    }
}
Also used : RefactoringIssueAcceptor(org.eclipse.xtext.ide.refactoring.RefactoringIssueAcceptor) Arrays(java.util.Arrays) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAcceptor(org.eclipse.xtext.util.IAcceptor) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Inject(com.google.inject.Inject) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IContainer(org.eclipse.core.resources.IContainer) Logger(org.apache.log4j.Logger) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) IWorkspace(org.eclipse.core.resources.IWorkspace) TextChange(org.eclipse.ltk.core.refactoring.TextChange) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Change(org.eclipse.ltk.core.refactoring.Change) ITextDocumentChange(org.eclipse.xtext.ide.serializer.ITextDocumentChange) RenameResourceChange(org.eclipse.ltk.core.refactoring.resource.RenameResourceChange) IEditorPart(org.eclipse.ui.IEditorPart) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Exceptions(org.eclipse.xtext.util.Exceptions) TextEdit(org.eclipse.text.edits.TextEdit) IOException(java.io.IOException) DisplayRunnableWithResult(org.eclipse.xtext.ui.util.DisplayRunnableWithResult) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) List(java.util.List) Predicate(com.google.common.base.Predicate) MoveResourceChange(org.eclipse.ltk.core.refactoring.resource.MoveResourceChange) IWorkbench(org.eclipse.ui.IWorkbench) EditorDocumentChange(org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange) Nullable(org.eclipse.xtext.util.internal.Nullable) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) EditorDocumentChange(org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange)

Example 20 with TextFileChange

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);
}
Also used : FileDocument(org.eclipse.xtext.ui.refactoring.impl.DefaultRefactoringDocumentProvider.FileDocument) 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) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) Test(org.junit.Test)

Aggregations

TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)37 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)18 TextChange (org.eclipse.ltk.core.refactoring.TextChange)12 IFile (org.eclipse.core.resources.IFile)11 CoreException (org.eclipse.core.runtime.CoreException)11 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)10 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)10 TextEdit (org.eclipse.text.edits.TextEdit)9 InsertEdit (org.eclipse.text.edits.InsertEdit)8 Module (org.eclipse.titan.designer.AST.Module)8 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)6 ArrayList (java.util.ArrayList)5 IDocument (org.eclipse.jface.text.IDocument)5 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)3 IProject (org.eclipse.core.resources.IProject)3