Search in sources :

Example 21 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange in project webtools.sourceediting by eclipse.

the class TextChangeManager method get.

/**
 * Returns the <code>TextChange</code> associated with the given file.
 * If the manager does not already manage an association it creates a one.
 *
 * @param file the file for which the text buffer change is requested
 * @return the text change associated with the given file.
 */
public TextChange get(IFile file) {
    TextChange result = (TextChange) fMap.get(file);
    if (result == null) {
        result = new TextFileChange(file.toString(), file);
        result.setKeepPreviewEdits(fKeepExecutedTextEdits);
        result.initializeValidationData(new NullProgressMonitor());
        fMap.put(file, result);
    }
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TextChange(org.eclipse.ltk.core.refactoring.TextChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange)

Example 22 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange in project webtools.sourceediting by eclipse.

the class MakeTypeGlobalChange method getChange.

public TextChange getChange(IFile file) {
    TextChange result = (TextChange) fChanges.get(file);
    if (result == null) {
        result = new TextFileChange(file.getName(), file);
        fChanges.put(file, result);
    }
    return result;
}
Also used : TextChange(org.eclipse.ltk.core.refactoring.TextChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange)

Example 23 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange in project flux by eclipse.

the class CUCorrectionProposal method createTextChange.

protected TextChange createTextChange() throws CoreException {
    ICompilationUnit cu = getCompilationUnit();
    String name = getName();
    TextChange change;
    if (!cu.getResource().exists()) {
        String source;
        try {
            source = cu.getSource();
        } catch (JavaModelException e) {
            JavaPlugin.log(e);
            // empty
            source = new String();
        }
        Document document = new Document(source);
        document.setInitialLineDelimiter(StubUtility.getLineDelimiterUsed(cu));
        change = new DocumentChange(name, document);
    } else {
        CompilationUnitChange cuChange = new CompilationUnitChange(name, cu);
        cuChange.setSaveMode(TextFileChange.LEAVE_DIRTY);
        change = cuChange;
    }
    TextEdit rootEdit = new MultiTextEdit();
    change.setEdit(rootEdit);
    // initialize text change
    IDocument document = change.getCurrentDocument(new NullProgressMonitor());
    addEdits(document, rootEdit);
    return change;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentChange(org.eclipse.ltk.core.refactoring.DocumentChange) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) IDocument(org.eclipse.jface.text.IDocument) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 24 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange in project flux by eclipse.

the class CUCorrectionProposal method getAdditionalProposalInfo.

@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
    StringBuffer buf = new StringBuffer();
    try {
        TextChange change = getTextChange();
        change.setKeepPreviewEdits(true);
        IDocument previewDocument = change.getPreviewDocument(monitor);
        TextEdit rootEdit = change.getPreviewEdit(change.getEdit());
        EditAnnotator ea = new EditAnnotator(buf, previewDocument);
        rootEdit.accept(ea);
        // Final pre-existing region
        ea.unchangedUntil(previewDocument.getLength());
    } catch (CoreException e) {
        JavaPlugin.log(e);
    }
    return buf.toString();
}
Also used : EditAnnotator(org.eclipse.jdt.internal.ui.text.correction.proposals.EditAnnotator) CoreException(org.eclipse.core.runtime.CoreException) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) IDocument(org.eclipse.jface.text.IDocument)

Example 25 with TextChange

use of org.eclipse.ltk.core.refactoring.TextChange 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)

Aggregations

TextChange (org.eclipse.ltk.core.refactoring.TextChange)44 TextEdit (org.eclipse.text.edits.TextEdit)14 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)13 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)13 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)10 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IFile (org.eclipse.core.resources.IFile)7 IDocument (org.eclipse.jface.text.IDocument)7 ArrayList (java.util.ArrayList)6 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)6 Change (org.eclipse.ltk.core.refactoring.Change)6 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)6 Iterator (java.util.Iterator)5 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)5 HashMap (java.util.HashMap)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)4 EditorDocumentChange (org.eclipse.xtext.ui.refactoring.impl.EditorDocumentChange)4 IOException (java.io.IOException)3