use of org.eclipse.ltk.core.refactoring.CompositeChange in project titan.EclipsePlug-ins by eclipse.
the class MinimizeScopeRefactoring method createChange.
@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
if (fileSelection != null) {
// resource(s) selected
final CompositeChange cchange = new CompositeChange("MinimizeScopeRefactoring");
final Iterator<?> it = fileSelection.iterator();
while (it.hasNext()) {
final Object o = it.next();
if (!(o instanceof IResource)) {
continue;
}
final IResource res = (IResource) o;
final ResourceVisitor vis = new ResourceVisitor();
res.accept(vis);
cchange.add(vis.getChange());
}
this.affectedObjects = cchange.getAffectedObjects();
return cchange;
} else {
// a single definition selected
final CompositeChange cchange = new CompositeChange("MinimizeScopeRefactoring");
final IResource file = defSelection.getLocation().getFile();
if (!(file instanceof IFile)) {
ErrorReporter.logError("MinimizeScopeRefactoring.createChange(): File container of defSelection is not an IFile! ");
}
final ChangeCreator chCreator = new ChangeCreator((IFile) file, defSelection, settings);
chCreator.perform();
final Change ch = chCreator.getChange();
if (ch != null) {
cchange.add(ch);
this.affectedObjects = ch.getAffectedObjects();
} else {
this.affectedObjects = new Object[] {};
}
return cchange;
}
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project titan.EclipsePlug-ins by eclipse.
the class UngroupModuleparRefactoring method createChange.
@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
if (selection == null) {
return null;
}
final CompositeChange cchange = new CompositeChange("UngroupModuleparRefactoring");
final Iterator<?> it = selection.iterator();
while (it.hasNext()) {
final Object o = it.next();
if (!(o instanceof IResource)) {
continue;
}
final IResource res = (IResource) o;
final ResourceVisitor vis = new ResourceVisitor();
res.accept(vis);
cchange.add(vis.getChange());
}
affectedObjects = cchange.getAffectedObjects();
return cchange;
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project titan.EclipsePlug-ins by eclipse.
the class RenameRefactoring method createChange.
@Override
public Change createChange(final IProgressMonitor pm) throws CoreException {
CompositeChange result = new CompositeChange(getName());
// add the change of all found identifiers grouped by module
boolean isAsnRename = module.getModuletype() == Module.module_type.ASN_MODULE;
String newTtcnIdentifierName = newIdentifierName;
if (isAsnRename) {
newTtcnIdentifierName = Identifier.getTtcnNameFromAsnName(newIdentifierName);
}
List<IFile> filesToProcess = new ArrayList<IFile>(idsMap.size());
for (Module m : idsMap.keySet()) {
List<Hit> hitList = idsMap.get(m);
boolean isTtcnModule = m.getModuletype() == Module.module_type.TTCN3_MODULE;
IFile file = (IFile) hitList.get(0).identifier.getLocation().getFile();
TextFileChange tfc = new TextFileChange(file.getName(), file);
result.add(tfc);
MultiTextEdit rootEdit = new MultiTextEdit();
tfc.setEdit(rootEdit);
for (Hit hit : hitList) {
int offset = hit.identifier.getLocation().getOffset();
int length = hit.identifier.getLocation().getEndOffset() - offset;
String newName = isTtcnModule ? newTtcnIdentifierName : newIdentifierName;
// reference.
if (rf.fieldId == null && hit.reference != null && hit.reference.getModuleIdentifier() == null && rf.assignment.getMyScope().getModuleScope() != hit.reference.getMyScope().getModuleScope() && hit.reference.getMyScope().hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), new Identifier(isTtcnModule ? Identifier_type.ID_TTCN : Identifier_type.ID_ASN, newIdentifierName))) {
newName = rf.assignment.getMyScope().getModuleScope().getName() + "." + newName;
}
rootEdit.addChild(new ReplaceEdit(offset, length, newName));
}
filesToProcess.add((IFile) m.getLocation().getFile());
}
return result;
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project titan.EclipsePlug-ins by eclipse.
the class OrganizeImportsOp method run.
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final Set<IProject> projects = new HashSet<IProject>();
for (final IFile f : files) {
projects.add(f.getProject());
}
monitor.beginTask("Organize imports", files.size() + projects.size() * 20);
for (final IProject project : projects) {
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
parser.reportOutdating(files);
final WorkspaceJob job = parser.analyzeAll();
monitor.subTask("Waiting for semantic analysis on project " + project.getName());
try {
job.join();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace("Error while waiting for the analysis to finish", e);
}
if (monitor.isCanceled()) {
throw new InterruptedException();
}
monitor.worked(20);
}
final CompositeChange compChange = new CompositeChange("Organize imports");
for (final IFile f : files) {
monitor.subTask("Organizing " + f.getName());
try {
final TextFileChange change = OrganizeImports.organizeImportsChange(f);
compChange.add(change);
compChange.perform(new SubProgressMonitor(monitor, 1));
final MultiTextEdit edit = (MultiTextEdit) change.getEdit();
if (edit != null && edit.getChildrenSize() > 0) {
final WorkspaceJob job = GlobalParser.getProjectSourceParser(f.getProject()).reportOutdating(f);
try {
job.join();
} catch (InterruptedException e) {
ErrorReporter.logExceptionStackTrace("Error while waiting for the outdating report to finish", e);
}
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while organizing file " + f.getName(), e);
}
if (monitor.isCanceled()) {
throw new InterruptedException();
}
monitor.worked(1);
}
for (final IProject project : projects) {
GlobalParser.getProjectSourceParser(project).analyzeAll();
}
monitor.done();
}
Aggregations