use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder in project xtext-core by eclipse.
the class RegionAccessCommentsTest method testDeleteMiddleRegion.
@Test
public void testDeleteMiddleRegion() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("8");
_builder.newLine();
_builder.append("a /*a*/ //a");
_builder.newLine();
_builder.append("/*b1*/");
_builder.newLine();
_builder.append("/*b2*/");
_builder.newLine();
_builder.append("b");
_builder.newLine();
final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
final ISemanticRegion foo = IterableExtensions.<ISemanticRegion>head(access.regionForRootEObject().getAllRegionsFor().features(RegionaccesstestlanguagePackage.Literals.VALUE_LIST__NAME));
it.remove(foo);
};
ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append(" ");
_builder_1.append("0 0 H");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("B ValueList\'[a, b]\' Root");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("0 1 S \"8\" Root:\'8\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("1 1 H \"\\n\" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("\"/*b1*/\" Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("\"\\n\" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("\"/*b2*/\" Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("15 \"\\n\" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("16 1 S \"b\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("E ValueList\'[a, b]\' Root");
_builder_1.newLine();
_builder_1.append("17 0 H");
_builder_1.newLine();
_builder_1.append("------------ diff 1 ------------");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("1 1 H \"\\n\" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("2 1 S \"a\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("3 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("\"/*a*/\" Comment:TerminalRule\'ML_COMMENT\' Association:PREVIOUS");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("\" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("\"//a\\n\" Comment:TerminalRule\'SL_COMMENT\' Association:PREVIOUS");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("\"/*b1*/\" Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("\"\\n\" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("\"/*b2*/\" Comment:TerminalRule\'ML_COMMENT\' Association:NEXT");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("25 \"\\n\" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder in project xtext-core by eclipse.
the class RegionAccessDiffTest method testEmptyModification.
@Test
public void testEmptyModification() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("1 foo");
_builder.newLine();
final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("0 0 H");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("B Simple\'foo\' Root");
_builder_1.newLine();
_builder_1.append("0 1 S \"1\" Simple:\'1\'");
_builder_1.newLine();
_builder_1.append("1 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("2 3 S \"foo\" Simple:name=ID");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("E Simple\'foo\' Root");
_builder_1.newLine();
_builder_1.append("5 0 H");
_builder_1.newLine();
this._regionAccessTestHelper.operator_tripleEquals(access, _builder_1);
final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
};
ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("0 0 H");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("B Simple\'foo\' Root");
_builder_2.newLine();
_builder_2.append("0 1 S \"1\" Simple:\'1\'");
_builder_2.newLine();
_builder_2.append("1 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_2.newLine();
_builder_2.append("2 3 S \"foo\" Simple:name=ID");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("E Simple\'foo\' Root");
_builder_2.newLine();
_builder_2.append("5 0 H");
_builder_2.newLine();
this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_2);
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder in project xtext-core by eclipse.
the class RegionAccessDiffTest method testMove.
@Test
public void testMove() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("8 a b c");
_builder.newLine();
final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
final List<ISemanticRegion> regions = access.regionForRootEObject().getAllRegionsFor().features(RegionaccesstestlanguagePackage.Literals.VALUE_LIST__NAME);
final ISemanticRegion a = regions.get(0);
final ISemanticRegion b = regions.get(1);
it.move(b.getNextHiddenRegion(), a.getPreviousHiddenRegion(), a.getNextHiddenRegion());
};
ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("0 0 H");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("B ValueList\'[a, b, c]\' Root");
_builder_1.newLine();
_builder_1.append("0 1 S \"8\" Root:\'8\'");
_builder_1.newLine();
_builder_1.append("1 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("2 \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("3 1 S \"b\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append("4 1 2 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("5 1 2 S \"a\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append("6 0 2 H");
_builder_1.newLine();
_builder_1.append("6 1 S \"c\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("E ValueList\'[a, b, c]\' Root");
_builder_1.newLine();
_builder_1.append("7 0 H");
_builder_1.newLine();
_builder_1.append("------------ diff 1 ------------");
_builder_1.newLine();
_builder_1.append("1 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("2 1 S \"a\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append("3 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("------------ diff 2 ------------");
_builder_1.newLine();
_builder_1.append("5 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("6 1 S \"c\" ValueList:name+=ID");
_builder_1.newLine();
this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder in project xtext-core by eclipse.
the class RecordingXtextResourceUpdater method beginRecording.
public ITextRegionDiffBuilder beginRecording(IChangeSerializer serializer, XtextResource resource) {
this.serializer = serializer;
this.snapshot = snapshotProvider.createResourceSnapshot(resource);
this.document = new StringBasedTextRegionAccessDiffBuilder(this.snapshot.getRegions());
EcoreUtil.resolveAll(resource);
this.recorder = new ChangeRecorder(resource);
return this.document;
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder in project xtext-core by eclipse.
the class RelatedXtextResourceUpdater method applyChange.
@Override
public void applyChange(Deltas deltas, IAcceptor<IEmfResourceChange> changeAcceptor) {
XtextResource res = (XtextResource) lifecycleManager.openAndApplyReferences(getResourceSet(), getResource());
if (!referenceUpdater.isAffected(deltas, getResource())) {
return;
}
ITextRegionAccess base = textRegionBuilderProvider.get().forNodeModel(res).create();
ITextRegionDiffBuilder rewriter = new StringBasedTextRegionAccessDiffBuilder(base);
ReferenceUpdaterContext context = new ReferenceUpdaterContext(deltas, rewriter, getResource());
referenceUpdater.update(context);
if (!context.getModifications().isEmpty()) {
ChangeRecorder rec = new ChangeRecorder(res);
for (Runnable run : context.getModifications()) {
run.run();
}
ChangeDescription recording = rec.endRecording();
ResourceSet rs = res.getResourceSet();
ResourceSetRecording tree = changeTreeProvider.createChangeTree(rs, Collections.emptyList(), recording);
ResourceRecording recordedResource = tree.getRecordedResource(res);
if (recordedResource != null) {
serializer.serializeChanges(recordedResource, rewriter);
}
}
for (IUpdatableReference upd : context.getUpdatableReferences()) {
referenceUpdater.updateReference(rewriter, upd);
}
ITextRegionAccessDiff rewritten = rewriter.create();
List<ITextReplacement> rep = formatter.format(rewritten);
TextDocumentChange change = new TextDocumentChange(rewritten, getResource().getUri(), rep);
changeAcceptor.accept(change);
}
Aggregations