Java Code Examples for org.eclipse.xtext.formatting2.IFormattableDocument#prepend()

The following examples show how to use org.eclipse.xtext.formatting2.IFormattableDocument#prepend() . 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 vote down vote up
protected void _format(final XFeatureCall expr, @Extension final IFormattableDocument format) {
  this.formatFeatureCallTypeParameters(expr, format);
  boolean _isExplicitOperationCall = expr.isExplicitOperationCall();
  if (_isExplicitOperationCall) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
      it.noSpace();
    };
    final ISemanticRegion open = format.prepend(this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getExplicitOperationCallLeftParenthesisKeyword_3_0_0()), _function);
    final ISemanticRegion close = this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getRightParenthesisKeyword_3_2());
    this.formatFeatureCallParams(expr.getFeatureCallArguments(), open, close, format);
  } else {
    EList<XExpression> _featureCallArguments = expr.getFeatureCallArguments();
    for (final XExpression arg : _featureCallArguments) {
      this.format(arg, format);
    }
  }
}
 
Example 2
Source File: SARLFormatter.java    From sarl with Apache License 2.0 6 votes vote down vote up
@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 vote down vote up
@Override
protected void _format(XForLoopExpression expr, IFormattableDocument document) {
	final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr);
	document.append(regionFor.keyword(this.keywords.getForKeyword()), ONE_SPACE);

	final JvmFormalParameter declaredParam = expr.getDeclaredParam();
	document.prepend(declaredParam, NO_SPACE);
	document.append(declaredParam, ONE_SPACE);
	document.format(declaredParam);

	final XExpression forExpression = expr.getForExpression();
	document.prepend(forExpression, ONE_SPACE);
	document.append(forExpression, NO_SPACE);
	document.format(forExpression);

	final XExpression eachExpression = expr.getEachExpression();
	if (eachExpression != null) {
		formatBody(eachExpression, true, document);
	} else {
		document.prepend(regionFor.keyword(this.keywords.getSemicolonKeyword()), NO_SPACE);
	}
}
 
Example 4
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XThrowExpression expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.<XExpression>prepend(expr.getExpression(), _function);
  format.<XExpression>format(expr.getExpression());
}
 
Example 5
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XReturnExpression expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.<XExpression>prepend(expr.getExpression(), _function);
  format.<XExpression>format(expr.getExpression());
}
 
Example 6
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XPostfixOperation expr, @Extension final IFormattableDocument doc) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.noSpace();
  };
  doc.prepend(this.textRegionExtensions.regionFor(expr).feature(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE), _function);
  doc.<XExpression>format(expr.getOperand());
}
 
Example 7
Source File: XtypeFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final JvmTypeParameter ref, @Extension final IFormattableDocument document) {
  EList<JvmTypeConstraint> _constraints = ref.getConstraints();
  for (final JvmTypeConstraint c : _constraints) {
    {
      final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
      };
      document.<JvmTypeConstraint>prepend(c, _function);
      document.<JvmTypeConstraint>format(c);
    }
  }
}
 
Example 8
Source File: SARLFormatter.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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 9
Source File: SARLFormatter.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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 10
Source File: SARLFormatter.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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 11
Source File: SARLFormatter.java    From sarl with Apache License 2.0 4 votes vote down vote up
@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);
}