use of org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion 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.IEObjectRegion in project xtext-core by eclipse.
the class RegionAccessDiffTest method testSerializeRootObject.
@Test
public void testSerializeRootObject() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("3 foo");
_builder.newLine();
final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
final IEObjectRegion root = access.regionForRootEObject();
EObject _semanticElement = root.getSemanticElement();
final Delegate rootObj = ((Delegate) _semanticElement);
rootObj.setName("baaaz");
final ITextRegionAccess textRegions = this.serializer.serializeToRegions(rootObj);
it.replace(root.getPreviousHiddenRegion(), root.getNextHiddenRegion(), textRegions);
};
ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("0 0 1 H");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("B Delegate\'baaaz\' Root");
_builder_1.newLine();
_builder_1.append("0 1 1 S \"3\" Unassigned:\'3\'");
_builder_1.newLine();
_builder_1.append("1 1 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("2 5 1 S \"baaaz\" Delegate:name=ID");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("E Delegate\'baaaz\' Root");
_builder_1.newLine();
_builder_1.append("7 0 1 H");
_builder_1.newLine();
_builder_1.append("------------ diff 1 ------------");
_builder_1.newLine();
_builder_1.append("0 0 H");
_builder_1.newLine();
_builder_1.append("0 1 S \"3\" Unassigned:\'3\'");
_builder_1.newLine();
_builder_1.append("1 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("2 3 S \"foo\" Delegate:name=ID");
_builder_1.newLine();
_builder_1.append("5 0 H");
_builder_1.newLine();
this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
use of org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion in project xtext-core by eclipse.
the class RegionAccessDiffTest method testSerializeChildObject.
@Test
public void testSerializeChildObject() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("2 foo");
_builder.newLine();
final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
EObject _semanticElement = access.regionForRootEObject().getSemanticElement();
final Delegate child = ((Delegation) _semanticElement).getDelegate();
final IEObjectRegion childRegion = access.regionForEObject(child);
child.setName("baaaz");
final ITextRegionAccess textRegions = this.serializer.serializeToRegions(child);
it.replace(childRegion.getPreviousHiddenRegion(), childRegion.getNextHiddenRegion(), textRegions);
};
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 Delegation Root");
_builder_1.newLine();
_builder_1.append("0 1 S \"2\" Delegation:\'2\'");
_builder_1.newLine();
_builder_1.append("1 1 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("B Delegate\'baaaz\' Delegate path:Delegation/delegate");
_builder_1.newLine();
_builder_1.append("2 5 1 S \"baaaz\" Delegate:name=ID");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("E Delegate\'baaaz\' Delegate path:Delegation/delegate");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("E Delegation Root");
_builder_1.newLine();
_builder_1.append("7 0 1 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 3 S \"foo\" Delegate:name=ID");
_builder_1.newLine();
_builder_1.append("5 0 H");
_builder_1.newLine();
this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
use of org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion in project xtext-core by eclipse.
the class SemanticRegionFinderTest method regionForFeatureCrossReference.
@Test
public void regionForFeatureCrossReference() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("6 (ref foo) action (foo) end");
final AssignedAction mixed = this.<AssignedAction>parseAs(_builder, AssignedAction.class);
final IEObjectRegion finder = this.toAccess(mixed).regionForEObject(mixed.getChild());
final ISemanticRegion actual = finder.getRegionFor().feature(RegionaccesstestlanguagePackage.Literals.MIXED__REF);
final List<ISemanticRegion> actuals = finder.getRegionFor().features(RegionaccesstestlanguagePackage.Literals.MIXED__REF);
this.assertEquals("foo", actual, actuals);
}
use of org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion in project xtext-core by eclipse.
the class AbstractFormatter2 method isInRequestedRange.
protected boolean isInRequestedRange(EObject obj) {
Collection<ITextRegion> regions = request.getRegions();
if (regions.isEmpty())
return true;
ITextRegionAccess access = request.getTextRegionAccess();
IEObjectRegion objRegion = access.regionForEObject(obj);
if (objRegion == null)
return false;
IHiddenRegion previousHidden = objRegion.getPreviousHiddenRegion();
IHiddenRegion nextHidden = objRegion.getNextHiddenRegion();
int objOffset = previousHidden != null ? previousHidden.getOffset() : 0;
int objEnd = nextHidden != null ? nextHidden.getEndOffset() : access.regionForRootEObject().getEndOffset();
for (ITextRegion region : regions) {
int regionOffset = region.getOffset();
int regionEnd = regionOffset + region.getLength();
if (regionOffset <= objEnd && regionEnd >= objOffset)
return true;
}
return false;
}
Aggregations