public void assertFormattedExpression(final Procedure1<? super FormatterTestRequest> test) { String _newLine = Strings.newLine(); final String prefix = ("{" + _newLine); String _newLine_1 = Strings.newLine(); final String postfix = (_newLine_1 + "}"); final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> { test.apply(it); final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> { it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(80)); }; it.preferences(_function_1); String _indent = this.indent(it.getExpectationOrToBeFormatted().toString().trim(), "\t"); String _plus = (prefix + _indent); String _plus_1 = (_plus + postfix); it.setExpectation(_plus_1); String _indent_1 = this.indent(it.getToBeFormatted().toString().trim(), "\t"); String _plus_2 = (prefix + _indent_1); String _plus_3 = (_plus_2 + postfix); it.setToBeFormatted(_plus_3); }; final Procedure1<? super FormatterTestRequest> setup = _function; this.assertFormatted(((Procedure1<FormatterTestRequest>)setup)); }
public IFormattableSubDocument requireFitsInLine(int offset, int length) { Integer maxLineWidth = getRequest().getPreferences().getPreference(FormatterPreferenceKeys.maxLineWidth); return requireFitsInLine(offset, length, maxLineWidth); }
protected ITextReplacerContext createReplacements(ITextReplacerContext previous) { Integer maxLineWidth = getRequest().getPreferences().getPreference(FormatterPreferenceKeys.maxLineWidth); ITextReplacerContext context = previous.withDocument(this); ITextReplacerContext wrappable = null; Set<ITextReplacer> wrapped = Sets.newHashSet(); Iterator<ITextReplacer> replacers = getReplacers().iterator(); while (replacers.hasNext()) { ITextReplacer replacer = replacers.next(); context = context.withReplacer(replacer); if (wrappable != null && context.isWrapSincePrevious()) { wrappable = null; } if (wrappable != null && needsAutowrap(wrappable, context, maxLineWidth)) { // TODO: raise report if replacer claims it can do autowrap but // then doesn't while (context != wrappable) { context = context.getPreviousContext(); } replacer = context.getReplacer(); replacers = getReplacers().iteratorAfter(replacer); context.setAutowrap(true); wrappable = null; } ITextReplacerContext nextContext = replacer.createReplacements(context); if (wrappable != null && context.isWrapInRegion()) { wrappable = null; } else { Integer canAutowrap = context.canAutowrap(); if (canAutowrap != null && canAutowrap >= 0 && !context.isAutowrap() && !wrapped.contains(replacer)) { boolean can = true; if (wrappable != null) { int lastEndOffset = wrappable.canAutowrap() + wrappable.getReplacer().getRegion().getEndOffset(); int thisEndOffset = canAutowrap + context.getReplacer().getRegion().getEndOffset(); can = lastEndOffset < thisEndOffset; } if (can) { wrappable = context; wrapped.add(replacer); } } } context = nextContext; } return context.withDocument(previous.getDocument()); }
@Override public String getIndentationString(int indentationLevel) { AbstractFormatter2 formatter = document.getFormatter(); return Strings.repeat(formatter.getPreference(FormatterPreferenceKeys.indentation), indentationLevel); }
@Override public String getNewLinesString(int count) { return Strings.repeat(document.getFormatter().getPreference(FormatterPreferenceKeys.lineSeparator), count); }