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 TextRegionAccessToString method toTokenAndGapList.
protected List<ITextSegment> toTokenAndGapList() {
final int range = this.hightlightOrigin ? 4 : (Integer.MAX_VALUE / 2);
ITextSegment first = null;
{
ITextSegment current = origin;
for (int i = 0; i < range && current != null; i++) {
first = current;
if (current instanceof ITextRegionAccess)
current = ((ITextRegionAccess) current).regionForRootEObject().getPreviousHiddenRegion();
else if (current instanceof ISequentialRegion)
current = ((ISequentialRegion) current).getPreviousHiddenRegion();
else if (current instanceof IHiddenRegionPart)
current = ((IHiddenRegionPart) current).getHiddenRegion();
else
throw new IllegalStateException("Unexpected Type: " + current.getClass());
}
}
if (first == null)
return Collections.emptyList();
List<ITextSegment> result = Lists.newArrayList();
{
ITextSegment current = first;
for (int i = 0; i <= (range * 2) && current != null; i++) {
result.add(current);
if (current instanceof ISemanticRegion)
current = ((ISemanticRegion) current).getNextHiddenRegion();
else if (current instanceof IHiddenRegion)
current = ((IHiddenRegion) current).getNextSemanticRegion();
else
throw new IllegalStateException("Unexpected Type: " + current.getClass());
}
}
return result;
}
use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion in project xtext-core by eclipse.
the class TextRegionAccessToString method toString.
@Override
public String toString() {
List<ITextSegment> list = toTokenAndGapList();
if (list.isEmpty())
return "(empty)";
ITextRegionAccess access = list.get(0).getTextRegionAccess();
DiffColumn diff = new DiffColumn(access);
TextRegionListToString result = new TextRegionListToString();
if (!hideColumnExplanation) {
if (diff.isDiff()) {
result.add("Columns: 1:offset 2:length 3:diff 4:kind 5: text 6:grammarElement", false);
} else {
result.add("Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement", false);
}
result.add("Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion", false);
result.add("", false);
}
appendRegions(result, list, diff, false);
diff.appendDiffs(result, this);
return result.toString();
}
use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion in project xtext-core by eclipse.
the class FormattableDocument method interior.
@Override
public <T extends EObject> T interior(T object, Procedure1<? super IHiddenRegionFormatter> init) {
if (object != null) {
IEObjectRegion objRegion = getTextRegionAccess().regionForEObject(object);
if (objRegion != null) {
IHiddenRegion previous = objRegion.getPreviousHiddenRegion();
IHiddenRegion next = objRegion.getNextHiddenRegion();
if (previous != null && next != null && previous != next) {
interior(previous.getNextSemanticRegion(), next.getPreviousSemanticRegion(), init);
}
}
}
return object;
}
use of org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion in project xtext-core by eclipse.
the class FormattableDocument method prepend.
@Override
public <T extends EObject> T prepend(T owner, Procedure1<? super IHiddenRegionFormatter> before) {
if (owner != null) {
IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
if (region != null) {
IHiddenRegion gap = region.getPreviousHiddenRegion();
set(gap, before);
}
}
return owner;
}
Aggregations