org.eclipse.xtext.formatting.impl.FormattingConfig Java Examples

The following examples show how to use org.eclipse.xtext.formatting.impl.FormattingConfig. 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
public void configure(FormattingConfig c, XbaseGrammarAccess ga) {
	xtypeFormatter.configure(c, ga.getXtypeGrammarAccess());
	configureXUnaryOperation(c, ga.getXUnaryOperationAccess());
	configureXPostfixOperation(c, ga.getXPostfixOperationAccess());
	configureXMemberFeatureCall(c, ga.getXMemberFeatureCallAccess());
	configureXClosure(c, ga.getXClosureAccess());
	configureXShortClosure(c, ga.getXShortClosureAccess());
	configureXParenthesizedExpression(c, ga.getXParenthesizedExpressionAccess());
	configureXIfExpression(c, ga.getXIfExpressionAccess());
	configureXSynchronizedExpression(c, ga.getXSynchronizedExpressionAccess());
	configureXSwitchExpression(c, ga.getXSwitchExpressionAccess());
	configureXCasePart(c, ga.getXCasePartAccess());
	configureXForLoopExpression(c, ga.getXForLoopExpressionAccess());
	configureXBasicForLoopExpression(c, ga.getXBasicForLoopExpressionAccess());
	configureXWhileExpression(c, ga.getXWhileExpressionAccess());
	configureXDoWhileExpression(c, ga.getXDoWhileExpressionAccess());
	configureXBlockExpression(c, ga.getXBlockExpressionAccess());
	configureXFeatureCall(c, ga.getXFeatureCallAccess());
	configureXConstructorCall(c, ga.getXConstructorCallAccess());
	configureXTypeLiteral(c, ga.getXTypeLiteralAccess());
	configureXTryCatchFinallyExpression(c, ga.getXTryCatchFinallyExpressionAccess());
	configureXCatchClause(c, ga.getXCatchClauseAccess());
}
 
Example #2
Source File: CheckCfgFormatter.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Entry point for Check Configuration formatting.
 *
 * @param c
 *          the formatting configuration
 * @param g
 *          the grammar access
 */
private void configure(final FormattingConfig c, final CheckCfgGrammarAccess g) {
  super.configure(c, g.getXbaseGrammarAccess());

  // Comments
  c.setLinewrap(0, 1, 2).before(g.getSL_COMMENTRule());
  c.setLinewrap(0, 1, 2).before(g.getML_COMMENTRule());
  c.setLinewrap(0, 1, 1).after(g.getML_COMMENTRule());

  // AutoLineWrap
  c.setAutoLinewrap(LINE_WRAP_LENGTH);

  configureCheckConfiguration(c, g.getCheckConfigurationAccess());
  configureLanguageValidatorConfiguration(c, g.getConfiguredLanguageValidatorAccess());
  configureConfiguredCatalog(c, g.getConfiguredCatalogAccess());
  configureConfiguredCheck(c, g.getConfiguredCheckAccess());
  // configureConfiguredParameter(c, g.getConfiguredParameterAccess());
}
 
Example #3
Source File: DotColorListFormatter.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configureFormatting(FormattingConfig c) {
	/**
	 * Configure the dot colorList formatter not set an extra white space
	 * after the '#' symbol and after the hex digits. It should produce
	 * '#abcdef' instead of '# ab cd ef'.
	 */
	c.setNoSpace().around(grammarAccess.getHexRule());

	/**
	 * Configure the dot colorList formatter not set an extra white space
	 * before and after the '/' symbol. It should produce '/svg/white'
	 * instead of '/ svg / white'.
	 */
	for (Keyword keyWord : grammarAccess.findKeywords("/")) {
		c.setNoSpace().around(keyWord);
	}
}
 
Example #4
Source File: DotFormatter.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private void configureSubgraphFormatting(FormattingConfig c) {
	SubgraphElements subgraph = grammarAccess.getSubgraphAccess();

	// newline after {
	c.setLinewrap(1, 1, 2).after(subgraph.getLeftCurlyBracketKeyword_2());

	// newline before }
	c.setLinewrap().before(subgraph.getRightCurlyBracketKeyword_4());

	// indentation between { }
	c.setIndentation(subgraph.getLeftCurlyBracketKeyword_2(),
			subgraph.getRightCurlyBracketKeyword_4());

	// newline after the subgraph's statements
	c.setLinewrap(1, 1, 2).after(subgraph.getStmtsAssignment_3());

	// an empty line before the subgraph itself
	c.setLinewrap(2, 2, 2).before(subgraph.getRule());
}
 
Example #5
Source File: ExBeeLangTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
	protected void configureFormatting(FormattingConfig c) {
// It's usually a good idea to activate the following three statements.
// They will add and preserve newlines around comments
//		c.setLinewrap(0, 1, 2).before(getGrammarAccess().getSL_COMMENTRule());
//		c.setLinewrap(0, 1, 2).before(getGrammarAccess().getML_COMMENTRule());
//		c.setLinewrap(0, 1, 1).after(getGrammarAccess().getML_COMMENTRule());
	}
 
Example #6
Source File: SGenFormatter.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void configureFormatting(FormattingConfig c) {
	SGenGrammarAccess g = (SGenGrammarAccess) getGrammarAccess();
	// It's usually a good idea to activate the following three statements.
	// They will add and preserve newlines around comments
	c.setLinewrap(0, 1, 2).before(g.getSL_COMMENTRule());
	c.setLinewrap(0, 1, 2).before(g.getML_COMMENTRule());
	c.setLinewrap(0, 1, 1).after(g.getML_COMMENTRule());
	c.setLinewrap().before(g.getPropertyDefinitionRule());

	// Find elements which declare their body in curly brackets.
	// - Increment Indentation for the body.
	// - Line wrap before opening and after closing element
	for (Pair<Keyword, Keyword> pair : grammar.findKeywordPairs("{", "}")) {
		c.setIndentation(pair.getFirst(), pair.getSecond());
		c.setLinewrap().after(pair.getFirst());
		c.setLinewrap().around(pair.getSecond());

		Keyword openingBrace = pair.getFirst();
		Group containingGroup = (Group) openingBrace.eContainer();

		c.setLinewrap(1, 2, 2).before(containingGroup);
		c.setLinewrap(1, 1, 2).after(containingGroup);
	}

	c.setLinewrap().around(g.getFeatureConfigurationRule());
	c.setLinewrap().around(g.getFeatureParameterValueRule());
	c.setNoLinewrap().after(g.getGeneratorEntryAccess().getContentTypeAssignment_0());
	c.setNoLinewrap().after(g.getFeatureConfigurationAccess().getFeatureKeyword_1());
	c.setNoLinewrap().before(g.getGeneratorModelAccess().getGeneratorModelKeyword_0());

}
 
Example #7
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void configureXBlockExpression(FormattingConfig c, XBlockExpressionElements ele) {
	c.setLinewrap().after(ele.getLeftCurlyBracketKeyword_1());
	c.setIndentationIncrement().after(ele.getLeftCurlyBracketKeyword_1());
	c.setLinewrap().after(ele.getExpressionsAssignment_2_0());
	c.setNoSpace().before(ele.getSemicolonKeyword_2_1());
	c.setLinewrap().after(ele.getSemicolonKeyword_2_1());
	c.setLinewrap().before(ele.getRightCurlyBracketKeyword_3());
	c.setIndentationDecrement().before(ele.getRightCurlyBracketKeyword_3());
}
 
Example #8
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void configureXCasePart(FormattingConfig c, XCasePartElements ele) {
	c.setNoSpace().before(ele.getColonKeyword_3_0_0());
	c.setNoSpace().before(ele.getFallThroughCommaKeyword_3_1_0());
	c.setIndentationIncrement().before(ele.getThenAssignment_3_0_1());
	c.setLinewrap().around(ele.getThenAssignment_3_0_1());
	c.setIndentationDecrement().after(ele.getThenAssignment_3_0_1());
}
 
Example #9
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void configureXSynchronizedExpression(FormattingConfig c, XSynchronizedExpressionElements ele) {
	c.setNoSpace().around(ele.getLeftParenthesisKeyword_0_0_2());
	c.setNoSpace().before(ele.getRightParenthesisKeyword_2());
	c.setLinewrap().around(ele.getExpressionAssignment_3());
	c.setIndentationIncrement().before(ele.getExpressionAssignment_3());
	c.setIndentationDecrement().after(ele.getExpressionAssignment_3());
}
 
Example #10
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void configureXIfExpression(FormattingConfig c, XIfExpressionElements ele) {
	c.setNoSpace().around(ele.getLeftParenthesisKeyword_2());
	c.setNoSpace().before(ele.getRightParenthesisKeyword_4());
	c.setLinewrap().around(ele.getThenAssignment_5());
	c.setIndentationIncrement().before(ele.getThenAssignment_5());
	c.setIndentationDecrement().after(ele.getThenAssignment_5());
	c.setLinewrap().around(ele.getElseAssignment_6_1());
	c.setIndentationIncrement().before(ele.getElseAssignment_6_1());
	c.setIndentationDecrement().after(ele.getElseAssignment_6_1());
}
 
Example #11
Source File: CheckFormatter.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Configure check.
 *
 * @param c
 *          the formatting configuration
 * @param elements
 *          the accessible formattable parser elements
 */
private void configureCheck(final FormattingConfig c, final CheckElements elements) {
  c.setNoSpace().between(elements.getLeftParenthesisKeyword_6_0(), elements.getRightParenthesisKeyword_6_2());
  c.setLinewrap(1, 1, 2).before(elements.getMessageKeyword_7_0());

  c.setNoSpace().after(elements.getLeftParenthesisKeyword_6_0());
  c.setNoSpace().before(elements.getRightParenthesisKeyword_6_2());
  c.setNoSpace().before(elements.getCommaKeyword_6_1_1_0());
  c.setLinewrap(0, 0, 1).after(elements.getCommaKeyword_6_1_1_0());
  c.setLinewrap(1, 2, 2).around(elements.getContextsAssignment_8_0_1());
}
 
Example #12
Source File: ConditionModelFormatter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
	protected void configureFormatting(FormattingConfig c) {
// It's usually a good idea to activate the following three statements.
// They will add and preserve newlines around comments
//		c.setLinewrap(0, 1, 2).before(getGrammarAccess().getSL_COMMENTRule());
//		c.setLinewrap(0, 1, 2).before(getGrammarAccess().getML_COMMENTRule());
//		c.setLinewrap(0, 1, 1).after(getGrammarAccess().getML_COMMENTRule());
	}
 
Example #13
Source File: DotHtmlLabelFormatter.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void configureHtmlAttributeFormatting(FormattingConfig c) {
	HtmlAttrElements htmlAttribute = grammarAccess.getHtmlAttrAccess();

	// one space before the html attribute name
	c.setSpace(" ").before(htmlAttribute.getNameAssignment_0());

	// no space after the html attribute name
	c.setNoSpace().after(htmlAttribute.getNameAssignment_0());

	// no space before the html attribute value
	c.setNoSpace().before(htmlAttribute.getValueAssignment_4());
}
 
Example #14
Source File: DotHtmlLabelFormatter.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void configureHtmlTagFormatting(FormattingConfig c) {
	HtmlTagElements htmlTag = grammarAccess.getHtmlTagAccess();

	// no space before and after the html tag name
	c.setNoSpace().around(htmlTag.getNameAssignment_1());

	// line break before and after the html tag's child
	c.setLinewrap(1, 1, 1).around(htmlTag.getChildrenAssignment_3_1_1());

	// indentation before and after the html tag's child
	c.setIndentationIncrement()
			.before(htmlTag.getChildrenAssignment_3_1_1());

	// dedentation before and after the html tag's child
	c.setIndentationDecrement()
			.after(htmlTag.getChildrenAssignment_3_1_1());

	// no space before and after the html tag close name
	c.setNoSpace().around(htmlTag.getCloseNameAssignment_3_1_3());

	// no space before the '>' symbol
	c.setNoSpace().before(htmlTag.getTAG_ENDTerminalRuleCall_3_1_0());

	// set a line wrap after the '>' symbol that is part of an end tag
	c.setLinewrap(1, 1, 1)
			.after(htmlTag.getTAG_ENDTerminalRuleCall_3_1_4());

	// set a line wrap after the '>' symbol that is part of a self-closing
	// end tag
	c.setLinewrap(1, 1, 1).after(
			htmlTag.getSelfClosingTAG_END_CLOSETerminalRuleCall_3_0_0());
}
 
Example #15
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void configureXWhileExpression(FormattingConfig c, XWhileExpressionElements ele) {
	c.setNoSpace().around(ele.getLeftParenthesisKeyword_2());
	c.setNoSpace().before(ele.getRightParenthesisKeyword_4());
	c.setIndentationIncrement().before(ele.getBodyAssignment_5());
	c.setLinewrap().around(ele.getBodyAssignment_5());
	c.setIndentationDecrement().after(ele.getBodyAssignment_5());
}
 
Example #16
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void configureXDoWhileExpression(FormattingConfig c, XDoWhileExpressionElements ele) {
	c.setLinewrap().after(ele.getDoKeyword_1());
	c.setIndentationIncrement().after(ele.getDoKeyword_1());
	c.setLinewrap().before(ele.getDoKeyword_1());
	c.setIndentationDecrement().before(ele.getWhileKeyword_3());
	c.setNoSpace().around(ele.getLeftParenthesisKeyword_4());
	c.setNoSpace().before(ele.getRightParenthesisKeyword_6());
}
 
Example #17
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void configureXFeatureCall(FormattingConfig c, XFeatureCallElements ele) {
	c.setNoSpace().around(ele.getLessThanSignKeyword_1_0());
	c.setNoSpace().before(ele.getCommaKeyword_1_2_0());
	c.setNoSpace().around(ele.getGreaterThanSignKeyword_1_3());
	c.setNoSpace().around(ele.getExplicitOperationCallAssignment_3_0());
	c.setNoSpace().before(ele.getCommaKeyword_3_1_1_1_0());
	c.setNoSpace().before(ele.getRightParenthesisKeyword_3_2());
}
 
Example #18
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void configureXConstructorCall(FormattingConfig c, XConstructorCallElements ele) {
	c.setNoSpace().around(ele.getLessThanSignKeyword_3_0());
	c.setNoSpace().before(ele.getCommaKeyword_3_2_0());
	c.setNoSpace().around(ele.getGreaterThanSignKeyword_3_3());
	c.setNoSpace().around(ele.getExplicitConstructorCallLeftParenthesisKeyword_4_0_0());
	c.setNoSpace().before(ele.getCommaKeyword_4_1_1_1_0());
	c.setNoSpace().before(ele.getRightParenthesisKeyword_4_2());
}
 
Example #19
Source File: CheckFormatter.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * (Re-) Configure feature call formatting.
 *
 * @param c
 *          the formatting configuration
 * @param featureCallElements
 *          the feature call elements
 */
private void configureFeatureCall(final FormattingConfig c, final XMemberFeatureCallElements featureCallElements) {
  // set no space after '::' in CheckUtil::hasQualifiedName(..., and also not after plain "." or "?."
  c.setNoSpace().after(featureCallElements.getFullStopKeyword_1_0_0_0_1_0());
  c.setNoSpace().after(featureCallElements.getFullStopKeyword_1_1_0_0_1_0());
  c.setNoSpace().after(featureCallElements.getNullSafeAssignment_1_1_0_0_1_1());
  c.setNoSpace().after(featureCallElements.getExplicitStaticAssignment_1_0_0_0_1_1());
  c.setNoSpace().after(featureCallElements.getExplicitStaticAssignment_1_1_0_0_1_2());
}
 
Example #20
Source File: GamlFormatter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private void handleBlockTermination(final FormattingConfig c, final Keyword closing, final int lineWrapAfter) {

		// c.setSpace("\n/*closing*/").before(closing);
		c.setLinewrap(0, 0, 1).before(closing);
		c.setIndentationDecrement().before(closing);
		c.setLinewrap(lineWrapAfter).after(closing);
		// c.setSpace(" ").after(closing);
	}
 
Example #21
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void configureXCatchClause(FormattingConfig c, XCatchClauseElements ele) {
	c.setNoSpace().around(ele.getLeftParenthesisKeyword_1());
	c.setNoSpace().before(ele.getRightParenthesisKeyword_3());
	c.setIndentationIncrement().before(ele.getExpressionAssignment_4());
	c.setLinewrap().around(ele.getExpressionAssignment_4());
	c.setIndentationDecrement().after(ele.getExpressionAssignment_4());
}
 
Example #22
Source File: DotFormatter.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void configureCommentsFormatting(FormattingConfig c) {
	// It's usually a good idea to activate the following three statements.
	// They will add and preserve newlines around comments
	c.setLinewrap(0, 1, 2).before(grammarAccess.getSL_COMMENTRule());
	c.setLinewrap(0, 1, 2).before(grammarAccess.getML_COMMENTRule());
	c.setLinewrap(0, 1, 1).after(grammarAccess.getML_COMMENTRule());
}
 
Example #23
Source File: CheckCfgFormatter.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Configures formatting for Configured Check.
 *
 * @param c
 *          the formatting configuration
 * @param elements
 *          the Configured Check elements
 */
private void configureConfiguredCheck(final FormattingConfig c, final ConfiguredCheckElements elements) {
  c.setLinewrap().before(elements.getSeverityAssignment_1());
  c.setNoSpace().after(elements.getLeftParenthesisKeyword_3_0());
  c.setNoSpace().before(elements.getRightParenthesisKeyword_3_3());
  c.setNoSpace().before(elements.getCommaKeyword_3_2_0());

  c.setLinewrap(0, 0, 1).after(elements.getCommaKeyword_3_2_0());
  c.setIndentation(elements.getLeftParenthesisKeyword_3_0(), elements.getRightParenthesisKeyword_3_3());
}
 
Example #24
Source File: DotFormatter.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configureFormatting(FormattingConfig c) {
	// auto line wrap lines longer than 120 characters
	c.setAutoLinewrap(120);

	configureKeywordFormatting(c);
	configureGraphFormatting(c);
	configureSubgraphFormatting(c);
	configureCommentsFormatting(c);
}
 
Example #25
Source File: BeeLangTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
	protected void configureFormatting(FormattingConfig c) {
// It's usually a good idea to activate the following three statements.
// They will add and preserve newlines around comments
//		c.setLinewrap(0, 1, 2).before(getGrammarAccess().getSL_COMMENTRule());
//		c.setLinewrap(0, 1, 2).before(getGrammarAccess().getML_COMMENTRule());
//		c.setLinewrap(0, 1, 1).after(getGrammarAccess().getML_COMMENTRule());
	}
 
Example #26
Source File: StatemachineFormatter.java    From xtext-web with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configureFormatting(final FormattingConfig c) {
	c.setLinewrap(0, 1, 2).before(this.statemachineGrammarAccess.getSL_COMMENTRule());
	c.setLinewrap(0, 1, 2).before(this.statemachineGrammarAccess.getML_COMMENTRule());
	c.setLinewrap(0, 1, 1).after(this.statemachineGrammarAccess.getML_COMMENTRule());
	c.setLinewrap().before(this.statemachineGrammarAccess.getInputSignalAccess().getInputKeyword_1());
	c.setLinewrap().before(this.statemachineGrammarAccess.getOutputSignalAccess().getOutputKeyword_1());
	c.setLinewrap(1, 1, 2).before(this.statemachineGrammarAccess.getStateAccess().getStateKeyword_0());
	c.setIndentationIncrement().after(this.statemachineGrammarAccess.getStateAccess().getNameAssignment_1());
	c.setLinewrap().before(this.statemachineGrammarAccess.getCommandAccess().getSetKeyword_0());
	c.setLinewrap().before(this.statemachineGrammarAccess.getTransitionAccess().getIfKeyword_0());
	c.setLinewrap().before(this.statemachineGrammarAccess.getStateAccess().getEndKeyword_5());
	c.setIndentationDecrement().before(this.statemachineGrammarAccess.getStateAccess().getEndKeyword_5());
}
 
Example #27
Source File: ValidFormatter.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Configure Category formatting.
 * 
 * @param config
 *          the formatter configuration
 * @param categoryElements
 *          the element to format
 */
protected void configureCategoryFormatting(final FormattingConfig config, final CategoryElements categoryElements) {
  config.setIndentation(categoryElements.getCategoryKeyword_0(), categoryElements.getLeftCurlyBracketKeyword_5());
  config.setIndentation(categoryElements.getLeftCurlyBracketKeyword_5(), categoryElements.getRightCurlyBracketKeyword_7());
  config.setLinewrap(NUM_WRAP_LINES).before(categoryElements.getCategoryKeyword_0());
  config.setLinewrap().before(categoryElements.getLeftCurlyBracketKeyword_5());
  config.setLinewrap(NUM_WRAP_LINES).after(categoryElements.getLeftCurlyBracketKeyword_5());
  config.setLinewrap().before(categoryElements.getLabelKeyword_2());
  config.setLinewrap().before(categoryElements.getDescriptionKeyword_4_0());
  config.setLinewrap(NUM_WRAP_LINES).before(categoryElements.getRightCurlyBracketKeyword_7());

  config.setLinewrap(2).before(categoryElements.getRulesAssignment_6());
}
 
Example #28
Source File: ParameterizedSingleLineColumnLocator.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
public ParameterizedSingleLineColumnLocator(final FormattingConfig formattingConfig, final LocatorParameterCalculator<?> calculator) {
  super(formattingConfig, 1);
  this.calculator = calculator;
}
 
Example #29
Source File: XsemanticsFormatter.java    From xsemantics with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void configureFormatting(FormattingConfig c) {
	// There's no implementation for custom formatting at the moment
}
 
Example #30
Source File: DotHtmlLabelFormatter.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
private void configureCommentsFormatting(FormattingConfig c) {
	// preserve newlines around comments
	c.setLinewrap(0, 1, 2).before(grammarAccess.getHTML_COMMENTRule());
}