use of org.eclipse.xtext.ide.refactoring.ResourceRelocationContext in project xtext-core by eclipse.
the class FileAwareTestLanguageResourceRelocationStrategy method applyChange.
@Override
public void applyChange(ResourceRelocationContext context) {
filter(context.getChanges(), c -> canHandle(c)).forEach(change -> {
context.addModification(change, resource -> {
EObject rootElement = head(resource.getContents());
if (rootElement instanceof PackageDeclaration) {
List<String> segments = change.getToURI().trimSegments(1).segmentsList();
String newPackage = Joiner.on(".").join(drop(segments, 2));
((PackageDeclaration) rootElement).setName(newPackage);
}
});
});
}
use of org.eclipse.xtext.ide.refactoring.ResourceRelocationContext in project xtext-eclipse by eclipse.
the class ResourceRelocationProcessor method executeParticipants.
protected void executeParticipants(final ResourceRelocationContext context) {
final List<? extends IResourceRelocationStrategy> strategies = this.strategyRegistry.getStrategies();
ResourceRelocationContext.ChangeType _changeType = context.getChangeType();
boolean _tripleEquals = (_changeType == ResourceRelocationContext.ChangeType.COPY);
if (_tripleEquals) {
IChangeSerializer _changeSerializer = context.getChangeSerializer();
_changeSerializer.setUpdateRelatedFiles(false);
}
final Consumer<IResourceRelocationStrategy> _function = (IResourceRelocationStrategy it) -> {
try {
it.applyChange(context);
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable t = (Throwable) _t;
this.issues.add(RefactoringIssueAcceptor.Severity.ERROR, "Error applying resource changes", t);
ResourceRelocationProcessor.LOG.error(t.getMessage(), t);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
};
strategies.forEach(_function);
}
use of org.eclipse.xtext.ide.refactoring.ResourceRelocationContext 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();
}
Aggregations