use of org.eclipse.xtext.ui.refactoring2.LtkIssueAcceptor in project xtext-eclipse by eclipse.
the class RenameElementProcessor2 method validateNewName.
@Override
public RefactoringStatus validateNewName(String newName) {
LtkIssueAcceptor nameStatus = statusProvider.get();
nameValidator.validate(target, newName, nameStatus);
return nameStatus.getRefactoringStatus();
}
use of org.eclipse.xtext.ui.refactoring2.LtkIssueAcceptor in project xtext-eclipse by eclipse.
the class DefaultLinkedPositionGroupCalculator2 method getLinkedPositionGroup.
@Override
public Provider<LinkedPositionGroup> getLinkedPositionGroup(IRenameElementContext renameElementContext, IProgressMonitor monitor) {
SubMonitor progress = SubMonitor.convert(monitor, 100);
XtextEditor editor = (XtextEditor) renameElementContext.getTriggeringEditor();
IProject project = projectUtil.getProject(renameElementContext.getContextResourceURI());
if (project == null) {
throw new IllegalStateException("Could not determine the project for context resource " + renameElementContext.getContextResourceURI());
}
CachingResourceSetProvider cachingResourceSetProvider = new CachingResourceSetProvider(resourceSetProvider);
ResourceSet resourceSet = cachingResourceSetProvider.get(project);
EObject targetElement = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true);
if (targetElement == null) {
throw new IllegalStateException("Target element could not be loaded");
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
IRenameStrategy2 renameStrategy = globalServiceProvider.findService(targetElement, IRenameStrategy2.class);
if (renameStrategy == null) {
throw new IllegalArgumentException("Cannot find a rename strategy for " + renameElementContext.getTargetElementURI());
}
String oldName = simpleNameProvider.getSimpleName(targetElement);
String newName = getNewDummyName(oldName);
IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(renameElementContext.getTargetElementURI());
LtkIssueAcceptor issues = resourceServiceProvider.get(LtkIssueAcceptor.class);
IChangeSerializer changeSerializer = resourceServiceProvider.get(IChangeSerializer.class);
changeSerializer.setUpdateRelatedFiles(false);
RenameChange change = new RenameChange(newName, renameElementContext.getTargetElementURI());
RenameContext renameContext = new RenameContext(Lists.newArrayList(change), resourceSet, changeSerializer, issues);
renameStrategy.applyRename(renameContext);
List<ReplaceEdit> replaceEdits = new ArrayList<>();
changeSerializer.applyModifications(c -> {
if (c instanceof ITextDocumentChange) {
ITextDocumentChange textDocumentChange = (ITextDocumentChange) c;
textDocumentChange.getReplacements().forEach(replacement -> {
replaceEdits.add(new ReplaceEdit(replacement.getOffset(), replacement.getLength(), replacement.getReplacementText()));
});
}
});
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
return () -> {
return createLinkedGroupFromReplaceEdits(replaceEdits, editor, oldName, progress.newChild(10));
};
}
Aggregations