org.eclipse.xtext.formatting2.IHiddenRegionFormatting Java Examples
The following examples show how to use
org.eclipse.xtext.formatting2.IHiddenRegionFormatting.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiddenRegionFormatting.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@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()); }
Example #2
Source File: RichStringFormatter.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void setNewLines(final IFormattableDocument doc, final int offset, final int length, final int indentationIncrease, final int indentationDecrease, final int newLines) { IHiddenRegionFormatting _createHiddenRegionFormatting = doc.getFormatter().createHiddenRegionFormatting(); final Procedure1<IHiddenRegionFormatting> _function = (IHiddenRegionFormatting it) -> { it.setIndentationIncrease(Integer.valueOf(indentationIncrease)); it.setIndentationDecrease(Integer.valueOf(indentationDecrease)); it.setNewLinesMin(Integer.valueOf(newLines)); it.setNewLinesDefault(Integer.valueOf(newLines)); it.setNewLinesMax(Integer.valueOf(newLines)); }; final IHiddenRegionFormatting fmt = ObjectExtensions.<IHiddenRegionFormatting>operator_doubleArrow(_createHiddenRegionFormatting, _function); AbstractFormatter2 _formatter = doc.getFormatter(); ITextRegionAccess _textRegionAccess = this._iTextRegionExtensions.getTextRegionAccess(); TextSegment _textSegment = new TextSegment(_textRegionAccess, offset, length); final ITextReplacer replacer = _formatter.createWhitespaceReplacer(_textSegment, fmt); doc.addReplacer(replacer); }
Example #3
Source File: TextReplacerMerger.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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; }
Example #4
Source File: HiddenRegionFormattingToString.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@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); }
Example #5
Source File: N4WhitespaceReplacer.java From n4js with Eclipse Public License 1.0 | 5 votes |
@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); }
Example #6
Source File: FormattableDocument.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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; }
Example #7
Source File: FormattableDocument.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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); }
Example #8
Source File: HiddenRegionFormattingMerger.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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; }
Example #9
Source File: RichStringFormatter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void suppressLineWraps(final Object it) { if (it instanceof HiddenRegionReplacer) { _suppressLineWraps((HiddenRegionReplacer)it); return; } else if (it instanceof IHiddenRegionFormatting) { _suppressLineWraps((IHiddenRegionFormatting)it); return; } else if (it instanceof ITextReplacer) { _suppressLineWraps((ITextReplacer)it); return; } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it).toString()); } }
Example #10
Source File: RichStringFormatter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void _suppressLineWraps(final IHiddenRegionFormatting it) { String _space = it.getSpace(); boolean _tripleEquals = (_space == null); if (_tripleEquals) { it.setSpace(" "); } it.setNewLinesMin(null); it.setNewLinesDefault(null); it.setNewLinesMax(null); it.setAutowrap(null); }
Example #11
Source File: RichStringFormatter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void setSpace(final IFormattableDocument doc, final int offset, final int length, final String space) { IHiddenRegionFormatting _createHiddenRegionFormatting = doc.getFormatter().createHiddenRegionFormatting(); final Procedure1<IHiddenRegionFormatting> _function = (IHiddenRegionFormatting it) -> { it.setSpace(space); }; final IHiddenRegionFormatting fmt = ObjectExtensions.<IHiddenRegionFormatting>operator_doubleArrow(_createHiddenRegionFormatting, _function); AbstractFormatter2 _formatter = doc.getFormatter(); ITextRegionAccess _textRegionAccess = this._iTextRegionExtensions.getTextRegionAccess(); TextSegment _textSegment = new TextSegment(_textRegionAccess, offset, length); final ITextReplacer replacer = _formatter.createWhitespaceReplacer(_textSegment, fmt); doc.addReplacer(replacer); }
Example #12
Source File: DoubleHiddenRegionFormatter.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public DoubleHiddenRegionFormatter(IHiddenRegionFormatting first, IHiddenRegionFormatting second) { super(); this.first = first; this.second = second; }
Example #13
Source File: HiddenRegionReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public HiddenRegionReplacer(IHiddenRegion region, IHiddenRegionFormatting formatting) { super(); this.region = region; this.formatting = formatting; }
Example #14
Source File: HiddenRegionReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public IHiddenRegionFormatting getFormatting() { return formatting; }
Example #15
Source File: SingleHiddenRegionFormatter.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public SingleHiddenRegionFormatter(IHiddenRegionFormatting formatting) { super(); this.formatting = formatting; }
Example #16
Source File: MaxLineWidthDocument.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void validate(HiddenRegionReplacer replacer) throws FormattingNotApplicableException { IHiddenRegionFormatting formatting = replacer.getFormatting(); Integer newLineMin = formatting.getNewLineMin(); if (newLineMin != null && newLineMin < 0) throw new FormattingNotApplicableException(); }
Example #17
Source File: WhitespaceReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public WhitespaceReplacer(ITextSegment whitespace, IHiddenRegionFormatting formatting) { super(); this.region = whitespace; this.formatting = formatting; }
Example #18
Source File: WhitespaceReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public IHiddenRegionFormatting getFormatting() { return formatting; }
Example #19
Source File: N4WhitespaceReplacer.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** */ public N4WhitespaceReplacer(ITextSegment whitespace, IHiddenRegionFormatting formatting) { super(whitespace, formatting); }