Search in sources :

Example 1 with StringBasedTextRegionAccessDiff

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;
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)

Example 2 with StringBasedTextRegionAccessDiff

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;
}
Also used : StringBasedTextRegionAccessDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder) StringBasedTextRegionAccessDiff(org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff)

Example 3 with StringBasedTextRegionAccessDiff

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;
}
Also used : IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Aggregations

IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)2 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)1 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)1 StringBasedTextRegionAccessDiff (org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff)1 StringBasedTextRegionAccessDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder)1