/** * 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; }
/** * 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; }
/** * 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 */ private 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 rangeEnd= end(range); if (first == -1 && rangeEnd > 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 ranges.subList(first, last + 1); }
/** * 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 */ private 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 rangeEnd= end(range); if (first == -1 && rangeEnd > 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 ranges.subList(first, last + 1); }
/** * Returns the revision range that contains the given line, or * <code>null</code> if there is none. * * @param line the line of interest * @return the corresponding <code>RevisionRange</code> or <code>null</code> */ private RevisionRange getRange(int line) { List<RevisionRange> ranges= getRangeCache(); if (ranges.isEmpty() || line == -1) return null; for (Iterator<RevisionRange> it= ranges.iterator(); it.hasNext();) { RevisionRange range= it.next(); if (contains(range, line)) return range; } // line may be right after the last region RevisionRange lastRegion= ranges.get(ranges.size() - 1); if (line == end(lastRegion)) return lastRegion; return null; }
/** * Returns the revision range that contains the given line, or * <code>null</code> if there is none. * * @param line the line of interest * @return the corresponding <code>RevisionRange</code> or <code>null</code> */ private RevisionRange getRange(int line) { List<RevisionRange> ranges= getRangeCache(); if (ranges.isEmpty() || line == -1) return null; for (RevisionRange range : ranges) { if (contains(range, line)) return range; } // line may be right after the last region RevisionRange lastRegion= ranges.get(ranges.size() - 1); if (line == end(lastRegion)) return lastRegion; return null; }
if (fViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) fViewer; int modelEndLine= end(range); for (int modelLine= range.getStartLine(); modelLine < modelEndLine; modelLine++) { int widgetLine= extension.modelLine2WidgetLine(modelLine); int visibleEndLine= document.getLineOfOffset(region.getOffset() + region.getLength()); widgetStartLine= Math.max(0, range.getStartLine() - visibleStartLine); widgetEndLine= Math.min(visibleEndLine, end(range) - 1); } catch (BadLocationException x) {
if (fViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) fViewer; int modelEndLine= end(range); for (int modelLine= range.getStartLine(); modelLine < modelEndLine; modelLine++) { int widgetLine= extension.modelLine2WidgetLine(modelLine); int visibleEndLine= document.getLineOfOffset(region.getOffset() + region.getLength()); widgetStartLine= Math.max(0, range.getStartLine() - visibleStartLine); widgetEndLine= Math.min(visibleEndLine, end(range) - 1); } catch (BadLocationException x) { x.printStackTrace();
/** * Returns the character offset based region of a line range. * * @param lines the line range to convert * @return the character offset range corresponding to <code>range</code> * @throws BadLocationException if the line range is not within the document bounds */ private IRegion toCharRegion(ILineRange lines) throws BadLocationException { IDocument document= fViewer.getDocument(); int offset= document.getLineOffset(lines.getStartLine()); int nextLine= end(lines); int endOffset; if (nextLine >= document.getNumberOfLines()) endOffset= document.getLength(); else endOffset= document.getLineOffset(nextLine); return new Region(offset, endOffset - offset); }
/** * Returns the character offset based region of a line range. * * @param lines the line range to convert * @return the character offset range corresponding to <code>range</code> * @throws BadLocationException if the line range is not within the document bounds */ private IRegion toCharRegion(ILineRange lines) throws BadLocationException { IDocument document= fViewer.getDocument(); int offset= document.getLineOffset(lines.getStartLine()); int nextLine= end(lines); int endOffset; if (nextLine >= document.getNumberOfLines()) endOffset= document.getLength(); else endOffset= document.getLineOffset(nextLine); return new Region(offset, endOffset - offset); }