org.eclipse.xtext.formatting2.IFormattableDocument Java Examples

The following examples show how to use org.eclipse.xtext.formatting2.IFormattableDocument. 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: BeeLangTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void format(final Object model, final IFormattableDocument document) {
  if (model instanceof XtextResource) {
    _format((XtextResource)model, document);
    return;
  } else if (model instanceof Model) {
    _format((Model)model, document);
    return;
  } else if (model instanceof Unit) {
    _format((Unit)model, document);
    return;
  } else if (model instanceof EObject) {
    _format((EObject)model, document);
    return;
  } else if (model == null) {
    _format((Void)null, document);
    return;
  } else if (model != null) {
    _format(model, document);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(model, document).toString());
  }
}
 
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
/** 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: RichStringFormatter.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
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 #5
Source File: SARLFormatter.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
protected void _format(XBlockExpression expr, IFormattableDocument document) {
	if (getPreferences().getPreference(SARLFormatterPreferenceKeys.ENABLE_SINGLELINE_EXPRESSION).booleanValue()) {
		super._format(expr, document);
	} else {
		// Avoid to format the block expression on a single line.
		final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr);
		if (expr.eContainer() == null) {
			document.surround(expr, NO_SPACE);
		}
		final ISemanticRegion open = regionFor.keyword(this.keywords.getLeftCurlyBracketKeyword());
		final ISemanticRegion close = regionFor.keyword(this.keywords.getRightCurlyBracketKeyword());
		if (open != null && close != null) {
			formatExpressionsMultiline(expr.getExpressions(), open, close, document);
		}
	}
}
 
Example #6
Source File: SARLFormatter.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void format(Object sarlComponent, IFormattableDocument document) {
	try {
		if (sarlComponent instanceof SarlEvent) {
			_format((SarlEvent) sarlComponent, document);
		} else if (sarlComponent instanceof SarlCapacity) {
			_format((SarlCapacity) sarlComponent, document);
		} else if (sarlComponent instanceof SarlAgent) {
			_format((SarlAgent) sarlComponent, document);
		} else if (sarlComponent instanceof SarlBehavior) {
			_format((SarlBehavior) sarlComponent, document);
		} else if (sarlComponent instanceof SarlSkill) {
			_format((SarlSkill) sarlComponent, document);
		} else if (sarlComponent instanceof SarlBehaviorUnit) {
			_format((SarlBehaviorUnit) sarlComponent, document);
		} else if (sarlComponent instanceof SarlCapacityUses) {
			_format((SarlCapacityUses) sarlComponent, document);
		} else if (sarlComponent instanceof SarlRequiredCapacity) {
			_format((SarlRequiredCapacity) sarlComponent, document);
		} else {
			super.format(sarlComponent, document);
		}
	} catch (Throwable exception) {
		// Silently ignore this exception.
	}
}
 
Example #7
Source File: FormatterSerializerIntegrationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void format(final Object model, final IFormattableDocument document) {
  if (model instanceof XtextResource) {
    _format((XtextResource)model, document);
    return;
  } else if (model instanceof IDList) {
    _format((IDList)model, document);
    return;
  } else if (model instanceof EObject) {
    _format((EObject)model, document);
    return;
  } else if (model == null) {
    _format((Void)null, document);
    return;
  } else if (model != null) {
    _format(model, document);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(model, document).toString());
  }
}
 
Example #8
Source File: PartialSerializationTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void format(final Object obj, final IFormattableDocument document) {
  if (obj instanceof XtextResource) {
    _format((XtextResource)obj, document);
    return;
  } else if (obj instanceof Node) {
    _format((Node)obj, document);
    return;
  } else if (obj instanceof EObject) {
    _format((EObject)obj, document);
    return;
  } else if (obj == null) {
    _format((Void)null, document);
    return;
  } else if (obj != null) {
    _format(obj, document);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(obj, document).toString());
  }
}
 
Example #9
Source File: GenericFormatter.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void format(Object obj, IFormattableDocument document) {
	if (obj instanceof XtextResource) {
		_format((XtextResource) obj, document);
		return;
	} else if (obj instanceof EObject) {
		_format((EObject) obj, document);
		return;
	} else if (obj == null) {
		_format((Void) null, document);
		return;
	} else if (obj != null) {
		_format(obj, document);
		return;
	}
}
 
Example #10
Source File: NoJdtTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void format(final Object greeting, final IFormattableDocument document) {
  if (greeting instanceof XtextResource) {
    _format((XtextResource)greeting, document);
    return;
  } else if (greeting instanceof Greeting) {
    _format((Greeting)greeting, document);
    return;
  } else if (greeting instanceof Model) {
    _format((Model)greeting, document);
    return;
  } else if (greeting instanceof EObject) {
    _format((EObject)greeting, document);
    return;
  } else if (greeting == null) {
    _format((Void)null, document);
    return;
  } else if (greeting != null) {
    _format(greeting, document);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(greeting, document).toString());
  }
}
 
Example #11
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 #12
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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 #13
Source File: FileAwareTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void format(final Object element, final IFormattableDocument document) {
  if (element instanceof XtextResource) {
    _format((XtextResource)element, document);
    return;
  } else if (element instanceof Element) {
    _format((Element)element, document);
    return;
  } else if (element instanceof PackageDeclaration) {
    _format((PackageDeclaration)element, document);
    return;
  } else if (element instanceof EObject) {
    _format((EObject)element, document);
    return;
  } else if (element == null) {
    _format((Void)null, document);
    return;
  } else if (element != null) {
    _format(element, document);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(element, document).toString());
  }
}
 
Example #14
Source File: BeeLangTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void _format(final Unit unit, @Extension final IFormattableDocument document) {
  EList<SimpleTypeRef> _implements = unit.getImplements();
  for (final SimpleTypeRef simpleTypeRef : _implements) {
    document.<SimpleTypeRef>format(simpleTypeRef);
  }
  EList<ProvidedCapability> _providedCapabilities = unit.getProvidedCapabilities();
  for (final ProvidedCapability providedCapability : _providedCapabilities) {
    document.<ProvidedCapability>format(providedCapability);
  }
  EList<AliasedRequiredCapability> _requiredCapabilities = unit.getRequiredCapabilities();
  for (final AliasedRequiredCapability aliasedRequiredCapability : _requiredCapabilities) {
    document.<AliasedRequiredCapability>format(aliasedRequiredCapability);
  }
  EList<RequiredCapability> _metaRequiredCapabilities = unit.getMetaRequiredCapabilities();
  for (final RequiredCapability requiredCapability : _metaRequiredCapabilities) {
    document.<RequiredCapability>format(requiredCapability);
  }
  EList<Function> _functions = unit.getFunctions();
  for (final Function function : _functions) {
    document.<Function>format(function);
  }
}
 
Example #15
Source File: RichStringFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XExpression expr, @Extension final IFormattableDocument doc) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.noSpace();
  };
  doc.<XExpression>surround(expr, _function);
  this.formatIntoSingleLine(doc, expr);
}
 
Example #16
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 #17
Source File: PureXbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@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 #18
Source File: XtendFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Always put existing modifiers into this fixed order
 */
protected void formatModifiers(final XtendMember member, @Extension final IFormattableDocument document) {
  final Consumer<ISemanticRegion> _function = (ISemanticRegion it) -> {
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
      it_1.oneSpace();
    };
    document.append(it, _function_1);
  };
  this.textRegionExtensions.regionFor(member).ruleCallsTo(this._xtendGrammarAccess.getCommonModifierRule(), this._xtendGrammarAccess.getMethodModifierRule(), this._xtendGrammarAccess.getFieldModifierRule()).forEach(_function);
}
 
Example #19
Source File: SARLFormatter.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Format the given SARL behavior.
 *
 * @param behavior the SARL component.
 * @param document the document.
 */
protected void _format(SarlBehavior behavior, IFormattableDocument document) {
	formatAnnotations(behavior, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations);
	formatModifiers(behavior, document);

	final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(behavior);
	document.append(regionFor.keyword(this.keywords.getBehaviorKeyword()), ONE_SPACE);

	document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE);
	document.format(behavior.getExtends());

	formatBody(behavior, document);
}
 
Example #20
Source File: RichStringFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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 #21
Source File: SARLFormatter.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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 #22
Source File: SARLFormatter.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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 #23
Source File: RichStringFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void formatIntoSingleLine(final IFormattableDocument doc, final EObject obj) {
  final Predicate<ITextReplacer> _function = (ITextReplacer it) -> {
    boolean _xblockexpression = false;
    {
      this.suppressLineWraps(it);
      _xblockexpression = true;
    }
    return _xblockexpression;
  };
  doc.getFormatter().format(obj, doc.withReplacerFilter(_function));
}
 
Example #24
Source File: TestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void format(final Object property, final IFormattableDocument document) {
  if (property instanceof XtextResource) {
    _format((XtextResource)property, document);
    return;
  } else if (property instanceof Property) {
    _format((Property)property, document);
    return;
  } else if (property instanceof TypeDeclaration) {
    _format((TypeDeclaration)property, document);
    return;
  } else if (property instanceof Model) {
    _format((Model)property, document);
    return;
  } else if (property instanceof EObject) {
    _format((EObject)property, document);
    return;
  } else if (property == null) {
    _format((Void)null, document);
    return;
  } else if (property != null) {
    _format(property, document);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(property, document).toString());
  }
}
 
Example #25
Source File: RichStringFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void format(final EObject richString, final IFormattableDocument doc) {
  if (richString instanceof RichString) {
    _format((RichString)richString, doc);
    return;
  } else if (richString instanceof RichStringForLoop) {
    _format((RichStringForLoop)richString, doc);
    return;
  } else if (richString instanceof RichStringLiteral) {
    _format((RichStringLiteral)richString, doc);
    return;
  } else if (richString instanceof RichStringIf) {
    _format((RichStringIf)richString, doc);
    return;
  } else if (richString instanceof RichStringElseIf) {
    _format((RichStringElseIf)richString, doc);
    return;
  } else if (richString instanceof XExpression) {
    _format((XExpression)richString, doc);
    return;
  } else if (richString == null) {
    _format((Void)null, doc);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(richString, doc).toString());
  }
}
 
Example #26
Source File: SARLFormatter.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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 #27
Source File: BeeLangTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final Model model, @Extension final IFormattableDocument document) {
  EList<Unit> _units = model.getUnits();
  for (final Unit unit : _units) {
    document.<Unit>format(unit);
  }
  EList<Function> _functions = model.getFunctions();
  for (final Function function : _functions) {
    document.<Function>format(function);
  }
}
 
Example #28
Source File: TextReplacerContext.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TextReplacerContext(IFormattableDocument document, ITextReplacerContext previous, int indentation,
		ITextReplacer replacer) {
	super();
	this.document = document;
	this.indentation = indentation;
	this.previous = previous;
	this.replacer = replacer;
	this.replacements = createTextReplacementsSet();
}
 
Example #29
Source File: TextReplacerContext.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ITextReplacerContext withDocument(IFormattableDocument document) {
	TextReplacerContext context = new TextReplacerContext(document, this, indentation, null);
	if (this.nextReplacerIsChild)
		context.setNextReplacerIsChild();
	return context;
}
 
Example #30
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);
	}
}