Java 类org.eclipse.jface.text.source.ILineRange 实例源码

项目:codelens-eclipse    文件:LineNumberChangeRulerColumnPatch.java   
@Override
public Object invoke(Object obj, Method thisMethod, Method proceed, Object[] args) throws Throwable {
    if ("createControl".equals(thisMethod.getName())) {
        CompositeRuler parentRuler = (CompositeRuler) args[0];
        this.fCachedTextViewer = parentRuler.getTextViewer();
        this.fCachedTextWidget = fCachedTextViewer.getTextWidget();
    } else if ("setDisplayMode".equals(thisMethod.getName())) {
        this.fCharacterDisplay = (boolean) args[0];
    } else if ("doPaint".equals(thisMethod.getName()) && args.length > 1) {
        GC gc = (GC) args[0];
        ILineRange visibleLines = (ILineRange) args[1];

        if (fRevisionPainter == null) {
            fRevisionPainter = getValue("fRevisionPainter", obj);
            fDiffPainter = getValue("fDiffPainter", obj);
        }

        LineNumberChangeRulerColumn l = ((LineNumberChangeRulerColumn) obj);
        doPaint(gc, visibleLines, l);
        return null;
    }
    return proceed.invoke(obj, args);
}
项目:codelens-eclipse    文件:LineNumberChangeRulerColumnPatch.java   
void doPaint(GC gc, ILineRange visibleLines, LineNumberChangeRulerColumn l) {
    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 (l.isShowingLineNumbers() || fCharacterDisplay)
        doPaintPatch(gc, visibleLines, l);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaMoveLinesAction.java   
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);
}
项目:Eclipse-Postfix-Code-Completion    文件:IndentUtil.java   
/**
 * 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;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaMoveLinesAction.java   
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);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:IndentUtil.java   
/**
 * 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;
}
项目:Pydev    文件:PyMoveLineAction.java   
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);
}
项目:APICloud-Studio    文件:CommonLineNumberChangeRulerColumn.java   
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);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaMoveLinesAction.java   
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);
}
项目:Eclipse-Postfix-Code-Completion    文件:IndentUtil.java   
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;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaMoveLinesAction.java   
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);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:IndentUtil.java   
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;
}
项目:Pydev    文件:PyMoveLineAction.java   
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);
}
项目:codelens-eclipse    文件:LineNumberChangeRulerColumnPatch.java   
/**
 * Draws the ruler column.
 *
 * @param gc
 *            the GC to draw into
 * @param visibleLines
 *            the visible model lines
 * @since 3.2
 */
void doPaintPatch(GC gc, ILineRange visibleLines, LineNumberChangeRulerColumn l) {
    Display display = fCachedTextWidget.getDisplay();

    // draw diff info
    int y = -JFaceTextUtil.getHiddenTopLinePixels(fCachedTextWidget);

    // add empty lines if line is wrapped
    boolean isWrapActive = fCachedTextWidget.getWordWrap();

    int lastLine = end(visibleLines);
    for (int line = visibleLines.getStartLine(); line < lastLine; line++) {
        int widgetLine = JFaceTextUtil.modelLineToWidgetLine(fCachedTextViewer, line);
        if (widgetLine == -1)
            continue;

        final int offsetAtLine = fCachedTextWidget.getOffsetAtLine(widgetLine);
        // START PATCH
        // int lineHeight=
        // fCachedTextWidget.getLineHeight(offsetAtLine);
        int lineHeight = JFaceTextUtil.computeLineHeight(fCachedTextWidget, widgetLine, widgetLine + 1, 1);
        // END PATCH
        paintLine(line, y, lineHeight, gc, display, l);

        // increment y position
        if (!isWrapActive) {
            y += lineHeight;
        } else {
            int charCount = fCachedTextWidget.getCharCount();
            if (offsetAtLine == charCount)
                continue;

            // end of wrapped line
            final int offsetEnd = offsetAtLine + fCachedTextWidget.getLine(widgetLine).length();

            if (offsetEnd == charCount)
                continue;

            // use height of text bounding because bounds.width changes
            // on
            // word wrap
            y += fCachedTextWidget.getTextBounds(offsetAtLine, offsetEnd).height;
        }
    }
}
项目:codelens-eclipse    文件:LineNumberChangeRulerColumnPatch.java   
private static int end(ILineRange range) {
    return range.getStartLine() + range.getNumberOfLines();
}
项目:Eclipse-Postfix-Code-Completion    文件:IndentUtil.java   
/**
 * 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;

}
项目:Eclipse-Postfix-Code-Completion    文件:AnnotationExpandHover.java   
public Object getHoverInfo(ISourceViewer sourceViewer, ILineRange lineRange, int visibleLines) {
    return getHoverInfoForLine(sourceViewer, lineRange.getStartLine());
}
项目:Eclipse-Postfix-Code-Completion    文件:AnnotationExpandHover.java   
public ILineRange getHoverLineRange(ISourceViewer viewer, int lineNumber) {
    return new LineRange(lineNumber, 1);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:IndentUtil.java   
/**
 * 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;

}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AnnotationExpandHover.java   
public Object getHoverInfo(ISourceViewer sourceViewer, ILineRange lineRange, int visibleLines) {
    return getHoverInfoForLine(sourceViewer, lineRange.getStartLine());
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AnnotationExpandHover.java   
public ILineRange getHoverLineRange(ISourceViewer viewer, int lineNumber) {
    return new LineRange(lineNumber, 1);
}