Search in sources :

Example 11 with TextChange

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

the class QualifiedNameSearchResult method getChange.

public TextChange getChange(IFile file) {
    TextChange result = 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 12 with TextChange

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

the class TextChangeManager method get.

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

Example 13 with TextChange

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

the class ProcessorBasedRefactoring method addToTextChangeMap.

private void addToTextChangeMap(Change change) {
    if (change instanceof TextChange) {
        Object element = ((TextChange) change).getModifiedElement();
        if (element != null) {
            fTextChangeMap.put(element, change);
        }
        // under the file resource into the hash table if possible.
        if (change instanceof TextFileChange && !change.getClass().equals(TextFileChange.class)) {
            IFile file = ((TextFileChange) change).getFile();
            fTextChangeMap.put(file, change);
        }
    } else if (change instanceof CompositeChange) {
        Change[] children = ((CompositeChange) change).getChildren();
        for (int i = 0; i < children.length; i++) {
            addToTextChangeMap(children[i]);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TextChange(org.eclipse.ltk.core.refactoring.TextChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 14 with TextChange

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

the class RefactoringCorrectionProposal method createTextChange.

@Override
protected TextChange createTextChange() throws CoreException {
    init(fRefactoring);
    fRefactoringStatus = fRefactoring.checkFinalConditions(new NullProgressMonitor());
    if (fRefactoringStatus.hasFatalError()) {
        // $NON-NLS-1$
        TextFileChange dummyChange = new TextFileChange("fatal error", (IFile) getCompilationUnit().getResource());
        // $NON-NLS-1$
        dummyChange.setEdit(new InsertEdit(0, ""));
        return dummyChange;
    }
    return (TextChange) fRefactoring.createChange(new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) InsertEdit(org.eclipse.text.edits.InsertEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange)

Example 15 with TextChange

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

the class CUCorrectionProposal method createTextChange.

/**
 * Creates the text change for this proposal.
 * This method is only called once and only when no text change has been passed in
 * {@link #CUCorrectionProposal(String, ICompilationUnit, TextChange, int, Image)}.
 *
 * @return the created text change
 * @throws CoreException if the creation of the text change failed
 */
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) {
            JavaLanguageServerPlugin.log(e.getStatus());
            // empty
            source = new String();
        }
        Document document = new Document(source);
        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)

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