use of org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff in project xtext-core by eclipse.
the class StringBasedTextRegionAccessDiffBuilder method create.
@Override
public StringBasedTextRegionAccessDiff create() {
StringBasedTextRegionAccessDiffAppender appender = createAppender();
IEObjectRegion root = original.regionForRootEObject();
appender.copyAndAppend(root.getPreviousHiddenRegion(), PREVIOUS);
appender.copyAndAppend(root.getPreviousHiddenRegion(), CONTAINER);
List<Rewrite> rws = createList();
IHiddenRegion last = null;
for (Rewrite rw : rws) {
boolean diff = rw.isDiff();
if (diff) {
appender.beginDiff();
}
if (rw instanceof Insert) {
Insert ins = (Insert) rw;
IHiddenRegion f = ins.getInsertFirst();
IHiddenRegion l = ins.getInsertLast();
appender.copyAndAppend(f, NEXT);
if (f != l) {
appender.copyAndAppend(f.getNextSemanticRegion(), l.getPreviousSemanticRegion());
}
appender.copyAndAppend(l, PREVIOUS);
}
if (diff) {
appender.endDiff();
}
if (rw.originalLast != last) {
appender.copyAndAppend(rw.originalLast, CONTAINER);
}
last = rw.originalLast;
}
appender.copyAndAppend(root.getNextHiddenRegion(), NEXT);
StringBasedTextRegionAccessDiff result = appender.finish();
AbstractEObjectRegion newRoot = result.regionForEObject(root.getSemanticElement());
result.setRootEObject(newRoot);
return result;
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff in project xtext-core by eclipse.
the class RegionAccessTestHelper method modify.
public ITextRegionAccess modify(final ITextRegionAccess base, final Procedure1<? super ITextRegionDiffBuilder> modify) {
final StringBasedTextRegionAccessDiffBuilder fac = new StringBasedTextRegionAccessDiffBuilder(base);
modify.apply(fac);
final StringBasedTextRegionAccessDiff modified = fac.create();
return modified;
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff in project xtext-core by eclipse.
the class StringBasedTextRegionAccessDiffAppender method finish.
public StringBasedTextRegionAccessDiff finish() {
if (this.last instanceof ISemanticRegion) {
appendHiddenRegion(false);
}
updateEObjectRegions();
if (diffFirstOriginal != null && diffFirstCopy != null && diffFirstCopy != null) {
IHiddenRegion orig = result.getOriginalTextRegionAccess().regionForRootEObject().getNextHiddenRegion();
result.append(new SequentialRegionDiff(diffFirstOriginal, orig, diffFirstCopy, this.last));
diffFirstCopy = null;
diffFirstOriginal = null;
}
return result;
}
Aggregations