public int getTokenLength() { return lastComputed.partitions[index].getLength(); }
/** * Creates a position based on the typed region. * * @param region the typed region */ public TypedPosition(ITypedRegion region) { super(region.getOffset(), region.getLength()); fType= region.getType(); }
/** * Creates a position based on the typed region. * * @param region the typed region */ public TypedPosition(ITypedRegion region) { super(region.getOffset(), region.getLength()); fType= region.getType(); }
/** * 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 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); } }
protected String getDocumentContent(IDocument document, DocumentCommand command) throws BadLocationException { final ITypedRegion partition = document.getPartition(command.offset); ITypedRegion[] partitions = document.getDocumentPartitioner().computePartitioning(0, document.getLength()); Iterable<ITypedRegion> partitionsOfCurrentType = Iterables.filter(Arrays.asList(partitions), new Predicate<ITypedRegion>() { public boolean apply(ITypedRegion input) { return input.getType().equals(partition.getType()); } }); StringBuilder builder = new StringBuilder(); for (ITypedRegion position : partitionsOfCurrentType) { builder.append(document.get(position.getOffset(), position.getLength())); } return builder.toString(); }
/** * @return the common region of the given partition and the changed region in the DocumentEvent based on the underlying tokens. */ protected IRegion computeInterSection(ITypedRegion partition, DocumentEvent e, XtextDocument document) { Iterable<ILexerTokenRegion> tokensInPartition = Iterables.filter(document.getTokens(),Regions.overlaps(partition.getOffset(), partition.getLength())); Iterator<ILexerTokenRegion> tokens = Iterables.filter(tokensInPartition, Regions.overlaps(e.getOffset(), e.getLength())).iterator(); if (tokens.hasNext()) { ILexerTokenRegion first = tokens.next(); ILexerTokenRegion last = first; while(tokens.hasNext()) last = tokens.next(); return new Region(first.getOffset(), last.getOffset()+last.getLength() -first.getOffset()); } // this shouldn't happen, but just in case return the whole partition return partition; }
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); } }
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); } }
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 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 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 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 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() + 1 || offset == region.getOffset() + region.getLength() - 1) { return getSelectedRegion(document, region); } } catch (BadLocationException e) { return null; } return null; }
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException { int selectionOffset= selection.getOffset(); int selectionEndOffset= selectionOffset + selection.getLength(); List edits= new LinkedList(); ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, selectionOffset, false); handleFirstPartition(partition, edits, factory, selectionOffset); while (partition.getOffset() + partition.getLength() < selectionEndOffset) { partition= handleInteriorPartition(partition, edits, factory, docExtension); } handleLastPartition(partition, edits, factory, selectionEndOffset); executeEdits(edits); }
@Override protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException { int selectionOffset= selection.getOffset(); int selectionEndOffset= selectionOffset + selection.getLength(); List<Edit> edits= new LinkedList<>(); ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, selectionOffset, false); handleFirstPartition(partition, edits, factory, selectionOffset); while (partition.getOffset() + partition.getLength() < selectionEndOffset) { partition= handleInteriorPartition(partition, edits, factory, docExtension); } handleLastPartition(partition, edits, factory, selectionEndOffset); executeEdits(edits); }
public void createPresentation(TextPresentation presentation, ITypedRegion damage) { presentation.addStyleRange(new StyleRange(damage.getOffset(), damage.getLength(), defaultTextAttribute.getForeground(), defaultTextAttribute.getBackground(), defaultTextAttribute.getStyle())); }
@Override protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException { int selectionOffset= selection.getOffset(); int selectionEndOffset= selectionOffset + selection.getLength(); List<Edit> edits= new LinkedList<>(); ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, selectionOffset, false); handleFirstPartition(partition, edits, factory, selectionOffset); while (partition.getOffset() + partition.getLength() < selectionEndOffset) { partition= handleInteriorPartition(partition, edits, factory, docExtension); } handleLastPartition(partition, edits, factory, selectionEndOffset); executeEdits(edits); if (action != null) { action.run(); } }