use of org.eclipse.xtext.util.ReplaceRegion in project xtext-eclipse by eclipse.
the class PartialParsingProcessor method processFile.
@Override
public String processFile(String completeData, String data, int offset, int len, String change) throws Exception {
IParseResult initialParseResult = parser.parse(new StringReader(data));
String newData = applyDelta(data, offset, len, change);
ReplaceRegion replaceRegion = new ReplaceRegion(offset, len, change);
try {
IParseResult reparsed = parser.reparse(initialParseResult, replaceRegion);
IParseResult parsedFromScratch = parser.parse(new StringReader(newData));
assertEqual(data, newData, parsedFromScratch, reparsed);
return newData;
} catch (Throwable e) {
ComparisonFailure throwMe = new ComparisonFailure(e.getMessage(), newData, replaceRegion + DELIM + data);
throwMe.initCause(e);
throw throwMe;
}
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-eclipse by eclipse.
the class AbstractSmokeTest method testSkipNodesInBetweenWithoutResourceSet.
@Test
public void testSkipNodesInBetweenWithoutResourceSet() throws Exception {
for (String string : getSmokeTestModels()) {
LazyLinkingResource resource = createResource(string);
if (resource != null) {
ICompositeNode rootNode = resource.getParseResult().getRootNode();
ReplaceRegion replaceRegion = null;
for (INode node : rootNode.getAsTreeIterable()) {
int offset = node.getTotalOffset();
int length = node.getTotalLength();
if (replaceRegion == null || replaceRegion.getOffset() != offset || replaceRegion.getLength() != length) {
replaceRegion = new ReplaceRegion(offset, length, "");
StringBuilder builder = new StringBuilder(string);
replaceRegion.applyTo(builder);
processModelWithoutResourceSet(builder.toString());
}
}
}
}
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-eclipse by eclipse.
the class OrganizeImportsTest method assertIsOrganizedTo.
protected void assertIsOrganizedTo(final CharSequence model, final CharSequence expected) throws Exception {
final DomainModel domainModel = this._parseHelper.parse(model.toString());
Resource _eResource = domainModel.eResource();
final List<ReplaceRegion> changes = this.importOrganizer.getOrganizedImportChanges(((XtextResource) _eResource));
final StringBuilder builder = new StringBuilder(model);
final Function1<ReplaceRegion, Integer> _function = (ReplaceRegion it) -> {
return Integer.valueOf(it.getOffset());
};
final List<ReplaceRegion> sortedChanges = IterableExtensions.<ReplaceRegion, Integer>sortBy(changes, _function);
ReplaceRegion lastChange = null;
for (final ReplaceRegion it : sortedChanges) {
{
if (((lastChange != null) && (lastChange.getEndOffset() > it.getOffset()))) {
Assert.fail(((("Overlapping text edits: " + lastChange) + " and ") + it));
}
lastChange = it;
}
}
List<ReplaceRegion> _reverse = ListExtensions.<ReplaceRegion>reverse(sortedChanges);
for (final ReplaceRegion it_1 : _reverse) {
int _offset = it_1.getOffset();
int _offset_1 = it_1.getOffset();
int _length = it_1.getLength();
int _plus = (_offset_1 + _length);
builder.replace(_offset, _plus, it_1.getText());
}
Assert.assertEquals(expected.toString(), builder.toString());
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-eclipse by eclipse.
the class DefaultTextEditComposer method getObjectEdits.
protected List<TextEdit> getObjectEdits() {
final Collection<EObject> modifiedObjects = getModifiedObjects();
Collection<EObject> topLevelObjects = EcoreUtil.filterDescendants(modifiedObjects);
Iterable<EObject> containedModifiedObjects = Collections.emptyList();
if (!resource.getContents().isEmpty()) {
final EObject root = resource.getContents().get(0);
containedModifiedObjects = Iterables.filter(topLevelObjects, new Predicate<EObject>() {
@Override
public boolean apply(EObject input) {
return EcoreUtil.isAncestor(root, input);
}
});
}
List<TextEdit> edits = Lists.newArrayListWithExpectedSize(Iterables.size(containedModifiedObjects));
for (EObject modifiedObject : containedModifiedObjects) {
ReplaceRegion replaceRegion = serializer.serializeReplacement(modifiedObject, getSaveOptions());
TextEdit edit = new ReplaceEdit(replaceRegion.getOffset(), replaceRegion.getLength(), replaceRegion.getText());
edits.add(edit);
}
return edits;
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-eclipse by eclipse.
the class XbaseReferenceUpdater method processReferringResource.
@Override
protected void processReferringResource(Resource referringResource, Iterable<IReferenceDescription> referenceDescriptions, ElementRenameArguments elementRenameArguments, IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
ImportAwareUpdateAcceptor importAwareUpdateAcceptor = createUpdateAcceptor(referringResource, updateAcceptor);
Iterable<IReferenceDescription> importTypeReferences = getImportTypeReferences(referenceDescriptions);
super.processReferringResource(referringResource, importTypeReferences, elementRenameArguments, importAwareUpdateAcceptor, monitor);
importAwareUpdateAcceptor.getImportSection().update();
Iterable<IReferenceDescription> notImportTypeReferences = getNotImportTypeReferences(referenceDescriptions);
super.processReferringResource(referringResource, notImportTypeReferences, elementRenameArguments, importAwareUpdateAcceptor, monitor);
List<ReplaceRegion> importChanges = importAwareUpdateAcceptor.getImportSection().rewrite();
TextEdit importChangeEdit = replaceConverter.convertToTextEdit(importChanges);
if (importChangeEdit != null)
updateAcceptor.accept(referringResource.getURI(), importChangeEdit);
}
Aggregations