use of org.eclipse.xtext.formatting2.regionaccess.ITextSegment in project xtext-core by eclipse.
the class TextReplacerContext method getRegion.
protected ITextSegment getRegion(int index) {
ITextReplacerContext current = this;
while (current != null) {
ITextReplacer replacer2 = current.getReplacer();
if (replacer2 != null) {
if (index == 0) {
return replacer2.getRegion();
} else
index--;
}
current = current.getPreviousContext();
}
return null;
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextSegment in project xtext-core by eclipse.
the class TextReplacerContext method isWrapInRegion.
@Override
public boolean isWrapInRegion() {
ITextRegionAccess access = getDocument().getRequest().getTextRegionAccess();
ITextSegment region = getReplacer().getRegion();
int lastOffset = region.getOffset();
for (ITextReplacement rep : this.getLocalReplacements()) {
int endOffset = rep.getOffset();
String between = access.textForOffset(lastOffset, endOffset - lastOffset);
if (between.contains("\n") || rep.getReplacementText().contains("\n")) {
return true;
}
lastOffset = rep.getEndOffset();
}
String rest = access.textForOffset(lastOffset, region.getEndOffset() - lastOffset);
if (rest.contains("\n")) {
return true;
}
return false;
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextSegment 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.ITextSegment 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.ITextSegment in project xtext-core by eclipse.
the class TextRegionsInTextToString method toString.
@Override
public String toString() {
try {
ITextRegionAccess access = getTextRegionAccess();
ITextSegment frame = getFrame();
if (access == null || frame == null)
return box(title, "(no changes)");
StringBuilder builder = new StringBuilder();
String vizualized = access.getRewriter().renderToString(frame, items);
builder.append(box(title, vizualized));
return builder.toString();
} catch (Exception e) {
return box("error", e.getMessage() + "\n" + Throwables.getStackTraceAsString(e));
}
}
Aggregations