use of org.eclipse.xtext.ide.serializer.ITextDocumentChange in project xtext-eclipse by eclipse.
the class ChangeSerializerTextEditComposer method collectChanges.
protected void collectChanges(IEmfResourceChange e, List<TextEdit> edits) {
if (e instanceof ITextDocumentChange && e.getResource() == recording) {
ITextDocumentChange change = (ITextDocumentChange) e;
for (ITextReplacement c : change.getReplacements()) {
ReplaceEdit edit = new ReplaceEdit(c.getOffset(), c.getLength(), c.getReplacementText());
edits.add(edit);
}
}
}
use of org.eclipse.xtext.ide.serializer.ITextDocumentChange in project xtext-core by eclipse.
the class CodeActionService method recordWorkspaceEdit.
private WorkspaceEdit recordWorkspaceEdit(final Document doc, final XtextResource resource, final IChangeSerializer.IModification<Resource> mod) {
try {
final XtextResourceSet rs = new XtextResourceSet();
final Resource copy = rs.createResource(resource.getURI());
String _text = resource.getParseResult().getRootNode().getText();
StringInputStream _stringInputStream = new StringInputStream(_text);
copy.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
this.serializer.<Resource>addModification(copy, mod);
final ArrayList<IEmfResourceChange> documentchanges = CollectionLiterals.<IEmfResourceChange>newArrayList();
this.serializer.applyModifications(CollectionBasedAcceptor.<IEmfResourceChange>of(documentchanges));
WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
final Procedure1<WorkspaceEdit> _function = (WorkspaceEdit it) -> {
Iterable<ITextDocumentChange> _filter = Iterables.<ITextDocumentChange>filter(documentchanges, ITextDocumentChange.class);
for (final ITextDocumentChange documentchange : _filter) {
{
final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
TextEdit _textEdit = new TextEdit();
final Procedure1<TextEdit> _function_2 = (TextEdit it_1) -> {
it_1.setNewText(replacement.getReplacementText());
Position _position = doc.getPosition(replacement.getOffset());
Position _position_1 = doc.getPosition(replacement.getEndOffset());
Range _range = new Range(_position, _position_1);
it_1.setRange(_range);
};
return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
};
final List<TextEdit> edits = ListExtensions.<ITextReplacement, TextEdit>map(documentchange.getReplacements(), _function_1);
it.getChanges().put(documentchange.getNewURI().toString(), edits);
}
}
};
return ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.ide.serializer.ITextDocumentChange in project xtext-core by eclipse.
the class TextDocumentChangeToString method toString.
@Override
public String toString() {
List<String> result = Lists.newArrayList();
for (IEmfResourceChange c : changes) {
String title = getTitle(c);
if (c instanceof ITextDocumentChange) {
ITextDocumentChange change = (ITextDocumentChange) c;
TextRegionsToString textRegionsToString = new TextRegionsToString();
textRegionsToString.setIgnoreCarriageReturnInQuotes(true);
textRegionsToString.addAllReplacements(change.getReplacements());
textRegionsToString.setTitle(title);
result.add(textRegionsToString.toString());
} else {
String box = box(title, c.toString());
result.add(box);
}
}
return Joiner.on("\n").join(result);
}
use of org.eclipse.xtext.ide.serializer.ITextDocumentChange in project xtext-eclipse by eclipse.
the class DefaultLinkedPositionGroupCalculator2 method getLinkedPositionGroup.
@Override
public Provider<LinkedPositionGroup> getLinkedPositionGroup(final IRenameElementContext renameElementContext, final IProgressMonitor monitor) {
final SubMonitor progress = SubMonitor.convert(monitor, 100);
IEditorPart _triggeringEditor = renameElementContext.getTriggeringEditor();
final XtextEditor editor = ((XtextEditor) _triggeringEditor);
final IProject project = this.projectUtil.getProject(renameElementContext.getContextResourceURI());
if ((project == null)) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Could not determine project for context resource ");
URI _contextResourceURI = renameElementContext.getContextResourceURI();
_builder.append(_contextResourceURI);
String _string = _builder.toString();
throw new IllegalStateException(_string);
}
final CachingResourceSetProvider resourceSetProvider = new CachingResourceSetProvider(this.resourceSetProvider);
final ResourceSet resourceSet = resourceSetProvider.get(project);
final EObject targetElement = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true);
if ((targetElement == null)) {
throw new IllegalStateException("Target element could not be loaded");
}
boolean _isCanceled = monitor.isCanceled();
if (_isCanceled) {
throw new OperationCanceledException();
}
IRenameStrategy2 renameStrategy = this.globalServiceProvider.<IRenameStrategy2>findService(targetElement, IRenameStrategy2.class);
if ((renameStrategy == null)) {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("Cannot find a rename strategy for ");
URI _targetElementURI = renameElementContext.getTargetElementURI();
_builder_1.append(_targetElementURI);
throw new IllegalArgumentException(_builder_1.toString());
}
final String oldName = this.simpleNameProvider.getSimpleName(targetElement);
final String newName = this.getNewDummyName(oldName);
final IResourceServiceProvider resourceServiceProvider = this.resourceServiceProviderRegistry.getResourceServiceProvider(renameElementContext.getTargetElementURI());
final LtkIssueAcceptor issues = resourceServiceProvider.<LtkIssueAcceptor>get(LtkIssueAcceptor.class);
final IChangeSerializer changeSerializer = resourceServiceProvider.<IChangeSerializer>get(IChangeSerializer.class);
changeSerializer.setUpdateRelatedFiles(false);
URI _targetElementURI_1 = renameElementContext.getTargetElementURI();
final RenameChange change = new RenameChange(newName, _targetElementURI_1);
final RenameContext renameContext = new RenameContext(Collections.<RenameChange>unmodifiableList(CollectionLiterals.<RenameChange>newArrayList(change)), resourceSet, changeSerializer, issues);
renameStrategy.applyRename(renameContext);
final ArrayList<ReplaceEdit> replaceEdits = CollectionLiterals.<ReplaceEdit>newArrayList();
final IAcceptor<IEmfResourceChange> _function = (IEmfResourceChange c) -> {
if ((c instanceof ITextDocumentChange)) {
final Function1<ITextReplacement, ReplaceEdit> _function_1 = (ITextReplacement replacement) -> {
int _offset = replacement.getOffset();
int _length = replacement.getLength();
String _replacementText = replacement.getReplacementText();
return new ReplaceEdit(_offset, _length, _replacementText);
};
List<ReplaceEdit> _map = ListExtensions.<ITextReplacement, ReplaceEdit>map(((ITextDocumentChange) c).getReplacements(), _function_1);
Iterables.<ReplaceEdit>addAll(replaceEdits, _map);
}
};
changeSerializer.applyModifications(_function);
boolean _isCanceled_1 = monitor.isCanceled();
if (_isCanceled_1) {
throw new OperationCanceledException();
}
final Provider<LinkedPositionGroup> _function_1 = () -> {
return this.createLinkedGroupFromReplaceEdits(replaceEdits, editor, oldName, progress.newChild(10));
};
return _function_1;
}
Aggregations