use of org.eclipse.xtext.formatting2.regionaccess.ILineRegion in project xtext-core by eclipse.
the class AbstractRegionAccess method regionForLineAtOffset.
@Override
public ILineRegion regionForLineAtOffset(int offset) {
String text = getText();
if (offset < 0 || offset > text.length())
return null;
int start = text.lastIndexOf('\n', offset) + 1;
if (start < 0)
start = 0;
int end = text.indexOf('\n', offset + 1);
if (end > 0) {
if (text.charAt(end - 1) == '\r')
end = end - 1;
} else
end = text.length();
return new LineRegion(this, start, end - start);
}
use of org.eclipse.xtext.formatting2.regionaccess.ILineRegion in project xtext-core by eclipse.
the class AbstractTextSegment method getLineRegions.
@Override
public List<ILineRegion> getLineRegions() {
ILineRegion current = getTextRegionAccess().regionForLineAtOffset(getOffset());
List<ILineRegion> result = Lists.newArrayList();
int endOffset = getEndOffset();
while (current != null) {
result.add(current);
if (current.getEndOffset() >= endOffset)
return result;
current = current.getNextLine();
if (current == null || current.getOffset() >= endOffset)
return result;
}
return result;
}
use of org.eclipse.xtext.formatting2.regionaccess.ILineRegion in project xtext-core by eclipse.
the class LineRegion method getNextLine.
@Override
public ILineRegion getNextLine() {
ITextRegionAccess access = getTextRegionAccess();
int start = getEndOffset() + 1;
String text = access.regionForDocument().getText();
while (true) {
if (start >= text.length())
return null;
char c = text.charAt(start);
if (c == '\n' || c == '\r')
start++;
else
break;
}
int end = text.indexOf('\n', start);
if (end > 0) {
if (text.charAt(end - 1) == '\r')
end = end - 1;
} else
end = text.length();
return new LineRegion(access, start, end - start);
}
Aggregations