use of org.eclipse.xtext.ui.refactoring2.ChangeConverter in project xtext-eclipse by eclipse.
the class ResourceRelocationProcessor method createChange.
public Change createChange(String name, ResourceRelocationContext.ChangeType type, IProgressMonitor pm) throws CoreException, OperationCanceledException {
if (uriChanges.isEmpty()) {
return null;
}
SubMonitor subMonitor = SubMonitor.convert(pm);
// Declaring the task and its effort in 'SubMonitor.convert(...)' doesn't yield the expected UI updates
// so let's do it separately; the total effort of '5' is chosen for weighting the subsequent efforts
subMonitor.beginTask("Preparing the refactoring...", 5);
IChangeSerializer changeSerializer = changeSerializerProvider.get();
ResourceSet resourceSet = resourceSetProvider.get(project);
ResourceRelocationContext context = new ResourceRelocationContext(type, uriChanges, issues, changeSerializer, resourceSet);
boolean persistedIndexUsageRequested = isPersistedIndexUsageRequested(context);
// TODO check preconditions like all editors being saved if 'persistedIndexUsageRequested' == true
initializeResourceSet(persistedIndexUsageRequested, context);
executeParticipants(context, subMonitor.split(1));
ChangeConverter changeConverter = //
changeConverterFactory.create(//
name, (it) -> {
return (!(it instanceof MoveResourceChange || it instanceof RenameResourceChange) || !excludedResources.contains(it.getModifiedElement()));
}, issues);
// remaining effort is assigned to 'changeSerializer's work
SubMonitor modificationApplicationMonitor = subMonitor.split(4);
changeSerializer.setProgressMonitor(modificationApplicationMonitor);
changeSerializer.applyModifications(changeConverter);
modificationApplicationMonitor.done();
return changeConverter.getChange();
}
use of org.eclipse.xtext.ui.refactoring2.ChangeConverter in project xtext-eclipse by eclipse.
the class RenameElementProcessor2 method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException {
RenameChange renameChange = new RenameChange(newName, renameElementContext.getTargetElementURI());
RenameContext renameContext = new RenameContext(Arrays.asList(renameChange), resourceSet, changeSerializer, status);
renameStrategy.applyRename(renameContext);
String name = "Rename " + originalName + " to " + newName;
ChangeConverter changeConverter = changeConverterFactory.create(name, null, status);
changeSerializer.applyModifications(changeConverter);
change = changeConverter.getChange();
return status.getRefactoringStatus();
}
use of org.eclipse.xtext.ui.refactoring2.ChangeConverter in project xtext-eclipse by eclipse.
the class BatchModification method applyInWorkspace.
protected void applyInWorkspace(Iterable<IBatchableModification> modifications, IProgressMonitor monitor) throws CoreException {
IProject proj = getResolvedProject();
if (proj == null) {
LOG.error("No project configured.");
return;
}
SubMonitor progress = SubMonitor.convert(monitor, 100);
ResourceSet resourceSet = resourceSetProvider.get(proj);
liveScopeResourceSetInitializer.initialize(resourceSet);
List<ResolvedModification> resolved = Lists.newArrayList();
for (IBatchableModification modification : modifications) {
EObject obj = resourceSet.getEObject(modification.getEObjectURI(), true);
if (obj == null || obj.eIsProxy()) {
LOG.error("Invalid EObject URI " + modification.getEObjectURI());
continue;
}
resolved.add(new ResolvedModification(obj, modification));
}
progress.split(5);
IChangeSerializer serializer = serializerProvider.get();
SubMonitor subProgress = SubMonitor.convert(progress.split(80), resolved.size());
for (ResolvedModification mod : resolved) {
serializer.setProgressMonitor(subProgress.split(1));
mod.modification.apply(mod.object, serializer);
subProgress.split(1);
}
boolean first = true;
for (ResolvedModification mod : resolved) {
if (first) {
serializer.setUpdateCrossReferences(mod.modification.isUpdateCrossReferences());
serializer.setUpdateRelatedFiles(mod.modification.isUpdateRelatedFiles());
} else {
if (serializer.isUpdateCrossReferences() != mod.modification.isUpdateCrossReferences()) {
LOG.error("two modifications can't be batched.");
return;
}
if (serializer.isUpdateRelatedFiles() != mod.modification.isUpdateRelatedFiles()) {
LOG.error("two modifications can't be batched.");
return;
}
}
}
// 15 ticks yet available
progress.split(1);
ChangeConverter converter = changeConverterFactory.create("Resolving Issues", null, issueAcceptor);
serializer.applyModifications(converter);
progress.split(1);
Change change = converter.getChange();
if (change != null) {
change.initializeValidationData(progress.split(3));
new PerformChangeOperation(change).run(progress.split(10));
}
progress.done();
}
Aggregations