/** * Returns the end offset of the keyword. * * @return the end offset of the keyword */ public int getEnd() { return fPosition.getOffset() + fPosition.getLength(); }
/** * Pretty print a <code>Position</code>. * * @param position the position to format * @return a formatted string */ private String toString(Position position) { return "P[" + position.getOffset() + "+" + position.getLength() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } }
/** * Pretty print a <code>Position</code>. * * @param position the position to format * @return a formatted string */ private String toString(Position position) { return "P[" + position.getOffset() + "+" + position.getLength() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } }
private boolean covers(List<Position> coverage, Position position) { Iterator<Position> e= coverage.iterator(); while (e.hasNext()) { Position p= e.next(); if (p.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= p.getOffset() + p.getLength()) return true; } return false; }
private boolean covers(List<Position> coverage, Position position) { Iterator<Position> e= coverage.iterator(); while (e.hasNext()) { Position p= e.next(); if (p.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= p.getOffset() + p.getLength()) return true; } return false; }
@Override public void apply(IDocument document) { try { document.replace(fReplacementPosition.getOffset(), fReplacementPosition.getLength(), fReplacementString); } catch (BadLocationException x) { // ignore } }
public Diff findDiff(char contributor, Position range) { int start= range.getOffset(); int end= start + range.getLength(); return findDiff(contributor, start, end); }
@Override public void apply(IDocument document) { try { document.replace(fReplacementPosition.getOffset(), fReplacementPosition.getLength(), fReplacementString); } catch (BadLocationException x) { // ignore } }
@Override public IRegion getRangeIndication() { if (fRangeIndicator != null && fVisualAnnotationModel != null) { Position position= fVisualAnnotationModel.getPosition(fRangeIndicator); if (position != null) return new Region(position.getOffset(), position.getLength()); } return null; }
@Override public IRegion getRangeIndication() { if (fRangeIndicator != null && fVisualAnnotationModel != null) { Position position= fVisualAnnotationModel.getPosition(fRangeIndicator); if (position != null) return new Region(position.getOffset(), position.getLength()); } return null; }
/** * Same as {@link #modelRange2WidgetRange(IRegion)} just for a {@link org.eclipse.jface.text.Position}. * * @param modelPosition the position describing a range in the viewer's document * @return a region describing a range in the viewer's widget * @since 2.1 */ protected IRegion modelRange2WidgetRange(Position modelPosition) { return modelRange2WidgetRange(new Region(modelPosition.getOffset(), modelPosition.getLength())); }
@Override public void update(DocumentEvent event) { int offset= event.getOffset(); int length= event.getLength(); int delta= event.getText().length() - length; if (offset < fPosition.getOffset()) fPosition.setOffset(fPosition.getOffset() + delta); else if (offset < fPosition.getOffset() + fPosition.getLength()) fPosition.setLength(fPosition.getLength() + delta); } }
/** * Returns <code>true</code> if inlined annotation is deleted and <code>false</code> otherwise. * * @param annotation the inlined annotation to check * @return <code>true</code> if inlined annotation is deleted and <code>false</code> otherwise. */ private static boolean isDeleted(AbstractInlinedAnnotation annotation) { return annotation.isMarkedDeleted() || annotation.getPosition().isDeleted() || annotation.getPosition().getLength() == 0; } }
private void processDeletions(AnnotationModelEvent event, Annotation[] removedAnnotations, boolean fireRedraw) throws BadLocationException { for (int i= 0; i < removedAnnotations.length; i++) { ProjectionAnnotation annotation= (ProjectionAnnotation) removedAnnotations[i]; if (annotation.isCollapsed()) { Position expanded= event.getPositionOfRemovedAnnotation(annotation); expand(expanded.getOffset(), expanded.getLength(), fireRedraw); } } }
private void add(String s, DocumentRangeNode parent, DocumentRangeNode child) { Position p= findCorrespondingPosition(parent, child); if (p != null) { try { fBaseDocument.replace(p.getOffset(), p.getLength(), s); } catch (BadLocationException ex) { CompareUIPlugin.log(ex); } } }
private void add(String s, DocumentRangeNode parent, DocumentRangeNode child) { Position p= findCorrespondingPosition(parent, child); if (p != null) { try { fBaseDocument.replace(p.getOffset(), p.getLength(), s); } catch (BadLocationException ex) { CompareUIPlugin.log(ex); } } }
protected IHyperlink createHyperlink(ISourceViewer viewer, IAnnotationModel annotationModel, AnchorHrefAnnotation anchorHrefAnnotation) { Position position = annotationModel.getPosition(anchorHrefAnnotation); IRegion region = new Region(position.getOffset(), position.getLength()); String href = anchorHrefAnnotation.getAnchorHref(); if (href != null && href.startsWith("#")) { //$NON-NLS-1$ return new DocumentHyperlink(viewer, region, href); } else { return createUrlHyperlink(region, href); } }
public static Position convertToCharacterPosition(Position linePosition, IDocument doc) throws BadLocationException { int lineOffset= linePosition.getOffset(); int lineLength= linePosition.getLength(); int charOffset= doc.getLineOffset(lineOffset); int charLength= 0; if (lineLength > 0) { int lastLine= lineOffset+lineLength-1; int endPosition= doc.getLineOffset(lastLine)+doc.getLineLength(lastLine); charLength= endPosition-charOffset; } return new Position(charOffset, charLength); }
@Override public IRegion getVisibleRegion() { IDocument document= getVisibleDocument(); if (document instanceof ChildDocument) { Position p= ((ChildDocument) document).getParentDocumentRange(); return new Region(p.getOffset(), p.getLength()); } return new Region(0, document == null ? 0 : document.getLength()); }
private boolean includes(IRegion[] regions, Position position) { for (int i= 0; i < regions.length; i++) { IRegion region= regions[i]; if (position != null && !position.isDeleted() && region.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength()) return true; } return false; } }