use of org.eclipse.ltk.core.refactoring.TextFileChange in project titan.EclipsePlug-ins by eclipse.
the class ImportSelectionDialog method createFileChange.
private Change createFileChange(final IFile toVisit) {
if (toVisit == null) {
return null;
}
final String designerId = ProductConstants.PRODUCT_ID_DESIGNER;
final String displayDebugInfo = org.eclipse.titan.designer.preferences.PreferenceConstants.DISPLAYDEBUGINFORMATION;
reportDebug = Platform.getPreferencesService().getBoolean(designerId, displayDebugInfo, false, null);
final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
final Module module = sourceParser.containedModule(toVisit);
if (module == null || !(module instanceof TTCN3Module)) {
return null;
}
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
IDocument doc;
final TTCN3Module tModule = (TTCN3Module) module;
try {
doc = tfc.getCurrentDocument(null);
final MultiTextEdit resultEdit = organizeImportsEdit(tModule, doc);
if (!resultEdit.hasChildren()) {
return null;
}
tfc.setEdit(resultEdit);
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace("Error while organizing imports", e);
} catch (CoreException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return tfc;
}
use of org.eclipse.ltk.core.refactoring.TextFileChange in project titan.EclipsePlug-ins by eclipse.
the class ExtractModuleParRefactoring method createChange.
private WorkspaceJob createChange() {
final WorkspaceJob job = new WorkspaceJob("ExtractModulePar: writing to target project") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
if (copyMap == null) {
ErrorReporter.logError("ExtractModuleParRefactoring::createChange(): Reading dependencies did not finish.");
return Status.CANCEL_STATUS;
}
if (filesToCopy == null) {
ErrorReporter.logError("ExtractModuleParRefactoring::createChange(): Reading dependencies did not finish (2).");
return Status.CANCEL_STATUS;
}
// create files & write dependencies in them
for (Entry<IPath, StringBuilder> e : copyMap.entrySet()) {
IFile targetFile = createFile(e.getKey());
if (targetFile == null) {
ErrorReporter.logError("Unable to create file `" + e.getKey() + "' while extracting module parameters.");
return Status.CANCEL_STATUS;
}
TextFileChange change = new TextFileChange("extract_append", targetFile);
MultiTextEdit rootEdit = new MultiTextEdit();
change.setEdit(rootEdit);
TextEdit edit = new InsertEdit(0, e.getValue().toString());
rootEdit.addChild(edit);
change.perform(new NullProgressMonitor());
}
// copy files from 'filesToCopy' without opening them
for (IFile f : filesToCopy) {
if (copyFile(f) == null) {
ErrorReporter.logError("Unable to copy file `" + (f == null ? "null" : f.getProjectRelativePath()) + "' while extracting module aprameters.");
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return job;
}
use of org.eclipse.ltk.core.refactoring.TextFileChange in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method performOnSelectionOnly.
private void performOnSelectionOnly(final Module module) {
final Location selLoc = new Location(file, textSelection.getStartLine(), textSelection.getOffset(), textSelection.getOffset() + textSelection.getLength());
final SelectionVisitor vis = new SelectionVisitor(selLoc);
module.accept(vis);
final Map<Log_Statement, Context> res = vis.getResult();
final MultiTextEdit rootEdit = new MultiTextEdit();
for (Map.Entry<Log_Statement, Context> e : res.entrySet()) {
final TextEdit edit = createTextEdit(e.getKey(), e.getValue());
if (edit != null) {
rootEdit.addChild(edit);
}
}
if (rootEdit.hasChildren()) {
change = new TextFileChange("Context logging", file);
change.setEdit(rootEdit);
}
}
use of org.eclipse.ltk.core.refactoring.TextFileChange in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method performOnWholeModule.
private void performOnWholeModule(final Module module) {
final ContextFinder vis = new ContextFinder(settings);
module.accept(vis);
final Map<Log_Statement, Context> res = vis.getResult();
final MultiTextEdit rootEdit = new MultiTextEdit();
for (Map.Entry<Log_Statement, Context> e : res.entrySet()) {
final TextEdit edit = createTextEdit(e.getKey(), e.getValue());
if (edit != null) {
rootEdit.addChild(edit);
}
}
if (rootEdit.hasChildren()) {
change = new TextFileChange("Context logging", file);
change.setEdit(rootEdit);
}
}
use of org.eclipse.ltk.core.refactoring.TextFileChange in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method createFileChange.
private Change createFileChange(final IFile toVisit) {
if (toVisit == null) {
return null;
}
final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
final Module module = sourceParser.containedModule(toVisit);
if (module == null) {
return null;
}
// find all locations in the module that should be edited
final DefinitionVisitor vis = new DefinitionVisitor();
module.accept(vis);
final NavigableSet<ILocateableNode> nodes = vis.getLocations();
if (nodes.isEmpty()) {
return null;
}
// calculate edit locations
final List<Location> locations = new ArrayList<Location>();
try {
final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, locations);
job1.join();
} catch (InterruptedException ie) {
ErrorReporter.logExceptionStackTrace(ie);
} catch (CoreException ce) {
ErrorReporter.logError("MinimizeVisibilityRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
ErrorReporter.logExceptionStackTrace(ce);
}
if (locations.isEmpty()) {
return null;
}
// create a change for each edit location
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
final MultiTextEdit rootEdit = new MultiTextEdit();
tfc.setEdit(rootEdit);
for (Location l : locations) {
final int len = l.getEndOffset() - l.getOffset();
if (len == 0) {
rootEdit.addChild(new InsertEdit(l.getOffset(), "private "));
} else {
rootEdit.addChild(new ReplaceEdit(l.getOffset(), len, "private "));
}
}
return tfc;
}
Aggregations