Java Code Examples for org.eclipse.xtext.formatting2.IFormattableDocument#append()
The following examples show how to use
org.eclipse.xtext.formatting2.IFormattableDocument#append() .
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: XbaseFormatter.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void _format(final XCollectionLiteral literal, @Extension final IFormattableDocument document) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.noSpace(); }; document.append(this.textRegionExtensions.regionFor(literal).keyword("#"), _function); ISemanticRegion _elvis = null; ISemanticRegion _keyword = this.textRegionExtensions.regionFor(literal).keyword("["); if (_keyword != null) { _elvis = _keyword; } else { ISemanticRegion _keyword_1 = this.textRegionExtensions.regionFor(literal).keyword("{"); _elvis = _keyword_1; } final ISemanticRegion open = _elvis; ISemanticRegion _elvis_1 = null; ISemanticRegion _keyword_2 = this.textRegionExtensions.regionFor(literal).keyword("]"); if (_keyword_2 != null) { _elvis_1 = _keyword_2; } else { ISemanticRegion _keyword_3 = this.textRegionExtensions.regionFor(literal).keyword("}"); _elvis_1 = _keyword_3; } final ISemanticRegion close = _elvis_1; this.formatCommaSeparatedList(literal.getElements(), open, close, document); }
Example 2
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 6 votes |
@Override protected void _format(XtendField field, IFormattableDocument document) { formatAnnotations(field, document, XbaseFormatterPreferenceKeys.newLineAfterFieldAnnotations); formatModifiers(field, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(field); final ISemanticRegion columnKw = regionFor.keyword(this.keywords.getColonKeyword()); document.prepend(columnKw, ONE_SPACE); document.append(columnKw, ONE_SPACE); final ISemanticRegion equalKw = regionFor.keyword(this.keywords.getEqualsSignKeyword()); document.prepend(equalKw, ONE_SPACE); document.append(equalKw, ONE_SPACE); final ISemanticRegion semicolumn = regionFor.keyword(this.keywords.getSemicolonKeyword()); document.prepend(semicolumn, NO_SPACE); final JvmTypeReference type = field.getType(); document.format(type); final XExpression initialValue = field.getInitialValue(); document.format(initialValue); }
Example 3
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 6 votes |
/** Format the given SARL skill. * * @param skill the SARL component. * @param document the document. */ protected void _format(SarlSkill skill, IFormattableDocument document) { formatAnnotations(skill, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(skill, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(skill); document.append(regionFor.keyword(this.keywords.getSkillKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(skill.getExtends()); document.surround(regionFor.keyword(this.keywords.getImplementsKeyword()), ONE_SPACE); formatCommaSeparatedList(skill.getImplements(), document); formatBody(skill, document); }
Example 4
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format a list of comma separated elements. * * <p>This function does not considerer opening and closing delimiters, as * {@link #formatCommaSeparatedList(Collection, ISemanticRegion, ISemanticRegion, IFormattableDocument)}. * * @param elements the elements to format. * @param document the document. */ protected void formatCommaSeparatedList(Collection<? extends EObject> elements, IFormattableDocument document) { for (final EObject element : elements) { document.format(element); final ISemanticRegionFinder immediatelyFollowing = this.textRegionExtensions.immediatelyFollowing(element); final ISemanticRegion keyword = immediatelyFollowing.keyword(this.keywords.getCommaKeyword()); document.prepend(keyword, NO_SPACE); document.append(keyword, ONE_SPACE); } }
Example 5
Source File: PureXbaseFormatter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void _format(final XBlockExpression xBlockExpression, @Extension final IFormattableDocument document) { final Consumer<ISemanticRegion> _function = (ISemanticRegion it) -> { final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> { it_1.newLine(); }; document.append(it, _function_1); }; this.textRegionExtensions.regionFor(xBlockExpression).keywords(this._pureXbaseGrammarAccess.getSpecialBlockExpressionAccess().getSemicolonKeyword_1_1()).forEach(_function); EList<XExpression> _expressions = xBlockExpression.getExpressions(); for (final XExpression xExpression : _expressions) { document.<XExpression>format(xExpression); } }
Example 6
Source File: XbaseFormatter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _format(final JvmFormalParameter expr, @Extension final IFormattableDocument format) { JvmTypeReference _parameterType = expr.getParameterType(); if (_parameterType!=null) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.oneSpace(); }; format.<JvmTypeReference>append(_parameterType, _function); } format.<JvmTypeReference>format(expr.getParameterType()); }
Example 7
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format a required capacity. * * @param requiredCapacity the element ot format. * @param document the document. */ protected void _format(SarlRequiredCapacity requiredCapacity, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(requiredCapacity); document.append(regionFor.keyword(this.keywords.getRequiresKeyword()), ONE_SPACE); formatCommaSeparatedList(requiredCapacity.getCapacities(), document); document.prepend(regionFor.keyword(this.keywords.getSemicolonKeyword()), NO_SPACE); }
Example 8
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format the given SARL agent. * * @param agent the SARL component. * @param document the document. */ protected void _format(SarlAgent agent, IFormattableDocument document) { formatAnnotations(agent, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(agent, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(agent); document.append(regionFor.keyword(this.keywords.getAgentKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(agent.getExtends()); formatBody(agent, document); }
Example 9
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format the given SARL capacity. * * @param capacity the SARL component. * @param document the document. */ protected void _format(SarlCapacity capacity, IFormattableDocument document) { formatAnnotations(capacity, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(capacity, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(capacity); document.append(regionFor.keyword(this.keywords.getCapacityKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); formatCommaSeparatedList(capacity.getExtends(), document); formatBody(capacity, document); }
Example 10
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format the given SARL event. * * @param event the SARL component. * @param document the document. */ protected void _format(SarlEvent event, IFormattableDocument document) { formatAnnotations(event, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); formatModifiers(event, document); final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(event); document.append(regionFor.keyword(this.keywords.getEventKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE); document.format(event.getExtends()); formatBody(event, document); }
Example 11
Source File: XtendFormatter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected void _format(final JvmFormalParameter expr, @Extension final IFormattableDocument format) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.oneSpace(); }; format.append(this.textRegionExtensions.regionFor(expr).keyword("extension"), _function); super._format(expr, format); }
Example 12
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
/** Format a capacity use. * * @param capacityUses the capacity uses. * @param document the document. */ protected void _format(SarlCapacityUses capacityUses, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(capacityUses); document.append(regionFor.keyword(this.keywords.getUsesKeyword()), ONE_SPACE); formatCommaSeparatedList(capacityUses.getCapacities(), document); document.prepend(regionFor.keyword(this.keywords.getSemicolonKeyword()), NO_SPACE); }
Example 13
Source File: XtendFormatter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void _format(final XtendAnnotationType annotationType, @Extension final IFormattableDocument format) { this.formatAnnotations(annotationType, format, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations); this.formatModifiers(annotationType, format); final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.oneSpace(); }; format.append(this.textRegionExtensions.regionFor(annotationType).keyword("annotation"), _function); this.formatBody(annotationType, format); }
Example 14
Source File: XtendFormatter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void formatAnnotations(final XtendAnnotationTarget target, @Extension final IFormattableDocument document, final Procedure1<? super IHiddenRegionFormatter> configKey) { boolean _isEmpty = target.getAnnotations().isEmpty(); if (_isEmpty) { return; } EList<XAnnotation> _annotations = target.getAnnotations(); for (final XAnnotation a : _annotations) { { document.<XAnnotation>format(a); document.<XAnnotation>append(a, configKey); } } }
Example 15
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 5 votes |
@Override protected void _format(XVariableDeclaration expr, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr); document.append(regionFor.keyword(this.keywords.getExtensionExtensionKeyword()), ONE_SPACE); document.append(regionFor.keyword(this.keywords.getValKeyword()), ONE_SPACE); document.append(regionFor.keyword(this.keywords.getWriteableVarKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getColonKeyword()), ONE_SPACE); document.surround(regionFor.keyword(this.keywords.getEqualsSignKeyword()), ONE_SPACE); document.format(expr.getType()); document.format(expr.getRight()); }
Example 16
Source File: XtypeFormatter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void _format(final JvmWildcardTypeReference ref, @Extension final IFormattableDocument document) { boolean _isEmpty = ref.getConstraints().isEmpty(); boolean _not = (!_isEmpty); if (_not) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.oneSpace(); }; document.append(this.textRegionExtensions.regionFor(ref).keyword("?"), _function); } EList<JvmTypeConstraint> _constraints = ref.getConstraints(); for (final JvmTypeConstraint c : _constraints) { document.<JvmTypeConstraint>format(c); } }
Example 17
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("checkstyle:cyclomaticcomplexity") protected ISemanticRegion formatBody(XtendTypeDeclaration type, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(type); final ISemanticRegion open = regionFor.keyword(this.keywords.getLeftCurlyBracketKeyword()); final ISemanticRegion close = regionFor.keyword(this.keywords.getRightCurlyBracketKeyword()); document.prepend(open, XbaseFormatterPreferenceKeys.bracesInNewLine); document.interior(open, close, INDENT); final EList<XtendMember> members = type.getMembers(); if (!members.isEmpty()) { XtendMember previous = null; for (final XtendMember current : members) { document.format(current); if (previous == null) { document.prepend(current, XtendFormatterPreferenceKeys.blankLinesBeforeFirstMember); } else if (previous instanceof XtendField) { if (current instanceof XtendField) { document.append(previous, XtendFormatterPreferenceKeys.blankLinesBetweenFields); } else { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_MEMBER_CATEGORIES); } } else if (previous instanceof XtendExecutable) { if (current instanceof XtendExecutable) { document.append(previous, XtendFormatterPreferenceKeys.blankLinesBetweenMethods); } else { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_MEMBER_CATEGORIES); } } else if (previous instanceof XtendTypeDeclaration) { if (current instanceof XtendTypeDeclaration) { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_INNER_TYPES); } else { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_MEMBER_CATEGORIES); } } else if (previous instanceof XtendEnumLiteral) { if (current instanceof XtendEnumLiteral) { document.append(previous, XtendFormatterPreferenceKeys.blankLinesBetweenEnumLiterals); } else { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_MEMBER_CATEGORIES); } } else if (previous instanceof SarlCapacityUses) { if (current instanceof SarlCapacityUses) { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_CAPACITY_USES); } else { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_MEMBER_CATEGORIES); } } else if (previous instanceof SarlRequiredCapacity) { if (current instanceof SarlCapacityUses) { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_CAPACITY_REQUIREMENTS); } else { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_MEMBER_CATEGORIES); } } else { document.append(previous, SARLFormatterPreferenceKeys.BLANK_LINES_BETWEEN_MEMBER_CATEGORIES); } previous = current; } if (previous != null) { document.append(previous, XtendFormatterPreferenceKeys.blankLinesAfterLastMember); } return null; } return document.append(open, NEW_LINE); }
Example 18
Source File: TestLanguageFormatter.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void _format(final Property property, @Extension final IFormattableDocument document) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.newLine(); }; document.<Property>append(property, _function); }
Example 19
Source File: NoJdtTestLanguageFormatter.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void _format(final Greeting greeting, @Extension final IFormattableDocument document) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.setNewLines(1, 1, 2); }; document.<Greeting>append(greeting, _function); }
Example 20
Source File: FormatterSerializerIntegrationTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void _format(final IDList model, @Extension final IFormattableDocument document) { final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> { it.setSpace(" "); }; document.append(this.textRegionExtensions.regionFor(model).keyword("idlist"), _function); }