org.eclipse.jface.text.source.ILineRange Java Examples

The following examples show how to use org.eclipse.jface.text.source.ILineRange. 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: PyMoveLineAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private IRegion getRegion(IDocument document, ILineRange lineRange) throws BadLocationException {
    final int startLine = lineRange.getStartLine();
    int offset = document.getLineOffset(startLine);
    final int numberOfLines = lineRange.getNumberOfLines();
    if (numberOfLines < 1) {
        return new Region(offset, 0);
    }
    int endLine = startLine + numberOfLines - 1;
    int endOffset;
    boolean blockSelectionModeEnabled = false;
    try {
        blockSelectionModeEnabled = ((AbstractTextEditor) getTextEditor()).isBlockSelectionModeEnabled();
    } catch (Throwable e) {
        //Ignore (not available before 3.5)
    }
    if (blockSelectionModeEnabled) {
        // in block selection mode, don't select the last delimiter as we count an empty selected line
        IRegion endLineInfo = document.getLineInformation(endLine);
        endOffset = endLineInfo.getOffset() + endLineInfo.getLength();
    } else {
        endOffset = document.getLineOffset(endLine) + document.getLineLength(endLine);
    }
    return new Region(offset, endOffset - offset);
}
 
Example #2
Source File: RevisionInformationSupport.java    From jdt-codemining with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the sublist of all <code>RevisionRange</code>s that intersect with the given lines.
 *
 * @param lines the model based lines of interest
 * @return elementType: RevisionRange
 */
public List<RevisionRange> getRanges(ILineRange lines) {
	List<RevisionRange> ranges= getRangeCache();

	// return the interesting subset
	int end= end(lines);
	int first= -1, last= -1;
	for (int i= 0; i < ranges.size(); i++) {
		RevisionRange range= ranges.get(i);
		int rangeStart = range.getStartLine();
		int rangeEnd= end(range);
		if (first == -1 && (rangeEnd > lines.getStartLine() && rangeStart <= lines.getStartLine()))
			first= i;
		if (first != -1 && rangeEnd > end) {
			last= i;
			break;
		}
	}
	if (first == -1)
		return Collections.emptyList();
	if (last == -1)
		last= ranges.size() - 1; // bottom index may be one too much
		//return Collections.emptyList();

	return ranges.subList(first, last + 1);
}
 
Example #3
Source File: IndentUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Indents the line range specified by <code>lines</code> in
 * <code>document</code>. The passed Java project may be
 * <code>null</code>, it is used solely to obtain formatter preferences.
 *
 * @param document the document to be changed
 * @param lines the line range to be indented
 * @param project the Java project to get the formatter preferences from, or
 *        <code>null</code> if global preferences should be used
 * @param result the result from a previous call to <code>indentLines</code>,
 *        in order to maintain comment line properties, or <code>null</code>.
 *        Note that the passed result may be changed by the call.
 * @return an indent result that may be queried for changes and can be
 *         reused in subsequent indentation operations
 * @throws BadLocationException if <code>lines</code> is not a valid line
 *         range on <code>document</code>
 */
public static IndentResult indentLines(IDocument document, ILineRange lines, IJavaProject project, IndentResult result) throws BadLocationException {
	int numberOfLines= lines.getNumberOfLines();

	if (numberOfLines < 1)
		return new IndentResult(null);

	result= reuseOrCreateToken(result, numberOfLines);

	JavaHeuristicScanner scanner= new JavaHeuristicScanner(document);
	JavaIndenter indenter= new JavaIndenter(document, scanner, project);
	boolean changed= false;
	int tabSize= CodeFormatterUtil.getTabWidth(project);
	for (int line= lines.getStartLine(), last= line + numberOfLines, i= 0; line < last; line++) {
		changed |= indentLine(document, line, indenter, scanner, result.commentLinesAtColumnZero, i++, tabSize);
	}
	result.hasChanged= changed;

	return result;
}
 
Example #4
Source File: JavaMoveLinesAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IRegion getRegion(IDocument document, ILineRange lineRange) throws BadLocationException {
	final int startLine= lineRange.getStartLine();
	int offset= document.getLineOffset(startLine);
	final int numberOfLines= lineRange.getNumberOfLines();
	if (numberOfLines < 1)
		return new Region(offset, 0);
	int endLine= startLine + numberOfLines - 1;
	int endOffset;
	if (fSharedState.fEditor.isBlockSelectionModeEnabled()) {
		// in block selection mode, don't select the last delimiter as we count an empty selected line
		IRegion endLineInfo= document.getLineInformation(endLine);
		endOffset= endLineInfo.getOffset() + endLineInfo.getLength();
	} else {
		endOffset= document.getLineOffset(endLine) + document.getLineLength(endLine);
	}
	return new Region(offset, endOffset - offset);
}
 
Example #5
Source File: BookmarkRulerColumn.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Draws the ruler column.
 *
 * @param gc the GC to draw into
 * @param visibleLines the visible model lines
 */
private void doPaint(GC gc, ILineRange visibleLines) {
    Display display= fCachedTextWidget.getDisplay();
    
    int lastLine = visibleLines.getStartLine() + visibleLines.getNumberOfLines();
    int y        = -JFaceTextUtil.getHiddenTopLinePixels(fCachedTextWidget);
    
    if (mapMarks != null) {
        for (int line= visibleLines.getStartLine(); line < lastLine; line++) {
            int widgetLine= JFaceTextUtil.modelLineToWidgetLine(fCachedTextViewer, line);
            if (widgetLine == -1)
                continue;
            int lineHeight= fCachedTextWidget.getLineHeight(fCachedTextWidget.getOffsetAtLine(widgetLine));

            if (mapMarks != null && mapMarks.containsKey(line)) {
                paintLine(line, mapMarks.get(line), y, lineHeight, gc, display);
            }
            y += lineHeight;
        }
    }
}
 
Example #6
Source File: CommonLineNumberChangeRulerColumn.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
void doPaint(GC gc, ILineRange visibleLines) {
	Color foreground= gc.getForeground();
	if (visibleLines != null) {
		if (fRevisionPainter.hasInformation())
			fRevisionPainter.paint(gc, visibleLines);
		else if (fDiffPainter.hasInformation()) // don't paint quick diff colors if revisions are painted
			fDiffPainter.paint(gc, visibleLines);
	}
	gc.setForeground(foreground);
	if (fShowNumbers || fCharacterDisplay)
		super.doPaint(gc, visibleLines);
}
 
Example #7
Source File: PyMoveLineAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private ILineRange getLineRange(IDocument document, ICoreTextSelection selection) throws BadLocationException {
    final int offset = selection.getOffset();
    int startLine = document.getLineOfOffset(offset);
    int endOffset = offset + selection.getLength();
    int endLine = document.getLineOfOffset(endOffset);
    final int nLines = endLine - startLine + 1;
    return new LineRange(startLine, nLines);
}
 
Example #8
Source File: IndentUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static int getLeftMostLine(IDocument document, ILineRange lines, int tabSize) throws BadLocationException {
	int numberOfLines= lines.getNumberOfLines();
	int first= lines.getStartLine();
	int minLine= -1;
	int minIndent= Integer.MAX_VALUE;
	for (int line= 0; line < numberOfLines; line++) {
		int length= computeVisualLength(getCurrentIndent(document, line + first), tabSize);
		if (length < minIndent) {
			minIndent= length;
			minLine= line;
		}
	}
	return minLine;
}
 
Example #9
Source File: JavaMoveLinesAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ILineRange getLineRange(IDocument document, ITextSelection selection) throws BadLocationException {
	final int offset= selection.getOffset();
	int startLine= document.getLineOfOffset(offset);
	int endOffset= offset + selection.getLength();
	int endLine= document.getLineOfOffset(endOffset);
	final int nLines= endLine - startLine + 1;
	return new LineRange(startLine, nLines);
}
 
Example #10
Source File: Utils.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
public static ILineRange getLineRange(IJavaElement element, IDocument document)
		throws JavaModelException, BadLocationException {
	ISourceRange r = ((ISourceReference) element).getSourceRange();
	int offset = r.getOffset();
	int startLine = document.getLineOfOffset(offset);
	int endLine = document.getLineOfOffset(offset + r.getLength());
	return new LineRange(startLine, endLine - startLine);
}
 
Example #11
Source File: JavaElementCodeMiningProvider.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public List<RevisionRange> getRanges(ILineRange lines) {
	if (fRevisionInfoSupport == null) {
		initRevisionSupport(fViewer, fUnit);
	}
	return fRevisionInfoSupport != null ? fRevisionInfoSupport.getRanges(lines) : null;
}
 
Example #12
Source File: RevisionAuthorsCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
public RevisionAuthorsCodeMining(int beforeLineNumber, ILineRange lineRange, IDocument document,
		ICodeMiningProvider provider, IRevisionRangeProvider rangeProvider)
		throws JavaModelException, BadLocationException {
	super(beforeLineNumber, document, provider);
	this.lineRange = lineRange;
	this.rangeProvider = rangeProvider;
	if (rangeProvider.isInitialized()) {
		updateLabel();
	}
}
 
Example #13
Source File: RevisionRecentChangeCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
public RevisionRecentChangeCodeMining(int beforeLineNumber, ILineRange lineRange, IDocument document,
		boolean showAvatar, boolean showDate, ICodeMiningProvider provider, IRevisionRangeProvider rangeProvider)
		throws JavaModelException, BadLocationException {
	super(beforeLineNumber, document, provider);
	this.rangeProvider = rangeProvider;
	this.lineRange = lineRange;
	this.showAvatar = showAvatar;
	this.showDate = showDate;
	if (rangeProvider.isInitialized()) {
		updateLabel();
	}
}
 
Example #14
Source File: IndentUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Shifts the line range specified by <code>lines</code> in
 * <code>document</code>. The amount that the lines get shifted
 * are determined by the first line in the range, all subsequent
 * lines are adjusted accordingly. The passed Java project may be
 * <code>null</code>, it is used solely to obtain formatter
 * preferences.
 *
 * @param document the document to be changed
 * @param lines the line range to be shifted
 * @param project the Java project to get the formatter preferences
 *        from, or <code>null</code> if global preferences should
 *        be used
 * @param result the result from a previous call to
 *        <code>shiftLines</code>, in order to maintain comment
 *        line properties, or <code>null</code>. Note that the
 *        passed result may be changed by the call.
 * @return an indent result that may be queried for changes and can
 *         be reused in subsequent indentation operations
 * @throws BadLocationException if <code>lines</code> is not a
 *         valid line range on <code>document</code>
 */
public static IndentResult shiftLines(IDocument document, ILineRange lines, IJavaProject project, IndentResult result) throws BadLocationException {
	int numberOfLines= lines.getNumberOfLines();

	if (numberOfLines < 1)
		return new IndentResult(null);

	result= reuseOrCreateToken(result, numberOfLines);
	result.hasChanged= false;

	JavaHeuristicScanner scanner= new JavaHeuristicScanner(document);
	JavaIndenter indenter= new JavaIndenter(document, scanner, project);

	String current= getCurrentIndent(document, lines.getStartLine());
	StringBuffer correct= indenter.computeIndentation(document.getLineOffset(lines.getStartLine()));
	if (correct == null)
		return result; // bail out

	int tabSize= CodeFormatterUtil.getTabWidth(project);
	StringBuffer addition= new StringBuffer();
	int difference= subtractIndent(correct, current, addition, tabSize);

	if (difference == 0)
		return result;

	if (result.leftmostLine == -1)
		result.leftmostLine= getLeftMostLine(document, lines, tabSize);

	int maxReduction= computeVisualLength(getCurrentIndent(document, result.leftmostLine + lines.getStartLine()), tabSize);

	if (difference > 0) {
		for (int line= lines.getStartLine(), last= line + numberOfLines, i= 0; line < last; line++)
			addIndent(document, line, addition, result.commentLinesAtColumnZero, i++);
	} else {
		int reduction= Math.min(-difference, maxReduction);
		for (int line= lines.getStartLine(), last= line + numberOfLines, i= 0; line < last; line++)
			cutIndent(document, line, reduction, tabSize, result.commentLinesAtColumnZero, i++);
	}

	result.hasChanged= true;

	return result;

}
 
Example #15
Source File: AnnotationExpandHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public Object getHoverInfo(ISourceViewer sourceViewer, ILineRange lineRange, int visibleLines) {
	return getHoverInfoForLine(sourceViewer, lineRange.getStartLine());
}
 
Example #16
Source File: AnnotationExpandHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public ILineRange getHoverLineRange(ISourceViewer viewer, int lineNumber) {
	return new LineRange(lineNumber, 1);
}
 
Example #17
Source File: IRevisionRangeProvider.java    From jdt-codemining with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the sublist of all <code>RevisionRange</code>s that intersect with
 * the given lines.
 *
 * @param lines the model based lines of interest
 * @return elementType: RevisionRange
 */
List<RevisionRange> getRanges(ILineRange lines);
 
Example #18
Source File: RevisionInformationSupport.java    From jdt-codemining with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Computes the end index of a line range.
 *
 * @param range a line range
 * @return the last line (exclusive) of <code>range</code>
 */
private static int end(ILineRange range) {
	return range.getStartLine() + range.getNumberOfLines();
}
 
Example #19
Source File: RevisionInformationSupport.java    From jdt-codemining with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns <code>true</code> if <code>range</code> contains <code>line</code>. A
 * line is not contained in a range if it is the range's exclusive end line.
 *
 * @param range the range to check whether it contains <code>line</code>
 * @param line  the line the line
 * @return <code>true</code> if <code>range</code> contains <code>line</code>,
 *         <code>false</code> if not
 */
private static boolean contains(ILineRange range, int line) {
	return range.getStartLine() <= line && end(range) > line;
}