use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess 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.ITextRegionAccess 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));
}
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class Serializer method serialize.
protected void serialize(EObject obj, Appendable appendable, SaveOptions options) throws IOException {
ITextRegionAccess regionAccess = serializeToRegions(obj);
FormatterRequest request = formatterRequestProvider.get();
request.setFormatUndefinedHiddenRegionsOnly(!options.isFormatting());
request.setTextRegionAccess(regionAccess);
IFormatter2 formatter2 = formatter2Provider.get();
List<ITextReplacement> replacements = formatter2.format(request);
regionAccess.getRewriter().renderToAppendable(replacements, appendable);
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class Serializer method serializeToRegions.
public ITextRegionAccess serializeToRegions(EObject obj) {
checkNotNull(obj, "obj must not be null.");
ISerializationContext context = getIContext(obj);
TextRegionAccessBuilder builder = textRegionBuilderProvider.get();
ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
serialize(context, obj, builder.forSequence(context, obj), errors);
ITextRegionAccess regionAccess = builder.create();
return regionAccess;
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project n4js by eclipse.
the class FormatterXpectMethod method getRegionForLines.
private ITextSegment getRegionForLines(ITextRegionAccess regions, int offset, int lines) {
ILineRegion firstLine = regions.regionForLineAtOffset(offset);
ILineRegion lastLine = firstLine;
for (int i = 1; i < lines; i++) {
ILineRegion next = lastLine.getNextLine();
if (next != null) {
lastLine = next;
} else {
break;
}
}
int firstLineOffset = firstLine.getOffset();
ITextSegment region = regions.regionForOffset(firstLineOffset, (lastLine.getEndOffset() - firstLineOffset) + 1);
return region;
}
Aggregations