use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion in project xtext-core by eclipse.
the class RegionAccessBuilderTest method assertToStringDoesNotCrash.
private void assertToStringDoesNotCrash(final ITextRegionAccess access) {
IHiddenRegion _previousHiddenRegion = access.regionForRootEObject().getPreviousHiddenRegion();
ISequentialRegion current = ((ISequentialRegion) _previousHiddenRegion);
while ((current != null)) {
{
Assert.assertNotNull(current.toString());
boolean _matched = false;
if (current instanceof IHiddenRegion) {
_matched = true;
current = ((IHiddenRegion) current).getNextSemanticRegion();
}
if (!_matched) {
if (current instanceof ISemanticRegion) {
_matched = true;
Assert.assertNotNull(((ISemanticRegion) current).getEObjectRegion().toString());
current = ((ISemanticRegion) current).getNextHiddenRegion();
}
}
}
}
}
use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion in project xtext-core by eclipse.
the class InsertionPointFinder method findInsertionPoint.
public IHiddenRegion findInsertionPoint(ISerializationContext ctx, IEObjectRegion obj, AbstractElement ins) {
ISerState insertionState = findState(ctx, ins);
Set<AbstractElement> followers = collectAdjacent(insertionState, s -> s.getFollowers());
Set<AbstractElement> precendents = collectAdjacent(insertionState, s -> s.getPrecedents());
List<IAstRegion> regions = Lists.newArrayList(obj.getAstRegions());
if (regions.isEmpty()) {
return obj.getPreviousHiddenRegion();
}
if (followers.contains(regions.get(0).getGrammarElement())) {
return obj.getPreviousHiddenRegion();
}
if (precendents.contains(regions.get(regions.size() - 1).getGrammarElement())) {
return obj.getNextHiddenRegion();
}
for (int i = 0; i < regions.size() - 1; i++) {
IAstRegion leading = regions.get(i);
IAstRegion trailing = regions.get(i + 1);
if (precendents.contains(leading.getGrammarElement()) && followers.contains(trailing.getGrammarElement())) {
return leading.getNextHiddenRegion();
}
}
return null;
}
use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion in project xtext-core by eclipse.
the class TextReplacerContext method isInUndefinedRegion.
protected boolean isInUndefinedRegion(ITextReplacement repl) {
ITextSegment replacerRegion = replacer.getRegion();
IHiddenRegion hidden = null;
if (replacerRegion instanceof IHiddenRegionPart) {
hidden = ((IHiddenRegionPart) replacerRegion).getHiddenRegion();
} else if (replacerRegion instanceof IHiddenRegion) {
hidden = (IHiddenRegion) replacerRegion;
}
return hidden == null || hidden.isUndefined();
}
use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion in project xtext-core by eclipse.
the class FormatterTestHelper method assertAllWhitespaceIsFormatted.
protected void assertAllWhitespaceIsFormatted(ITextRegionAccess access, List<ITextReplacement> replacements) {
List<ITextSegment> expected = Lists.newArrayList();
IHiddenRegion current = access.regionForRootEObject().getPreviousHiddenRegion();
while (current != null) {
expected.addAll(current.getMergedSpaces());
current = current.getNextHiddenRegion();
}
List<ITextSegment> missing = TextRegions.difference(expected, replacements);
if (!missing.isEmpty()) {
TextRegionsToString toString = new TextRegionsToString().setTextRegionAccess(access);
for (ITextSegment region : missing) toString.add(region, region.getClass().getSimpleName());
String msg = "The following regions are not formatted:\n" + toString;
System.err.println(msg);
Assert.fail(msg);
}
}
use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion in project xtext-core by eclipse.
the class FormattableDocument method append.
@Override
public <T extends EObject> T append(T owner, Procedure1<? super IHiddenRegionFormatter> after) {
if (owner != null) {
IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
if (region != null) {
IHiddenRegion gap = region.getNextHiddenRegion();
set(gap, after);
}
}
return owner;
}
Aggregations