protected Set<ElementLocator> collectLocatorsForComments(Collection<ElementLocator> semanticLocators, EObject left, EObject right) { Set<ElementLocator> result = Sets.newHashSet(); for (ElementLocator semantic : semanticLocators) if (semantic instanceof IndentationLocatorStart || semantic instanceof IndentationLocatorEnd || (semantic.getRight() != null && semantic.getRight() == right) || (semantic.getLeft() != null && semantic.getLeft() == left)) result.add(semantic); if (left != null) result.addAll(cfg.getLocatorsForCommentTokensAfter(left)); if (right != null) { List<ElementLocator> leadingElementLocators = cfg.getLocatorsForCommentTokensBefore(right); for (Iterator<ElementLocator> i = result.iterator(); i.hasNext();) { ElementLocator locator = i.next(); if (locator.getType() == LocatorType.BETWEEN && !leadingElementLocators.contains(locator)) i.remove(); } for (Iterator<ElementLocator> i = leadingElementLocators.iterator(); i.hasNext();) { if (i.next().getType() == LocatorType.BETWEEN) i.remove(); } result.addAll(leadingElementLocators); } return result; }
protected Set<ElementLocator> collectLocators(EObject ele) { Set<ElementLocator> result = Sets.newHashSet(activeRangeLocators); Collection<ElementLocator> loc = Sets.newHashSet(); if (ele instanceof AbstractElement) for (ElementPattern pattern : matcher.matchNext((AbstractElement) ele)) loc.add(pattern.getLocator()); if ((last instanceof AbstractRule && hiddenTokenHelper.isComment((AbstractRule) last)) || (ele instanceof AbstractRule && hiddenTokenHelper.isComment((AbstractRule) ele))) loc = collectLocatorsForComments(loc, last, ele); last = ele; for (ElementLocator locator : loc) if (locator.getType() == LocatorType.RANGE && !activeRangeLocators.add(locator)) activeRangeLocators.remove(locator); result.addAll(loc); for (ElementLocator locator : result) { if (locator instanceof IndentationLocatorStart) indentationLevel++; else if (locator instanceof IndentationLocatorEnd) indentationLevel--; } return result; }
@Override public String toString() { return locator.toString(); } }