Java Code Examples for org.eclipse.xtext.formatting.impl.FormattingConfig#setIndentation()

The following examples show how to use org.eclipse.xtext.formatting.impl.FormattingConfig#setIndentation() . 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: SimpleAntlrFormatter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configureFormatting(FormattingConfig c) {
	c.setLinewrap(2, 2, 2).before(getGrammarAccess().getSL_COMMENTRule());
	c.setLinewrap(0, 1, 2).before(getGrammarAccess().getML_COMMENTRule());
	c.setLinewrap(0, 1, 1).after(getGrammarAccess().getML_COMMENTRule());
	c.setSpace("\n\n").before(getGrammarAccess().getSL_COMMENTRule());
	c.setIndentation(getGrammarAccess().getParenthesizedAccess().getOPENTerminalRuleCall_0(), getGrammarAccess().getParenthesizedAccess().getRightParenthesisKeyword_2());
	c.setIndentation(getGrammarAccess().getRuleAccess().getColonKeyword_3(), getGrammarAccess().getRuleAccess().getSemicolonKeyword_5());
	c.setLinewrap().after(getGrammarAccess().getAlternativesAccess().getVerticalLineKeyword_1_1_0());
	c.setNoSpace().before(getGrammarAccess().getAtomAccess().getCardinalityAssignment_0_1_1());
	c.setLinewrap().around(getGrammarAccess().getAlternativesRule());
	c.setLinewrap().after(getGrammarAccess().getRuleAccess().getColonKeyword_3());
	c.setLinewrap().before(getGrammarAccess().getRuleAccess().getSemicolonKeyword_5());
	c.setLinewrap(2).after(getGrammarAccess().getRuleAccess().getSemicolonKeyword_5());
	c.setLinewrap().between(getGrammarAccess().getML_COMMENTRule(),	getGrammarAccess().getAntlrGrammarAccess().getGrammarKeyword_0());
}
 
Example 2
Source File: DotFormatter.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private void configureGraphFormatting(FormattingConfig c) {
	DotGraphElements graph = grammarAccess.getDotGraphAccess();

	// newline after {
	c.setLinewrap(1, 1, 2).after(graph.getLeftCurlyBracketKeyword_3());

	// newline before }
	c.setLinewrap().before(graph.getRightCurlyBracketKeyword_5());

	// indentation between { }
	c.setIndentation(graph.getLeftCurlyBracketKeyword_3(),
			graph.getRightCurlyBracketKeyword_5());

	// newline after the graph's statements
	c.setLinewrap(1, 1, 2).after(graph.getStmtsAssignment_4());
}
 
Example 3
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 4
Source File: ValidFormatter.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Configure NativeContext formatting.
 * 
 * @param config
 *          the formatter configuration
 * @param nativeContextElements
 *          the element to format
 */
protected void configureNativeContextFormatting(final FormattingConfig config, final NativeContextElements nativeContextElements) {
  config.setNoLinewrap().before(nativeContextElements.getMarkerKeyword_3_0());
  config.setNoSpace().around(nativeContextElements.getNumberSignKeyword_1_0());
  config.setNoSpace().around(nativeContextElements.getNumberSignKeyword_3_2_0());
  config.setNoLinewrap().before(nativeContextElements.getLeftCurlyBracketKeyword_4_1());
  config.setNoLinewrap().before(nativeContextElements.getQuickfixesKeyword_4_0());
  config.setLinewrap().after(nativeContextElements.getLeftCurlyBracketKeyword_4_1());
  config.setLinewrap().before(nativeContextElements.getRightCurlyBracketKeyword_4_3());
  config.setIndentation(nativeContextElements.getLeftCurlyBracketKeyword_4_1(), nativeContextElements.getRightCurlyBracketKeyword_4_3());
  config.setNoSpace().before(nativeContextElements.getSemicolonKeyword_5());
  config.setLinewrap().after(nativeContextElements.getGroup());
}
 
Example 5
Source File: ValidFormatter.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Configure NativeRule formatting.
 * 
 * @param config
 *          the formatter configuration
 * @param nativeRuleElements
 *          the element to format
 */
protected void configureNativeRuleFormatting(final FormattingConfig config, final NativeRuleElements nativeRuleElements) {
  config.setIndentation(nativeRuleElements.getNameAssignment_2(), nativeRuleElements.getContextKeyword_8());

  config.setLinewrap().before(nativeRuleElements.getLabelKeyword_3());
  config.setLinewrap().before(nativeRuleElements.getDescriptionKeyword_5_0());
  config.setLinewrap().before(nativeRuleElements.getContextKeyword_8());
  config.setLinewrap().before(nativeRuleElements.getMessageKeyword_6());
  config.setNoLinewrap().before(nativeRuleElements.getLeftCurlyBracketKeyword_9());
  config.setLinewrap().after(nativeRuleElements.getLeftCurlyBracketKeyword_9());
  config.setLinewrap().before(nativeRuleElements.getRightCurlyBracketKeyword_11());
  config.setIndentation(nativeRuleElements.getLeftCurlyBracketKeyword_9(), nativeRuleElements.getRightCurlyBracketKeyword_11());
}
 
Example 6
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 7
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 8
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 9
Source File: FormatterTestConfig.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void configureFormatting(FormattingConfig c) {
	FormatterTestLanguageGrammarAccess f = (FormatterTestLanguageGrammarAccess) getGrammarAccess();

	c.setAutoLinewrap(30);
	
	// indent wrapped lines (lines exceeding autoLineWrap setting above) by one tab stop
	c.setWrappedLineIndentation(1);
	
	// TestLinewrap
	c.setLinewrap().after(f.getTestLinewrapAccess().getLinewrapKeyword_1());

	// Line
	c.setLinewrap().after(f.getLineAccess().getSemicolonKeyword_1());
	c.setNoSpace().before(f.getLineAccess().getSemicolonKeyword_1());

	// TestIndentation
	c.setIndentationIncrement().after(f.getTestIndentationAccess().getLeftCurlyBracketKeyword_2());
	c.setIndentationDecrement().before(f.getTestIndentationAccess().getRightCurlyBracketKeyword_4());
	c.setLinewrap().after(f.getTestIndentationAccess().getLeftCurlyBracketKeyword_2());
	c.setLinewrap().after(f.getTestIndentationAccess().getRightCurlyBracketKeyword_4());
	c.setLinewrap().after(f.getTestIndentationAccess().getSemiAssignment_5());
	c.setNoLinewrap().between(f.getTestIndentationAccess().getRightCurlyBracketKeyword_4(),
			f.getTestIndentationAccess().getSemiAssignment_5());
	c.setNoSpace().before(f.getTestIndentationAccess().getSemiAssignment_5());

	// Assign
	c.setNoSpace().around(f.getAssignAccess().getOpAssignment_1());
	c.setNoSpace().before(f.getAssignAccess().getCommaKeyword_3_1_0());

	// Meth
	c.setNoSpace().around(f.getMethAccess().getLeftParenthesisKeyword_2());
	c.setNoSpace().before(f.getMethAccess().getRightParenthesisKeyword_4());
	c.setNoSpace().before(f.getMethAccess().getCommaKeyword_3_1_0());
	c.setNoLinewrap().before(f.getMethAccess().getCommaKeyword_3_1_0());
	c.setIndentation(f.getMethAccess().getLeftParenthesisKeyword_2(), f.getMethAccess()
			.getRightParenthesisKeyword_4());

	// Param
	c.setNoLinewrap().around(f.getParamAccess().getColonKeyword_1());
	c.setNoSpace().around(f.getParamAccess().getColonKeyword_1());

	// Space
	c.setSpace("     ").after(f.getSpaceAccess().getSpaceKeyword_0());

	// TestLinewrapMinMax
	c.setLinewrap(2, 3, 5).after(f.getTestLinewrapMinMaxAccess().getWrapminmaxKeyword_1());

	// FqnObj
	c.setLinewrap().before(f.getFqnObjAccess().getNameFQNParserRuleCall_1_0());

	// FqnRef
	c.setLinewrap().before(f.getFqnRefAccess().getRefAssignment_1());

	// Enumeration
	c.setNoSpace().between(f.getEnumerationAccess().getValAssignment_2_1(),
			f.getEnumerationAccess().getCommaKeyword_2_0());
	c.setLinewrap().before(f.getEnumerationAccess().getValEnum1EnumRuleCall_2_1_0());

	// Datatypes
	c.setLinewrap().after(f.getDatatype1Rule());
	c.setLinewrap().before(f.getDatatype2Rule());
	c.setLinewrap().between(f.getDatatype2Rule(), f.getDatatype3Rule());
	c.setLinewrap().between(f.getDatatype3Rule(), f.getDatatypesAccess().getKw3Keyword_5());

	// comments
	c.setNoLinewrap().before(f.getSL_COMMENTRule());

	//		saveDebugGraphvizDiagram("Test.dot");
}
 
Example 10
Source File: CheckFormatter.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * General formatting configuration. Delegates formatting configuration to individual grammar elements.
 *
 * @param configuration
 *          formating configuration
 * @param access
 *          grammarAccess
 */
private void configure(final FormattingConfig configuration, final CheckGrammarAccess access) {

  super.configure(configuration, access.getXbaseWithAnnotationsGrammarAccess());

  // Common curly brackets handling (for check grammar only)
  List<Pair<Keyword, Keyword>> curlyPairs = access.findKeywordPairs("{", "}"); //$NON-NLS-1$ //$NON-NLS-2$
  for (Pair<Keyword, Keyword> pair : curlyPairs) {
    if (EcoreUtil2.getContainerOfType(pair.getFirst(), GrammarImpl.class).getName().equals(CheckConstants.GRAMMAR)) {
      configuration.setLinewrap().after(pair.getFirst());
      configuration.setIndentation(pair.getFirst(), pair.getSecond());
      configuration.setLinewrap().before(pair.getSecond());
    }
  }

  // AutoLineWrap
  configuration.setAutoLinewrap(LINE_WRAP_LENGTH);

  // Comments
  configuration.setLinewrap(0, 1, 2).before(access.getSL_COMMENTRule());
  configuration.setLinewrap(1, 1, 2).before(access.getML_COMMENTRule());
  configuration.setLinewrap(1, 1, 1).after(access.getML_COMMENTRule());

  // Rules
  configuration.setLinewrap(1, 1, 2).before(access.getXImportDeclarationRule());
  configuration.setLinewrap(1, 2, 2).before(access.getCategoryRule());
  configuration.setLinewrap(1, 2, 2).before(access.getImplementationRule());
  configuration.setLinewrap(1, 2, 2).before(access.getCheckRule());
  configuration.setLinewrap(1, 1, 2).before(access.getXGuardExpressionRule());
  configuration.setLinewrap(1, 1, 2).before(access.getXIssueExpressionRule());
  configuration.setLinewrap(1, 1, 2).before(access.getXIfExpressionRule());
  configuration.setLinewrap(1, 1, 2).before(access.getXVariableDeclarationRule());

  // Rule elements
  configureFeatureCall(configuration, access.getXMemberFeatureCallAccess());
  configureCheckCatalog(configuration, access.getCheckCatalogAccess());
  configureSeverityRange(configuration, access.getSeverityRangeAccess());
  configureCheck(configuration, access.getCheckAccess());
  configureXIssueExpression(configuration, access.getXIssueExpressionAccess());
  configureCheckContext(configuration, access.getContextAccess());
}
 
Example 11
Source File: ValidFormatter.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Configure QuickFix formatting.
 * 
 * @param config
 *          the formatter configuration
 * @param quickFixElements
 *          the element to format
 */
protected void configureQuickFixFormatting(final FormattingConfig config, final QuickFixElements quickFixElements) {
  config.setIndentation(quickFixElements.getFixKeyword_1(), quickFixElements.getSemicolonKeyword_7());
  config.setLinewrap().after(quickFixElements.getSemicolonKeyword_7());
  config.setLinewrap().before(quickFixElements.getLabelKeyword_3());
  config.setLinewrap().before(quickFixElements.getMessageKeyword_5());
  config.setNoSpace().before(quickFixElements.getSemicolonKeyword_7());
}