org.eclipse.xtext.formatting2.regionaccess.ILineRegion Java Examples

The following examples show how to use org.eclipse.xtext.formatting2.regionaccess.ILineRegion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractRegionAccess.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: LineRegion.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: LineRegion.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: FormatterXpectMethod.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: TextRegionsInTextToString.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: TextRegionsWithTitleToString.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: AbstractTextSegment.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example #8
Source File: DocumentationFormatter.java    From sarl with Apache License 2.0 4 votes vote down vote up
public String getLineText(ILineRegion line) {
	ITextSegment segment = this.access.regionForOffset(line.getOffset(), line.getLength());
	return segment.getText();
}
 
Example #9
Source File: DocumentationFormatter.java    From sarl with Apache License 2.0 4 votes vote down vote up
public ILineRegion getFirstLine(int offset) {
	return this.access.regionForLineAtOffset(offset);
}
 
Example #10
Source File: DocumentationFormatter.java    From sarl with Apache License 2.0 4 votes vote down vote up
public ILineRegion getNextLine(ILineRegion currentLine) {
	return currentLine.getNextLine();
}
 
Example #11
Source File: DocumentationFormatter.java    From sarl with Apache License 2.0 4 votes vote down vote up
public int getLineOffset(ILineRegion currentLine) {
	return currentLine.getOffset() - getCommentOffset();
}
 
Example #12
Source File: DocumentationFormatter.java    From sarl with Apache License 2.0 4 votes vote down vote up
public int getLineLength(ILineRegion currentLine) {
	return currentLine.getLength();
}