@NotNull private static SpacingBuilder createSpacingBuilder(@NotNull CodeStyleSettings settings) { return new SpacingBuilder(settings, GoLanguage.INSTANCE) .before(COMMA).spaceIf(false) .after(COMMA).spaceIf(true) .betweenInside(SEMICOLON, SEMICOLON, FOR_CLAUSE).spaces(1) .before(SEMICOLON).spaceIf(false) .after(SEMICOLON).spaceIf(true) .beforeInside(DOT, IMPORT_SPEC).none() .afterInside(DOT, IMPORT_SPEC).spaces(1) .around(DOT).none() .around(ASSIGN).spaces(1) .around(VAR_ASSIGN).spaces(1) .aroundInside(MUL, POINTER_TYPE).none() .before(ARGUMENT_LIST).none() .before(BUILTIN_ARGUMENT_LIST).none() .afterInside(LPAREN, ARGUMENT_LIST).none() .beforeInside(RPAREN, ARGUMENT_LIST).none() .afterInside(LPAREN, BUILTIN_ARGUMENT_LIST).none() .beforeInside(RPAREN, BUILTIN_ARGUMENT_LIST).none() .before(SIGNATURE).none() .afterInside(LPAREN, TYPE_ASSERTION_EXPR).none() .beforeInside(RPAREN, TYPE_ASSERTION_EXPR).none() .afterInside(LPAREN, PARAMETERS).none() .beforeInside(RPAREN, PARAMETERS).none() .afterInside(LPAREN, RESULT).none() .beforeInside(RPAREN, RESULT).none() .between(PARAMETERS, RESULT).spaces(1) .before(BLOCK).spaces(1) .after(FUNC).spaces(1)
@Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { return mySpacingBuilder.getSpacing(this, child1, child2); }
return new SpacingBuilder(settings, ElixirLanguage.INSTANCE) .after(BLOCK_IDENTIFIER_TOKEN_SET).spaces(1) .around(ElixirTypes.AND_WORD_OPERATOR).spaces(1) .around(ElixirTypes.AND_SYMBOL_OPERATOR).spaceIf(elixirCustomSettings.SPACE_AROUND_AND_OPERATORS) .before(ElixirTypes.ARROW_OPERATOR).spaces(aroundArrowOperatorSpaceCount) .after( ElixirTypes.ARROW_OPERATOR ).spacing(aroundArrowOperatorSpaceCount, aroundArrowOperatorSpaceCount, 0, false, 0) .around(ElixirTypes.ASSOCIATION_OPERATOR).spaceIf(elixirCustomSettings.SPACE_AROUND_ASSOCIATION_OPERATOR) .after(ElixirTypes.AT_OPERATOR).none() .withinPair(ElixirTypes.OPENING_BIT, ElixirTypes.CLOSING_BIT).spaceIf(elixirCustomSettings.SPACE_WITHIN_BITS) .withinPair(ElixirTypes.OPENING_BRACKET, ElixirTypes.CLOSING_BRACKET).spaceIf(elixirCommonSettings.SPACE_WITHIN_BRACKETS) .after(ElixirTypes.CAPTURE_OPERATOR).spaceIf(elixirCustomSettings.SPACE_AFTER_CAPTURE_OPERATOR) .afterInside( ElixirTypes.COMMA, ElixirTypes.NO_PARENTHESES_KEYWORDS ).spaceIf(elixirCommonSettings.SPACE_AFTER_COMMA, true) .before(ElixirTypes.COMMA).spaceIf(elixirCommonSettings.SPACE_BEFORE_COMMA) .after(ElixirTypes.COMMA).spaceIf(elixirCommonSettings.SPACE_AFTER_COMMA) .around(ElixirTypes.COMPARISON_OPERATOR).spaceIf(elixirCommonSettings.SPACE_AROUND_EQUALITY_OPERATORS) .withinPair(ElixirTypes.OPENING_CURLY, ElixirTypes.CLOSING_CURLY).spaceIf(elixirCommonSettings.SPACE_WITHIN_BRACES) .around(ElixirTypes.DOT_OPERATOR).none() .after(ElixirTypes.FN).spaces(1) .aroundInside( ElixirTypes.DUAL_OPERATOR, ADDITION_OPERATION_TOKEN_SET ).spaceIf(elixirCommonSettings.SPACE_AROUND_ADDITIVE_OPERATORS)
static SpacingBuilder getSpacingBuilder(CommonCodeStyleSettings settings, MathematicaCodeStyleSettings mathematicaSettings) { return new SpacingBuilder(settings.getRootSettings(), MathematicaLanguage.INSTANCE) .around(ourAssignments).spaceIf(mathematicaSettings.SPACE_AROUND_ASSIGNMENT_OPERATIONS) .around(ourArithmeticOperations).spaceIf(mathematicaSettings.SPACE_AROUND_ARITHMETIC_OPERATIONS) .aroundInside(MINUS, MINUS_EXPRESSION).spaceIf(mathematicaSettings.SPACE_AROUND_ARITHMETIC_OPERATIONS) .around(ourRelationalOperations).spaceIf(mathematicaSettings.SPACE_AROUND_RELATION_OPERATIONS) .around(ourRuleOperations).spaceIf(mathematicaSettings.SPACE_AROUND_RULE_OPERATIONS) .around(ourFunctionalOperations).spaceIf(mathematicaSettings.SPACE_AROUND_FUNCTIONAL_OPERATIONS) .around(ourOtherOperations).spaceIf(mathematicaSettings.SPACE_AROUND_OTHER_OPERATIONS) .after(COMMA).spaceIf(settings.SPACE_AFTER_COMMA) .before(LEFT_BRACKET).none() .after(RIGHT_BRACKET).none() ; } }
mySpacingBuilder = new SpacingBuilder(commonSettings.getRootSettings(), TemplateToolkitLanguage.INSTANCE) .around(TT2_PERIOD).spaces(0) .after(TT2_MINUS_UNARY).spaces(0) .after(TT2_OUTLINE_TAG).spaces(1) .after(TT2_OPEN_TAG).spaces(1) .before(TT2_SEMI).spaces(0) .after(TT2_SEMI).spaces(1) .afterInside(TT2_NOT, UNARY_EXPR).spaces(0) .before(TT2_COMMA).spaces(0) .after(TT2_COMMA).spaces(1) .before(TT2_CLOSE_TAG).spaces(1) .around(KEYWORDS_TOKENSET).spaces(1) .before(MACRO_CONTENT).spaces(1) .before(DIRECTIVE_POSTFIX).spaces(1) .beforeInside(ASSIGN_EXPR, PROCESS_DIRECTIVE).spaces(1) .beforeInside(ASSIGN_EXPR, EXCEPTION_ARGS).spaces(1) .beforeInside(ASSIGN_EXPR, WRAPPER_DIRECTIVE).spaces(1) .before(PAIR_EXPR).spaces(1) .between(ASSIGN_EXPR, ASSIGN_EXPR).spaces(1) .between(PAIR_EXPR, PAIR_EXPR).spaces(1) .around(EXCEPTION_TYPE).spaces(1) .around(EXCEPTION_MESSAGE).spaces(1) .after(TT2_LEFT_BRACE).spaces(0) .after(TT2_LEFT_BRACKET).spaces(0) .after(TT2_LEFT_PAREN).spaces(0) .before(TT2_RIGHT_BRACE).spaces(0) .before(TT2_RIGHT_BRACKET).spaces(0) .before(TT2_RIGHT_PAREN).spaces(0) .around(ALL_OPERATORS_TOKENSET).spaces(1)
public static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) { CsvCodeStyleSettings csvCodeStyleSettings = settings.getCustomSettings(CsvCodeStyleSettings.class); SpacingBuilder builder = new SpacingBuilder(settings, CsvLanguage.INSTANCE); if (csvCodeStyleSettings.TRIM_LEADING_WHITE_SPACES || csvCodeStyleSettings.TABULARIZE) { builder .after(CsvTypes.COMMA).spaceIf(csvCodeStyleSettings.SPACE_AFTER_SEPARATOR) .after(CsvTypes.CRLF).spaces(0) .after(CsvElementType.DOCUMENT_START).spaces(0); if (csvCodeStyleSettings.TABULARIZE && !csvCodeStyleSettings.WHITE_SPACES_OUTSIDE_QUOTES) { builder.before(CsvTypes.QUOTE).spaces(0); } } else if (csvCodeStyleSettings.SPACE_AFTER_SEPARATOR) { builder.after(CsvTypes.COMMA).spaces(1); } if (csvCodeStyleSettings.TRIM_TRAILING_WHITE_SPACES || csvCodeStyleSettings.TABULARIZE) { builder .before(CsvTypes.COMMA).spaceIf(csvCodeStyleSettings.SPACE_BEFORE_SEPARATOR) .before(CsvTypes.CRLF).spaces(0); if (csvCodeStyleSettings.TABULARIZE && !csvCodeStyleSettings.WHITE_SPACES_OUTSIDE_QUOTES) { builder.after(CsvTypes.QUOTE).spaces(0); } } else if (csvCodeStyleSettings.SPACE_BEFORE_SEPARATOR) { builder.before(CsvTypes.COMMA).spaces(1); } return builder; }
@Override protected SpacingBuilder createSpacingBuilder() { return super.createSpacingBuilder() .after(SIMPLE_OPENERS).spaces(1) .before(HTML_MASON_BLOCK_CLOSER).spaces(1) .before(HTML_MASON_CALL_CLOSER).spaces(1) .before(HTML_MASON_CALL_CLOSER_UNMATCHED).spaces(1) .between(HTML_MASON_CALL_CLOSE_TAG_START, HTML_MASON_TAG_CLOSER).spaces(0) .after(HTML_MASON_CALL_CLOSE_TAG_START).spaces(1) .beforeInside(HTML_MASON_TAG_CLOSER, HTML_MASON_CALL_CLOSE_TAG).spaces(1) ; }
/** * Create spacing builder using given settings. */ public static SpacingBuilder createSpacingBuilder(CodeStyleSettings settings) { CommonCodeStyleSettings protoSettings = settings.getCommonSettings(ProtoLanguage.INSTANCE); SpacingBuilder builder = new SpacingBuilder(settings, ProtoLanguage.INSTANCE); builder.around(ASSIGN).spacing(1, 1, 0, false, 0); builder.before(SEMICOLON).spacing(0, 0, 0, false, 0); builder.after(LINE_COMMENT).spacing(0, 0, 1, true, 2); builder.after(LCURLY).spacing(0, 0, 1, true, 2); builder.before(RCURLY).spacing(0, 0, 1, true, 2); builder.after(LPAREN).spacing(0, 0, 0, false, 0); builder.before(RPAREN).spacing(0, 0, 0, false, 0); builder.after(LSQUARE).spacing(0, 0, 0, false, 0); builder.before(RSQUARE).spacing(0, 0, 0, false, 0); builder.before(LT).spacing(0, 0, 0, false, 0); builder.after(LT).spacing(0, 0, 0, false, 0); builder.before(GT).spacing(0, 0, 0, false, 0); builder.before(COMMA).spacing(0, 0, 0, false, 0); builder.before(SEMICOLON).spacing(0, 0, 0, false, 0); builder.after(COMMA).spacing(1, 1, 0, false, 0); return builder; }
return new SpacingBuilder(settings, ImpexLanguage.getInstance()) .before(ImpexTypes.VALUE_GROUP) .spaceIf(impexSettings.SPACE_BEFORE_FIELD_VALUE_SEPARATOR) .after(ImpexTypes.FIELD_VALUE_SEPARATOR) .spaceIf(impexSettings.SPACE_AFTER_FIELD_VALUE_SEPARATOR) .before(ImpexTypes.PARAMETERS_SEPARATOR) .spaceIf(impexSettings.SPACE_BEFORE_PARAMETERS_SEPARATOR) .after(ImpexTypes.PARAMETERS_SEPARATOR) .spaceIf(impexSettings.SPACE_AFTER_PARAMETERS_SEPARATOR) .before(ImpexTypes.ATTRIBUTE_SEPARATOR) .spaceIf(impexSettings.SPACE_BEFORE_ATTRIBUTE_SEPARATOR) .after(ImpexTypes.COMMA) .spaceIf(impexSettings.SPACE_AFTER_COMMA) .before(ImpexTypes.COMMA) .spaceIf(impexSettings.SPACE_BEFORE_COMMA) .after(ImpexTypes.ATTRIBUTE_SEPARATOR) .spaceIf(impexSettings.SPACE_AFTER_ATTRIBUTE_SEPARATOR) .before(ImpexTypes.FIELD_LIST_ITEM_SEPARATOR) .spaceIf(impexSettings.SPACE_BEFORE_FIELD_LIST_ITEM_SEPARATOR) .after(ImpexTypes.FIELD_LIST_ITEM_SEPARATOR)
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) { return new SpacingBuilder(settings, BallerinaLanguage.INSTANCE) .around(IMPORT).spaceIf(true) .around(AS).spaceIf(true) .around(PUBLIC).spaceIf(true) .around(PRIVATE).spaceIf(true) .around(REMOTE).spaceIf(true) .around(CLIENT).spaceIf(true) .around(EXTERN).spaceIf(true) .around(RESOURCE).spaceIf(true) .around(OBJECT).spaceIf(true) .around(WORKER).spaceIf(true) .around(XMLNS).spaceIf(true) .around(RETURNS).spaceIf(true) .around(VERSION).spaceIf(true) .around(DEPRECATED).spaceIf(true) .around(IS).spaceIf(true) .around(TRAP).spaceIf(true) .around(PANIC).spaceIf(true) .around(FLUSH).spaceIf(true) .around(WAIT).spaceIf(true) .around(ABORTED).spaceIf(true) .around(COMMITTED).spaceIf(true) .around(LISTENER).spaceIf(true) .around(VAR).spaceIf(true) .around(CONST).spaceIf(true) .around(FINAL).spaceIf(true) .around(IF).spaceIf(true)
/** * Returns a spacing object indicating what spaces and/or line breaks are added between two * specified children of this block. * * @param child1 the first child for which spacing is requested; * {@code null} if given {@code 'child2'} block is the first document block * @param child2 the second child for which spacing is requested. * @return the spacing instance, or null if no special spacing is required. If null is returned, * the formatter does not insert or delete spaces between the child blocks, but may insert * a line break if the line wraps at the position between the child blocks. * @see Spacing#createSpacing(int, int, int, boolean, int) * @see Spacing#getReadOnlySpacing() */ @Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { return spacingBuilder.getSpacing(this, child1, child2); }
static SpacingBuilder createSpacingBuilder(CodeStyleSettings settings) { return new SpacingBuilder(settings, CypherLanguage.INSTANCE) .before(OP_COLON).none() .afterInside(OP_COLON, MAP_LITERAL).spaces(1) .after(OP_COLON).none() .beforeInside(PARENTHESE_CLOSE, FOREACH).lineBreakInCode() .withinPair(PARENTHESE_OPEN, PARENTHESE_CLOSE).none() .withinPair(BRACKET_CURLYOPEN, BRACKET_CURLYCLOSE).none() .before(OP_COMMA).none() .after(OP_COMMA).spaces(1) .between(NODE_LABELS, PROPERTIES).spaces(1) .between(RELATIONSHIP_TYPES, PROPERTIES).spaces(1) .between(PARENTHESIZED_EXPRESSION, PATTERN).none() .between(NODE_LABEL, NODE_LABEL).none() .between(REL_TYPE, REL_TYPE).none() .between(NODE_PATTERN, RELATIONSHIP_PATTERN).none() .between(NODE_PATTERN, PATTERN_ELEMENT_CHAIN).none() .between(RELATIONSHIP_PATTERN, NODE_PATTERN).none() .between(PATTERN_ELEMENT_CHAIN, NODE_PATTERN).none() .between(VARIABLE, NODE_LABELS).none() .between(K_FOREACH, PARENTHESE_OPEN).spaces(1) .between(EXPRESSION, OP_PIPE).spaces(1) .between(ID_IN_COLL, OP_PIPE).spaces(1)
/** * Returns a spacing object indicating what spaces and/or line breaks are added between two * specified children of this block. * * @param child1 the first child for which spacing is requested; * {@code null} if given {@code 'child2'} block is the first document block * @param child2 the second child for which spacing is requested. * @return the spacing instance, or null if no special spacing is required. If null is returned, * the formatter does not insert or delete spaces between the child blocks, but may insert * a line break if the line wraps at the position between the child blocks. * @see Spacing#createSpacing(int, int, int, boolean, int) * @see Spacing#getReadOnlySpacing() */ @Nullable @Override public Spacing getSpacing(@Nullable com.intellij.formatting.Block child1, @NotNull com.intellij.formatting.Block child2) { return spacingBuilder.getSpacing(this, child1, child2); }
@NotNull static SpacingBuilder createSpacingBuilder(CommonCodeStyleSettings settings, PerlCodeStyleSettings perlSettings) { return new SpacingBuilder(settings) .before(COMMENT_LINE).spaceIf(perlSettings.ALIGN_COMMENTS_ON_CONSEQUENT_LINES) .after(COMMENT_LINE).lineBreakOrForceSpace(true, false) .around(OPERATOR_X).spaces(1) .before(OPERATOR_X_ASSIGN).spaces(1) .around(OPERATORS_ASSIGNMENT).spaceIf(settings.SPACE_AROUND_ASSIGNMENT_OPERATORS) .around(OPERATORS_EQUALITY).spaceIf(settings.SPACE_AROUND_EQUALITY_OPERATORS) .around(OPERATORS_RELATIONAL).spaceIf(settings.SPACE_AROUND_RELATIONAL_OPERATORS) .around(OPERATORS_LOGICAL).spaceIf(settings.SPACE_AROUND_LOGICAL_OPERATORS) .around(OPERATORS_BITWISE).spaceIf(settings.SPACE_AROUND_BITWISE_OPERATORS) .after(OPERATOR_REFERENCE).spaces(0) .afterInside(OPERATOR_MINUS, PREFIX_UNARY_EXPR).spaceIf(settings.SPACE_AROUND_UNARY_OPERATOR) .afterInside(OPERATOR_PLUS, PREFIX_UNARY_EXPR).spaceIf(settings.SPACE_AROUND_UNARY_OPERATOR) .around(OPERATORS_ADDITIVE).spaceIf(settings.SPACE_AROUND_ADDITIVE_OPERATORS) .around(OPERATORS_MULTIPLICATIVE).spaceIf(settings.SPACE_AROUND_MULTIPLICATIVE_OPERATORS) .around(OPERATORS_SHIFT).spaceIf(settings.SPACE_AROUND_SHIFT_OPERATORS) .around(OPERATORS_UNARY).spaceIf(settings.SPACE_AROUND_UNARY_OPERATOR) .aroundInside(OPERATORS_RANGE, FLIPFLOP_EXPR).spaceIf(perlSettings.SPACE_AROUND_RANGE_OPERATORS) .between(RESERVED_PACKAGE, PACKAGE).spaces(1) .between(PACKAGE, VERSION_ELEMENT).spaces(1) .between(RESERVED_FORMAT, SUB_NAME).spaces(1) .between(ATTRIBUTES, LEFT_PAREN).spaces(1) .beforeInside(LEFT_PAREN, SUB_DEFINITIONS_TOKENSET).spaceIf(settings.SPACE_BEFORE_METHOD_PARENTHESES)
spacing = spacingBuilder.getSpacing(this, child1, child2);
return mySpacingBuilder.getSpacing(this, child1, child2);
@Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { return mySpacingBuilder.getSpacing(this, child1, child2); }
@Nullable @Override public Spacing getSpacing(@Nullable final Block child1, @NotNull final Block child2) { return spacingBuilder.getSpacing(this, child1, child2); }
@Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { //todo Add more complex logic on spacing, if needed return spacingBuilder.getSpacing(this, child1, child2); }
@Nullable @Override public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) { Spacing spacing = spacingBuilder.getSpacing(this, child1, child2); if (spacing == null) { return SPACE; } return spacing; }