public boolean apply(IRegion input) { return TextUtilities.overlaps(region, input); } };
/** * Returns the region out of the given set that contains the given line or * <code>null</code>. * * @param regions the set of regions * @param line the line * @return the region of the set that contains the line * @throws BadLocationException in case line is invalid */ private IRegion findRegionContainingLine(IRegion[] regions, int line) throws BadLocationException { IDocument document= fSourceViewer.getDocument(); IRegion lineInfo= document.getLineInformation(line); for (IRegion region : regions) { if (TextUtilities.overlaps(region, lineInfo)) return region; } return null; }
/** * Returns the region out of the given set that contains the given line or * <code>null</code>. * * @param regions the set of regions * @param line the line * @return the region of the set that contains the line * @throws BadLocationException in case line is invalid */ private IRegion findRegionContainingLine(IRegion[] regions, int line) throws BadLocationException { IDocument document= fSourceViewer.getDocument(); IRegion lineInfo= document.getLineInformation(line); for (int i= 0; i < regions.length; i++) { if (TextUtilities.overlaps(regions[i], lineInfo)) return regions[i]; } return null; }
@Override protected ILexerTokenRegion computeNext() { while(delegate.hasNext()) { ILexerTokenRegion candidate = delegate.next(); if (overlapRegion.getOffset() + overlapRegion.getLength() < candidate.getOffset()) return endOfData(); if (TextUtilities.overlaps(overlapRegion, candidate)) return candidate; } return endOfData(); }
public void createPresentation( TextPresentation presentation, ITypedRegion damage ) { LdifFile ldifModel = this.editor.getLdifModel(); LdifContainer[] allContainers = ldifModel.getContainers(); List containerList = new ArrayList(); for ( int i = 0; i < allContainers.length; i++ ) { LdifContainer container = allContainers[i]; Region containerRegion = new Region( container.getOffset(), container.getLength() ); if ( TextUtilities.overlaps( containerRegion, damage ) ) { containerList.add( container ); } } LdifContainer[] containers = ( LdifContainer[] ) containerList .toArray( new LdifContainer[containerList.size()] ); this.highlight( containers, presentation, damage ); // LdifFile ldifModel = this.editor.getLdifModel(); // System.out.println(ldifModel.toRawString()); // LdifContainer[] allContainers = ldifModel.getContainers(); // this.highlight(allContainers, presentation, null); }
@Override public boolean overlapsWithVisibleRegion(int offset, int length) { disableProjection(); IRegion coverage= getModelCoverage(); if (coverage == null) return false; boolean appending= (offset == coverage.getOffset() + coverage.getLength()) && length == 0; return appending || TextUtilities.overlaps(coverage, new Region(offset, length)); }
@Override public boolean overlapsWithVisibleRegion(int offset, int length) { disableProjection(); IRegion coverage= getModelCoverage(); if (coverage == null) return false; boolean appending= (offset == coverage.getOffset() + coverage.getLength()) && length == 0; return appending || TextUtilities.overlaps(coverage, new Region(offset, length)); }
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent e, boolean documentPartitioningChanged) { if (!(e.getDocument() instanceof IXtextDocument)) { return new Region(0, 0); } XtextDocument document = (XtextDocument) e.getDocument(); IRegion lastDamage = document.getLastDamage(); // check whether this is just a presentation invalidation not based on a real document change if (lastDamage == null || !isEventMatchingLastDamage(e, lastDamage)) { IRegion result = computeInterSection(partition, e, document); return result; } if (!TextUtilities.overlaps(partition, lastDamage) && lastDamage.getOffset()<e.getDocument().getLength()) { if (documentPartitioningChanged) return partition; return lastDamage; } int offset = Math.max(lastDamage.getOffset(),partition.getOffset()); int endOffset = Math.min(lastDamage.getOffset()+lastDamage.getLength(),partition.getOffset()+partition.getLength()); IRegion result = new Region(offset,endOffset-offset); return result; }
/** * Call this method only from within an IUnitOfWork */ protected Pair<EObject, IRegion> getXtextElementAt(XtextResource resource, final int offset) { // check for cross reference EObject crossLinkedEObject = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, offset); if (crossLinkedEObject != null) { if (!crossLinkedEObject.eIsProxy()) { IParseResult parseResult = resource.getParseResult(); if (parseResult != null) { ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset); if(leafNode != null && leafNode.isHidden() && leafNode.getOffset() == offset) { leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset - 1); } if (leafNode != null) { return Tuples.create(crossLinkedEObject, (IRegion) new Region(leafNode.getOffset(), leafNode.getLength())); } } } } else { EObject o = eObjectAtOffsetHelper.resolveElementAt(resource, offset); if (o != null) { ITextRegion region = locationInFileProvider.getSignificantTextRegion(o); final IRegion region2 = new Region(region.getOffset(), region.getLength()); if (TextUtilities.overlaps(region2, new Region(offset, 0))) return Tuples.create(o, region2); } } return null; }