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;
}
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;
}
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]);
}
}
}
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());
}
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;
}
Aggregations