Java 类org.eclipse.xtext.formatting2.regionaccess.ILineRegion 实例源码

项目:xtext-core    文件:AbstractRegionAccess.java   
@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);
}
项目:xtext-core    文件:LineRegion.java   
@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);
}
项目:xtext-core    文件:LineRegion.java   
@Override
public ILineRegion getPreviousLine() {
    ITextRegionAccess access = getTextRegionAccess();
    int end = getOffset() - 1;
    String text = access.regionForDocument().getText();
    while (true) {
        if (end < 0)
            return null;
        char c = text.charAt(end);
        if (c == '\n' || c == '\r')
            end--;
        else
            break;
    }
    int start = text.lastIndexOf('\n', end);
    if (start < 0)
        start = 0;
    return new LineRegion(access, start, end - start);
}
项目:n4js    文件:FormatterXpectMethod.java   
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;
}
项目:xtext-core    文件:TextRegionsInTextToString.java   
public ITextSegment getFrame() {
    if (this.frame != null)
        return this.frame;
    ITextRegionAccess access = getTextRegionAccess();
    if (access != null) {
        ITextSegment impactRegion = TextRegions.merge(this.items);
        List<ILineRegion> expandToLines = TextRegions.expandToLines(impactRegion, getLeadingLines(),
                getTrailingLines());
        return TextRegions.merge(expandToLines);
    }
    return null;
}
项目:xtext-core    文件:TextRegionsWithTitleToString.java   
public ITextSegment getFrame() {
    if (this.frame != null)
        return this.frame;
    ITextRegionAccess access = getTextRegionAccess();
    if (access != null) {
        List<ITextSegment> segments = Lists.newArrayList();
        for (Item item : items)
            segments.add(item.getRegion());
        ITextSegment impactRegion = merge(segments);
        List<ILineRegion> expandToLines = expandToLines(impactRegion, getLeadingLines(), getTrailingLines());
        return merge(expandToLines);
    }
    return null;
}
项目:xtext-core    文件:AbstractTextSegment.java   
@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;
}