/** * Creates a document template context. * * @param type the context type * @param document the document this context applies to * @param offset the offset of the document region * @param length the length of the document region */ public DocumentTemplateContext(TemplateContextType type, IDocument document, int offset, int length) { this(type, document, new Position(offset, length)); }
private boolean willAutoExpand(Position position, int offset, int length) { if (position == null || position.isDeleted()) return false; // right or left boundary if (position.getOffset() == offset || position.getOffset() + position.getLength() == offset + length) return true; // completely embedded in given position if (position.getOffset() < offset && offset + length < position.getOffset() + position.getLength()) return true; return false; }
private boolean isWithinRegion(Position region, Position position, boolean canStartBefore, boolean canEndAfter) { if (canStartBefore && canEndAfter) { return region.overlapsWith(position.getOffset(), position.getLength()); } else if (canStartBefore) { return region.includes(position.getOffset() + position.getLength() - 1); } else if (canEndAfter) { return region.includes(position.getOffset()); } else { int start= position.getOffset(); return region.includes(start) && region.includes(start + position.getLength() - 1); } }
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 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); } }
/** * Hook method which is called when the given editor has been saved. * * @param part the editor part */ public void partSaved(IEditorPart part) { // http://dev.eclipse.org/bugs/show_bug.cgi?id=25440 if (fPosition == null || fPosition.isDeleted()) fSavedPosition= null; else fSavedPosition= new Position(fPosition.offset, fPosition.length); }
/** * 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; } }
/** * If <code>regionOffset</code> is the end of the visible region and the <code>regionLength == 0</code>, * the <code>regionOffset</code> is considered overlapping with the visible region. * * @see org.eclipse.jface.text.Position#overlapsWith(int, int) */ @Override public boolean overlapsWith(int regionOffset, int regionLength) { boolean appending= (regionOffset == offset + length) && regionLength == 0; return appending || super.overlapsWith(regionOffset, regionLength); } }
@Override public void setLength(int length) { synchronized (fLock) { super.setLength(length); } }
@Override public void setOffset(int offset) { synchronized (fLock) { super.setOffset(offset); } }
/** * Returns <code>true</code> if the receiver contains <code>position</code>. * * @param position the position to check * @return <code>true</code> if the receiver contains <code>position</code> */ boolean contains(Position position) { for (LinkedPosition p : fPositions) { if (position.equals(p)) return true; } return false; } }
private boolean isWithinRegion(int start, int length) { if (fCanStartBefore && fCanEndAfter) return fRegion.overlapsWith(start, length); else if (fCanStartBefore) return fRegion.includes(start + length - (length > 0 ? 1 : 0)); else if (fCanEndAfter) return fRegion.includes(start); else return fRegion.includes(start) && fRegion.includes(start + length - (length > 0 ? 1 : 0)); } }
public List<Position> findPath(Set<Position> closedSet, Position from, Position to) { if (from.equals(to)) return List.of(to); while (from.hasNeighboursNotIn(closedSet)) { Position pos = from.getRandomNeighbourNotIn(closedSet); closedSet.add(pos); List<Position> path = findPath(closedSet, pos, to); if (!path.isEmpty()) return List.of(pos, path); } closedSet.add(from); return Collection.EMPTY_LIST; }
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 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); } }
private boolean isWithinRegion(Position region, Position position, boolean canStartBefore, boolean canEndAfter) { if (canStartBefore && canEndAfter) { return region.overlapsWith(position.getOffset(), position.getLength()); } else if (canStartBefore) { return region.includes(position.getOffset() + position.getLength() - 1); } else if (canEndAfter) { return region.includes(position.getOffset()); } else { int start= position.getOffset(); return region.includes(start) && region.includes(start + position.getLength() - 1); } }