@Override public int compare(final AttributedPosition o1, final AttributedPosition o2) { if (o1 == null) { return o2 == null ? 0 : -1; } else if (o2 == null) { return 1; } int res = o1.offset - o2.offset; if (res != 0) { return res; } res = o1.length - o2.length; if (res != 0) { return res; } if (o1.isDeleted != o2.isDeleted) { return o1.isDeleted ? -1 : 1; } return o1.getHighlighting().hashCode() - o2.getHighlighting().hashCode(); }
/** * Reconcile positions based on the AST subtrees * * @param subtrees * the AST subtrees */ private void reconcilePositions(XtextResource resource) { // for (int i= 0, n= subtrees.length; i < n; i++) // subtrees[i].accept(fCollector); MergingHighlightedPositionAcceptor acceptor = new MergingHighlightedPositionAcceptor( calculator); acceptor.provideHighlightingFor(resource, this); // calculator.provideHighlightingFor(resource, this); List<AttributedPosition> oldPositions = removedPositions; List<AttributedPosition> newPositions = new ArrayList<AttributedPosition>( removedPositionCount); for (int i = 0, n = oldPositions.size(); i < n; i++) { AttributedPosition current = oldPositions.get(i); if (current != null) newPositions.add(current); } removedPositions = newPositions; }
/** * Add a position with the given range and highlighting if it does not exist already. * * @param offset * The range offset * @param length * The range length * @param highlighting * The highlighting */ @Override public void addPosition(final int offset, final int length, final String... ids) { TextAttribute highlighting = ids.length == 1 ? attributeProvider.getAttribute(ids[0]) : attributeProvider.getMergedAttributes(ids); AttributedPosition position = presenter.createHighlightedPosition(offset, length, highlighting); int idx = positionOrdering.binarySearch(removedPositions, position); boolean isExisting = idx >= 0 && removedPositions.get(idx).isEqual(offset, length, highlighting); if (isExisting) { removedPositions.remove(idx); } else { addedPositions.add(position); } }
/** * Update the presentation. * * @param textPresentation * the text presentation * @param addedPositions * the added positions * @param removedPositions * the removed positions */ private void updatePresentation(TextPresentation textPresentation, List<AttributedPosition> addedPositions, List<AttributedPosition> removedPositions) { Runnable runnable = presenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions); if (runnable == null) return; Display display = Display.getDefault(); display.asyncExec(runnable); }
/** * Update the presentation. * * @param textPresentation * the text presentation * @param addedPositions * the added positions * @param removedPositions * the removed positions */ private void updatePresentation(final TextPresentation textPresentation, final List<AttributedPosition> addedPositions, final List<AttributedPosition> removedPositions) { Runnable runnable = presenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions); if (runnable == null) { return; } Display display = getDisplay(); display.asyncExec(runnable); }