/** * Creates the presentation. * * @param presentation the presentation * @param region the region * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion) */ @Override public void createPresentation(TextPresentation presentation, ITypedRegion region) { addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextAttribute); }
public int findNextOffSetInPartition(IDocument doc, int partitionOffSet, int minIndex) throws BadLocationException { ITypedRegion partition = doc.getPartition(partitionOffSet); ITypedRegion partition2 = doc.getPartition(minIndex); if (partition.getType().equals(partition2.getType()) || partition2.getLength() == 0) { return minIndex; } else { return findNextOffSetInPartition(doc, partitionOffSet, minIndex + partition2.getLength()); } } }
@Override public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) { ITypedRegion region= getPartition(offset); if (preferOpenPartitions) { if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) { if (offset > 0) { region= getPartition(offset - 1); if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) return region; } return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE); } } return region; }
public int getTokenOffset() { return lastComputed.partitions[index].getOffset(); }
public int getTokenLength() { return lastComputed.partitions[index].getLength(); }
@Override protected IRegion getSelectedRegion(IDocument document, ITypedRegion completePartition) throws BadLocationException { if (fLeftBorder == 0 && fRightBorder == 0) return completePartition; if (fRightBorder == -1) { String delimiter = document.getLineDelimiter(document.getLineOfOffset(completePartition.getOffset() + completePartition.getLength() - 1)); if (delimiter == null) fRightBorder = 0; else fRightBorder = delimiter.length(); } return new Region(completePartition.getOffset() + fLeftBorder, completePartition.getLength() - fLeftBorder - fRightBorder); } }
@Override public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) { ITypedRegion region= getPartition(offset); if (preferOpenPartitions) { if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) { if (offset > 0) { region= getPartition(offset - 1); if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) return region; } return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE); } } return region; }
/** * {@inheritDoc} * <p> * May be replaced or extended by subclasses. * </p> */ @Override public String getContentType(int offset, boolean preferOpenPartitions) { return getPartition(offset, preferOpenPartitions).getType(); }
private void removeToken(final ITypedRegion partition, int partOffset, final Edit.EditFactory factory, final List<Edit> edits) throws BadLocationException { IEditorInput editorInput = getTextEditor().getEditorInput(); IDocument document = getTextEditor().getDocumentProvider().getDocument(editorInput); int startLine = document.getLineOfOffset(partOffset); int lines = document.getNumberOfLines(partOffset, partition.getLength()); for(int line = startLine; line < startLine + lines; line++) { int lineOffset = document.getLineOffset(line); int lineLength = document.getLineLength(line); char ch1 = document.getChar(lineOffset); int pos = 0; // skip all character codes <= 0x20 from start of line while(pos < lineLength && ((ch1 = document.getChar(lineOffset + pos)) <= 0x20)) { pos++; } if(ch1 == '*') { /* next char after '*' must NOT be a '/', this is handled separately */ if(pos + 1 < lineLength) { char ch2 = document.getChar(lineOffset + pos + 1); if(ch2 == '/') { continue; // do next line } } Edit edit= factory.createEdit(lineOffset + pos, 1, ""); //$NON-NLS-1$ edits.add(edit); } } }
@Override protected IRegion findExtendedDoubleClickSelection(IDocument document, int offset) { IRegion match= super.findExtendedDoubleClickSelection(document, offset); if (match != null) return match; try { ITypedRegion region= TextUtilities.getPartition(document, fPartitioning, offset, true); if (offset == region.getOffset() + 1 || offset == region.getOffset() + region.getLength() - 1) { return getSelectedRegion(document, region); } } catch (BadLocationException e) { return null; } return null; }
@Override public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) { ITypedRegion region= getPartition(offset); if (preferOpenPartitions) { if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) { if (offset > 0) { region= getPartition(offset - 1); if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) return region; } return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE); } } return region; }
/** * {@inheritDoc} * <p> * May be replaced or extended by subclasses. * </p> * * @since 2.2 */ public String getContentType(int offset, boolean preferOpenPartitions) { return getPartition(offset, preferOpenPartitions).getType(); }
public int nextPosition(int position, boolean forward) { ITypedRegion partition= getPartition(position); if (fPartition.equals(partition.getType())) return super.nextPosition(position, forward); if (forward) { int end= partition.getOffset() + partition.getLength(); if (position < end) return end; } else { int offset= partition.getOffset(); if (position > offset) return offset - 1; } return super.nextPosition(position, forward); } }
@Override protected IRegion findExtendedDoubleClickSelection(IDocument document, int offset) { IRegion match= super.findExtendedDoubleClickSelection(document, offset); if (match != null) return match; try { ITypedRegion region= TextUtilities.getPartition(document, fPartitioning, offset, true); if (offset == region.getOffset() + fHitDelta || offset == region.getOffset() + region.getLength() - fHitDelta) { if (fLeftBorder == 0 && fRightBorder == 0) return region; if (fRightBorder == -1) { String delimiter= document.getLineDelimiter(document.getLineOfOffset(region.getOffset() + region.getLength() - 1)); if (delimiter == null) fRightBorder= 0; else fRightBorder= delimiter.length(); } return new Region(region.getOffset() + fLeftBorder, region.getLength() - fLeftBorder - fRightBorder); } } catch (BadLocationException e) { return null; } return null; } }
@Override public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) { ITypedRegion region= getPartition(offset); if (preferOpenPartitions) { if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) { if (offset > 0) { region= getPartition(offset - 1); if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) return region; } return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE); } } return region; }
/** * Returns true if the specified offset is within the partition * managed by this document. * * @param pos an offset within this document * @return true if the offset is within this document's partition */ public boolean inPartition(int pos) { final ITypedRegion partition= getPartition(pos); return partition != null && partition.getType().equals(fPartition); }
public int nextPosition(int position, boolean forward) { ITypedRegion partition= getPartition(position); if (fPartition.equals(partition.getType())) return super.nextPosition(position, forward); if (forward) { int end= partition.getOffset() + partition.getLength(); if (position < end) return end; } else { int offset= partition.getOffset(); if (position > offset) return offset - 1; } return super.nextPosition(position, forward); } }