use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment in project xtext-xtend by eclipse.
the class RichStringFormatter method setSpace.
protected void setSpace(final IFormattableDocument doc, final int offset, final int length, final String space) {
IHiddenRegionFormatting _createHiddenRegionFormatting = doc.getFormatter().createHiddenRegionFormatting();
final Procedure1<IHiddenRegionFormatting> _function = (IHiddenRegionFormatting it) -> {
it.setSpace(space);
};
final IHiddenRegionFormatting fmt = ObjectExtensions.<IHiddenRegionFormatting>operator_doubleArrow(_createHiddenRegionFormatting, _function);
AbstractFormatter2 _formatter = doc.getFormatter();
ITextRegionAccess _textRegionAccess = this._iTextRegionExtensions.getTextRegionAccess();
TextSegment _textSegment = new TextSegment(_textRegionAccess, offset, length);
final ITextReplacer replacer = _formatter.createWhitespaceReplacer(_textSegment, fmt);
doc.addReplacer(replacer);
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment in project xtext-core by eclipse.
the class TextRegions method merge.
public static ITextSegment merge(Iterable<? extends ITextSegment> segments) {
Iterator<? extends ITextSegment> it = segments.iterator();
if (!it.hasNext())
throw new IllegalStateException();
ITextSegment first = it.next();
int minOffset = first.getOffset();
int maxEndOffset = first.getEndOffset();
while (it.hasNext()) {
ITextSegment next = it.next();
int offset = next.getOffset();
int endOffset = next.getEndOffset();
if (offset < minOffset)
minOffset = offset;
if (endOffset > maxEndOffset)
maxEndOffset = endOffset;
}
return new TextSegment(first.getTextRegionAccess(), minOffset, maxEndOffset - minOffset);
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment in project xtext-core by eclipse.
the class SinglelineCommentReplacer method getFirstSpace.
protected ITextSegment getFirstSpace() {
IComment comment = getComment();
String text = comment.getText();
if (!text.startsWith(prefix))
return null;
int start = prefix.length();
for (int i = start; i < text.length(); i++) {
char charAt = text.charAt(i);
if (!Character.isWhitespace(charAt) || charAt == '\r' || charAt == '\n')
return new TextSegment(comment.getTextRegionAccess(), comment.getOffset() + start, i - start);
}
return new TextSegment(comment.getTextRegionAccess(), comment.getOffset() + start, text.length() - start);
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment in project xtext-core by eclipse.
the class AbstractHiddenRegion method collectAlternatingSpaceAndComments.
protected List<ITextSegment> collectAlternatingSpaceAndComments(boolean includeComments) {
List<IHiddenRegionPart> parts = getParts();
if (parts.isEmpty()) {
return Collections.<ITextSegment>singletonList(this);
} else {
ITextSegment lastWhitespace = null;
List<ITextSegment> result = Lists.newArrayList();
for (IHiddenRegionPart part : parts) {
if (part instanceof IWhitespace) {
if (lastWhitespace == null) {
result.add(part);
lastWhitespace = part;
} else {
int mergedLength = lastWhitespace.getLength() + part.getLength();
lastWhitespace = new TextSegment(access, lastWhitespace.getOffset(), mergedLength);
result.set(result.size() - 1, lastWhitespace);
}
} else if (part instanceof IComment) {
if (lastWhitespace == null) {
result.add(new TextSegment(access, part.getOffset(), 0));
} else {
lastWhitespace = null;
}
if (includeComments) {
result.add(part);
}
}
}
if (lastWhitespace == null) {
result.add(new TextSegment(access, getEndOffset(), 0));
}
return ImmutableList.copyOf(result);
}
}
use of org.eclipse.xtext.formatting2.regionaccess.internal.TextSegment in project xtext-core by eclipse.
the class RegionSetTest method testMergeConflic3.
@Test
public void testMergeConflic3() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("issues=mergeConflict:[20,2]<>[21,0]");
_builder.newLine();
_builder.append("set=[[20,2]]");
_builder.newLine();
final Procedure1<TestableTextSegmentSet> _function = (TestableTextSegmentSet it) -> {
TextSegment _textSegment = new TextSegment(null, 21, 0);
it.add(_textSegment);
TextSegment _textSegment_1 = new TextSegment(null, 20, 2);
it.add(_textSegment_1);
};
this.test(_builder, _function);
}
Aggregations