Search in sources :

Example 6 with ILineRegion

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);
}
Also used : ILineRegion(org.eclipse.xtext.formatting2.regionaccess.ILineRegion) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)

Example 7 with ILineRegion

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;
}
Also used : ILineRegion(org.eclipse.xtext.formatting2.regionaccess.ILineRegion)

Example 8 with ILineRegion

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);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ILineRegion(org.eclipse.xtext.formatting2.regionaccess.ILineRegion)

Aggregations

ILineRegion (org.eclipse.xtext.formatting2.regionaccess.ILineRegion)8 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)5 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)3 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)2 IComment (org.eclipse.xtext.formatting2.regionaccess.IComment)1