use of org.eclipse.xtext.ide.serializer.IChangeSerializer 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