protected List<ITextSegment> toTokenAndGapList() { final int range = this.hightlightOrigin ? 4 : (Integer.MAX_VALUE / 2); ITextSegment first = null; { ITextSegment current = origin; for (int i = 0; i < range && current != null; i++) { first = current; if (current instanceof ITextRegionAccess) current = ((ITextRegionAccess) current).regionForRootEObject().getPreviousHiddenRegion(); else if (current instanceof ISequentialRegion) current = ((ISequentialRegion) current).getPreviousHiddenRegion(); else if (current instanceof IHiddenRegionPart) current = ((IHiddenRegionPart) current).getHiddenRegion(); else throw new IllegalStateException("Unexpected Type: " + current.getClass()); } } if (first == null) return Collections.emptyList(); List<ITextSegment> result = Lists.newArrayList(); { ITextSegment current = first; for (int i = 0; i <= (range * 2) && current != null; i++) { result.add(current); if (current instanceof ISemanticRegion) current = ((ISemanticRegion) current).getNextHiddenRegion(); else if (current instanceof IHiddenRegion) current = ((IHiddenRegion) current).getNextSemanticRegion(); else throw new IllegalStateException("Unexpected Type: " + current.getClass()); } } return result; }
public TextRegionsToString addReplacement( ITextSegment region, String replacement, String description) { text.add(region, getReplacement(region, replacement)); list.add( region, quote(region.getText(), 20) + " -> " + quote(replacement, 20) + ": " + description); return this; }
protected String toString(ITextSegment region) { String result; if (region instanceof IEObjectRegion) result = toString((IEObjectRegion) region); else if (region instanceof ISemanticRegion) result = toString((ISemanticRegion) region); else if (region instanceof IHiddenRegion) result = toString((IHiddenRegion) region); else if (region instanceof IWhitespace) result = toString((IWhitespace) region); else if (region instanceof IComment) result = toString((IComment) region); else if (region != null) result = region.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(region)); else result = "null"; if (hightlightOrigin && region == origin) return ">>>" + result + "<<<"; return result; }
protected String getReplacement(ITextSegment region, String replacement) { String string = region.getText(); if (Strings.equal(string, replacement)) return "<" + region.getOffset() + "|" + replacement + ">"; return "<" + region.getOffset() + ":" + region.getLength() + "|" + replacement + ">"; }