@Override public void format(final ITextSegment region, final IHiddenRegionFormatting wrapped, @Extension final IFormattableDocument document) { if ((!this.hasWrapped)) { IHiddenRegion _switchResult = null; boolean _matched = false; if (region instanceof IHiddenRegion) { _matched=true; _switchResult = ((IHiddenRegion)region); } if (!_matched) { if (region instanceof IHiddenRegionPart) { _matched=true; _switchResult = ((IHiddenRegionPart)region).getHiddenRegion(); } } final IHiddenRegion hiddenRegion = _switchResult; final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.indent(); }; document.set(hiddenRegion, this.last, _function); this.hasWrapped = true; } }
@Override public String apply(IHiddenRegionFormatting gapFormatting) { String space = gapFormatting.getSpace(); Integer nlMin = gapFormatting.getNewLineMin(); Integer nlDefault = gapFormatting.getNewLineDefault(); Integer nlMax = gapFormatting.getNewLineMax(); Integer autowrap = gapFormatting.getAutowrap(); Integer indentationIncrease = gapFormatting.getIndentationIncrease(); Integer indentationDecrease = gapFormatting.getIndentationDecrease(); List<String> result = Lists.newArrayList(); if (space != null) result.add("space='" + space.replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t") + "'"); if (nlDefault != null && nlDefault.equals(nlMin) && nlDefault.equals(nlMax)) result.add("newLine=" + nlDefault); else if (nlMin != null || nlDefault != null || nlMax != null) { String x = firstNonNull(nlMin, "?") + "-" + firstNonNull(nlDefault, "?") + "-" + firstNonNull(nlMax, "?"); result.add("newLine=" + x); } if (autowrap != null) result.add(autowrap >= 0 ? ("autowrap" + ((autowrap > 0) ? "(" + autowrap + ")" : "")) : "noAutowrap"); if (indentationIncrease != null) result.add("indentInc=" + indentationIncrease); if (indentationDecrease != null) result.add("indentDec=" + indentationDecrease); return Joiner.on(";").join(result); }
protected ITextReplacer mergeHiddenRegionReplacers(List<? extends ITextReplacer> conflicting) { List<IHiddenRegionFormatting> formattings = Lists.newArrayList(); IHiddenRegion region = null; for (ITextReplacer replacer : conflicting) { if (replacer instanceof HiddenRegionReplacer) { HiddenRegionReplacer hiddenRegionReplacer = (HiddenRegionReplacer) replacer; formattings.add(hiddenRegionReplacer.getFormatting()); if (region == null) region = hiddenRegionReplacer.getRegion(); else if (region != hiddenRegionReplacer.getRegion()) return null; } else return null; } IHiddenRegionFormatting mergedFormatting = merger.merge(formattings); if (mergedFormatting != null) return formatter.createHiddenRegionReplacer(region, mergedFormatting); return null; }
@Override public void mergeValuesFrom(IHiddenRegionFormatting other) throws ConflictingFormattingException { int strategy = other.getPriority() - getPriority(); setSpace(merge(getSpace(), other.getSpace(), strategy, "space")); setNewLinesMin(merge(getNewLineMin(), other.getNewLineMin(), strategy, "newLineMin")); setNewLinesDefault(merge(getNewLineDefault(), other.getNewLineDefault(), strategy, "newLineDefault")); setNewLinesMax(merge(getNewLineMax(), other.getNewLineMax(), strategy, "newLineMax")); setAutowrap(merge(getAutowrap(), other.getAutowrap(), strategy, "autowrap")); setOnAutowrap(merge(getOnAutowrap(), other.getOnAutowrap(), strategy, "onAutowrap")); setNoIndentation(merge(getNoIndentation(), other.getNoIndentation(), strategy, "noIndentation")); if (getIndentationIncrease() != null && other.getIndentationIncrease() != null) setIndentationIncrease(getIndentationIncrease() + other.getIndentationIncrease()); else setIndentationIncrease( getIndentationIncrease() != null ? getIndentationIncrease() : other.getIndentationIncrease()); if (getIndentationDecrease() != null && other.getIndentationDecrease() != null) setIndentationDecrease(getIndentationDecrease() + other.getIndentationDecrease()); else setIndentationDecrease( getIndentationDecrease() != null ? getIndentationDecrease() : other.getIndentationDecrease()); }
@Override protected int computeNewLineCount(ITextReplacerContext context) { // In case no information is configured, we do not want to swallow any lines (super give 0 here): IHiddenRegionFormatting formatting = getFormatting(); if (formatting.getNewLineDefault() == null && formatting.getNewLineMin() == null && formatting.getNewLineMax() == null) { // return the actual newlines: return getRegion().getLineCount() - 1; } // all other cases are handled as always: return super.computeNewLineCount(context); }
@Override public IHiddenRegionFormatting merge(List<? extends IHiddenRegionFormatting> conflicting) { if (conflicting.size() == 2) { // TODO: don't do this conflicting.get(1).mergeValuesFrom(conflicting.get(0)); return conflicting.get(1); } IHiddenRegionFormatting result = formatter.createHiddenRegionFormatting(); for (IHiddenRegionFormatting conflict : conflicting) result.mergeValuesFrom(conflict); return result; }
@Override public Pair<IHiddenRegion, IHiddenRegion> set(IHiddenRegion first, IHiddenRegion second, Procedure1<? super IHiddenRegionFormatter> init) { if (first != null && second != null) { AbstractFormatter2 formatter = getFormatter(); IHiddenRegionFormatting f1 = formatter.createHiddenRegionFormatting(); IHiddenRegionFormatting f2 = formatter.createHiddenRegionFormatting(); init.apply(formatter.createHiddenRegionFormatter(f1, f2)); ITextReplacer replacer1 = formatter.createHiddenRegionReplacer(first, f1); ITextReplacer replacer2 = formatter.createHiddenRegionReplacer(second, f2); addReplacer(replacer1); addReplacer(replacer2); } return Pair.of(first, second); }
@Override public IHiddenRegion set(IHiddenRegion hiddenRegion, Procedure1<? super IHiddenRegionFormatter> init) { if (hiddenRegion != null) { AbstractFormatter2 formatter = getFormatter(); IHiddenRegionFormatting formatting = formatter.createHiddenRegionFormatting(); init.apply(formatter.createHiddenRegionFormatter(formatting)); ITextReplacer replacer = formatter.createHiddenRegionReplacer(hiddenRegion, formatting); addReplacer(replacer); } return hiddenRegion; }
/** */ public N4WhitespaceReplacer(ITextSegment whitespace, IHiddenRegionFormatting formatting) { super(whitespace, formatting); }
public DoubleHiddenRegionFormatter(IHiddenRegionFormatting first, IHiddenRegionFormatting second) { super(); this.first = first; this.second = second; }
public HiddenRegionReplacer(IHiddenRegion region, IHiddenRegionFormatting formatting) { super(); this.region = region; this.formatting = formatting; }
public IHiddenRegionFormatting getFormatting() { return formatting; }
public SingleHiddenRegionFormatter(IHiddenRegionFormatting formatting) { super(); this.formatting = formatting; }
protected void validate(HiddenRegionReplacer replacer) throws FormattingNotApplicableException { IHiddenRegionFormatting formatting = replacer.getFormatting(); Integer newLineMin = formatting.getNewLineMin(); if (newLineMin != null && newLineMin > 0) throw new FormattingNotApplicableException(); }
public WhitespaceReplacer(ITextSegment whitespace, IHiddenRegionFormatting formatting) { super(); this.region = whitespace; this.formatting = formatting; }