diff options
author | Mateusz Matela | 2019-01-15 21:08:39 +0000 |
---|---|---|
committer | Mateusz Matela | 2019-01-15 21:09:33 +0000 |
commit | 4237ef6b545dd5995fd169cd96b702bc59156f02 (patch) | |
tree | 5f695f1925d6b92bf2cc673b3827b584f97ca6d8 /org.eclipse.jdt.core | |
parent | 4138c8369bc6ccf4ed4e4fc23f657248a261d40f (diff) | |
download | eclipse.jdt.core-4237ef6b545dd5995fd169cd96b702bc59156f02.tar.gz eclipse.jdt.core-4237ef6b545dd5995fd169cd96b702bc59156f02.tar.xz eclipse.jdt.core-4237ef6b545dd5995fd169cd96b702bc59156f02.zip |
Bug 159565 - [formatter] Separate white space preferences for separateI20190115-1800
operators
Diffstat (limited to 'org.eclipse.jdt.core')
5 files changed, 402 insertions, 50 deletions
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java index 60fb2e7e30..8390c3a88b 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -2152,10 +2152,98 @@ public class DefaultCodeFormatterConstants { * @see JavaCore#INSERT * @see JavaCore#DO_NOT_INSERT * @since 3.0 + * @deprecated Use the new settings instead: {@link #FORMATTER_INSERT_SPACE_AFTER_MULTIPLICATIVE_OPERATOR}, + * {@link #FORMATTER_INSERT_SPACE_AFTER_ADDITIVE_OPERATOR}, {@link #FORMATTER_INSERT_SPACE_AFTER_STRING_CONCATENATION}, + * {@link #FORMATTER_INSERT_SPACE_AFTER_SHIFT_OPERATOR}, {@link #FORMATTER_INSERT_SPACE_AFTER_RELATIONAL_OPERATOR}, + * {@link #FORMATTER_INSERT_SPACE_AFTER_BITWISE_OPERATOR}, {@link #FORMATTER_INSERT_SPACE_AFTER_LOGICAL_OPERATOR} */ public static final String FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_after_binary_operator"; //$NON-NLS-1$ /** * <pre> + * FORMATTER / Option to insert a space after a multiplicative operator (*, /, %) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_AFTER_MULTIPLICATIVE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_after_multiplicative_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space after an additive operator (+, -) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_after_additive_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_AFTER_ADDITIVE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_after_additive_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space after a string concatenation operator + * - option id: "org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_AFTER_STRING_CONCATENATION = JavaCore.PLUGIN_ID + ".formatter.insert_space_after_string_concatenation"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space after a shift operator (<<, >>, >>>) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_after_shift_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_AFTER_SHIFT_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_after_shift_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space after a relational operator (<, >, <=, >=, ==, !=) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_after_relational_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_AFTER_RELATIONAL_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_after_relational_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space after a bitwise operator (&, ^, |) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_AFTER_BITWISE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_after_bitwise_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space after a logical operator (&&, ||) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_after_logical_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_AFTER_LOGICAL_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_after_logical_operator"; //$NON-NLS-1$ + /** + * <pre> * FORMATTER / Option to insert a space after the closing angle bracket in explicit type arguments on method/constructor invocations * - option id: "org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" * - possible values: { INSERT, DO_NOT_INSERT } @@ -2885,10 +2973,98 @@ public class DefaultCodeFormatterConstants { * @see JavaCore#INSERT * @see JavaCore#DO_NOT_INSERT * @since 3.0 + * @deprecated Use the new settings instead: {@link #FORMATTER_INSERT_SPACE_BEFORE_MULTIPLICATIVE_OPERATOR}, + * {@link #FORMATTER_INSERT_SPACE_BEFORE_ADDITIVE_OPERATOR}, {@link #FORMATTER_INSERT_SPACE_BEFORE_STRING_CONCATENATION}, + * {@link #FORMATTER_INSERT_SPACE_BEFORE_SHIFT_OPERATOR}, {@link #FORMATTER_INSERT_SPACE_BEFORE_RELATIONAL_OPERATOR}, + * {@link #FORMATTER_INSERT_SPACE_BEFORE_BITWISE_OPERATOR}, {@link #FORMATTER_INSERT_SPACE_BEFORE_LOGICAL_OPERATOR} */ public static final String FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_before_binary_operator"; //$NON-NLS-1$ /** * <pre> + * FORMATTER / Option to insert a space before a multiplicative operator (*, /, %) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_MULTIPLICATIVE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_before_multiplicative_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space before an additive operator (+, -) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_before_additive_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_ADDITIVE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_before_additive_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space before a string concatenation operator + * - option id: "org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_STRING_CONCATENATION = JavaCore.PLUGIN_ID + ".formatter.insert_space_before_string_concatenation"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space before a shift operator (<<, >>, >>>) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_before_shift_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_SHIFT_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_before_shift_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space before a relational operator (<, >, <=, >=, ==, !=) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_before_relational_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_RELATIONAL_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_before_relational_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space before a bitwise operator (&, ^, |) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_BITWISE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_before_bitwise_operator"; //$NON-NLS-1$ + /** + * <pre> + * FORMATTER / Option to insert a space before a logical operator (&&, ||) + * - option id: "org.eclipse.jdt.core.formatter.insert_space_before_logical_operator" + * - possible values: { INSERT, DO_NOT_INSERT } + * - default: INSERT + * </pre> + * @see JavaCore#INSERT + * @see JavaCore#DO_NOT_INSERT + * @since 3.17 + */ + public static final String FORMATTER_INSERT_SPACE_BEFORE_LOGICAL_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.insert_space_before_logical_operator"; //$NON-NLS-1$ + /** + * <pre> * FORMATTER / Option to insert a space before the closing angle bracket in parameterized type reference * - option id: "org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" * - possible values: { INSERT, DO_NOT_INSERT } diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java index a5ff4c5095..12b0b2f2f0 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -274,7 +274,13 @@ public class DefaultCodeFormatterOptions { public boolean insert_space_after_assignment_operator; public boolean insert_space_after_at_in_annotation; public boolean insert_space_after_at_in_annotation_type_declaration; - public boolean insert_space_after_binary_operator; + public boolean insert_space_after_multiplicative_operator; + public boolean insert_space_after_additive_operator; + public boolean insert_space_after_string_concatenation; + public boolean insert_space_after_shift_operator; + public boolean insert_space_after_relational_operator; + public boolean insert_space_after_bitwise_operator; + public boolean insert_space_after_logical_operator; public boolean insert_space_after_closing_angle_bracket_in_type_arguments; public boolean insert_space_after_closing_angle_bracket_in_type_parameters; public boolean insert_space_after_closing_paren_in_cast; @@ -336,7 +342,13 @@ public class DefaultCodeFormatterOptions { public boolean insert_space_before_and_in_type_parameter; public boolean insert_space_before_at_in_annotation_type_declaration; public boolean insert_space_before_assignment_operator; - public boolean insert_space_before_binary_operator; + public boolean insert_space_before_multiplicative_operator; + public boolean insert_space_before_additive_operator; + public boolean insert_space_before_string_concatenation; + public boolean insert_space_before_shift_operator; + public boolean insert_space_before_relational_operator; + public boolean insert_space_before_bitwise_operator; + public boolean insert_space_before_logical_operator; public boolean insert_space_before_closing_angle_bracket_in_parameterized_type_reference; public boolean insert_space_before_closing_angle_bracket_in_type_arguments; public boolean insert_space_before_closing_angle_bracket_in_type_parameters; @@ -629,7 +641,13 @@ public class DefaultCodeFormatterOptions { options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ASSIGNMENT_OPERATOR, this.insert_space_after_assignment_operator? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AT_IN_ANNOTATION, this.insert_space_after_at_in_annotation? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_AT_IN_ANNOTATION_TYPE_DECLARATION, this.insert_space_after_at_in_annotation_type_declaration ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); - options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR, this.insert_space_after_binary_operator? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_MULTIPLICATIVE_OPERATOR, this.insert_space_after_multiplicative_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ADDITIVE_OPERATOR, this.insert_space_after_additive_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_STRING_CONCATENATION, this.insert_space_after_string_concatenation ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_SHIFT_OPERATOR, this.insert_space_after_shift_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_RELATIONAL_OPERATOR, this.insert_space_after_relational_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BITWISE_OPERATOR, this.insert_space_after_bitwise_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_LOGICAL_OPERATOR, this.insert_space_after_logical_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_CLOSING_ANGLE_BRACKET_IN_TYPE_ARGUMENTS, this.insert_space_after_closing_angle_bracket_in_type_arguments ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_CLOSING_ANGLE_BRACKET_IN_TYPE_PARAMETERS, this.insert_space_after_closing_angle_bracket_in_type_parameters ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_CLOSING_PAREN_IN_CAST, this.insert_space_after_closing_paren_in_cast? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); @@ -690,7 +708,13 @@ public class DefaultCodeFormatterOptions { options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_AND_IN_TYPE_PARAMETER, this.insert_space_before_and_in_type_parameter ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_AT_IN_ANNOTATION_TYPE_DECLARATION, this.insert_space_before_at_in_annotation_type_declaration ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR, this.insert_space_before_assignment_operator? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); - options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR, this.insert_space_before_binary_operator? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_MULTIPLICATIVE_OPERATOR, this.insert_space_before_multiplicative_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ADDITIVE_OPERATOR, this.insert_space_before_additive_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_STRING_CONCATENATION, this.insert_space_before_string_concatenation ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_SHIFT_OPERATOR, this.insert_space_before_shift_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_RELATIONAL_OPERATOR, this.insert_space_before_relational_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BITWISE_OPERATOR, this.insert_space_before_bitwise_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); + options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_LOGICAL_OPERATOR, this.insert_space_before_logical_operator ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_PARAMETERIZED_TYPE_REFERENCE, this.insert_space_before_closing_angle_bracket_in_parameterized_type_reference? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_TYPE_ARGUMENTS, this.insert_space_before_closing_angle_bracket_in_type_arguments? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); options.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_TYPE_PARAMETERS, this.insert_space_before_closing_angle_bracket_in_type_parameters? JavaCore.INSERT : JavaCore.DO_NOT_INSERT); @@ -1619,10 +1643,20 @@ public class DefaultCodeFormatterOptions { if (insertSpaceAfterAtInAnnotationTypeDeclarationOption != null) { this.insert_space_after_at_in_annotation_type_declaration = JavaCore.INSERT.equals(insertSpaceAfterAtInAnnotationTypeDeclarationOption); } - final Object insertSpaceAfterBinaryOperatorOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR); - if (insertSpaceAfterBinaryOperatorOption != null) { - this.insert_space_after_binary_operator = JavaCore.INSERT.equals(insertSpaceAfterBinaryOperatorOption); - } + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_MULTIPLICATIVE_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_multiplicative_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ADDITIVE_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_additive_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_STRING_CONCATENATION, JavaCore.INSERT, + v -> this.insert_space_after_string_concatenation = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_SHIFT_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_shift_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_RELATIONAL_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_relational_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BITWISE_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_bitwise_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_LOGICAL_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_logical_operator = v); final Object insertSpaceAfterClosingAngleBracketInTypeArgumentsOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_CLOSING_ANGLE_BRACKET_IN_TYPE_ARGUMENTS); if (insertSpaceAfterClosingAngleBracketInTypeArgumentsOption != null) { this.insert_space_after_closing_angle_bracket_in_type_arguments = JavaCore.INSERT.equals(insertSpaceAfterClosingAngleBracketInTypeArgumentsOption); @@ -1863,10 +1897,20 @@ public class DefaultCodeFormatterOptions { if (insertSpaceBeforeAssignmentOperatorOption != null) { this.insert_space_before_assignment_operator = JavaCore.INSERT.equals(insertSpaceBeforeAssignmentOperatorOption); } - final Object insertSpaceBeforeBinaryOperatorOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR); - if (insertSpaceBeforeBinaryOperatorOption != null) { - this.insert_space_before_binary_operator = JavaCore.INSERT.equals(insertSpaceBeforeBinaryOperatorOption); - } + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_MULTIPLICATIVE_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_multiplicative_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ADDITIVE_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_additive_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_STRING_CONCATENATION, JavaCore.INSERT, + v -> this.insert_space_before_string_concatenation = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_SHIFT_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_shift_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_RELATIONAL_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_relational_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BITWISE_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_bitwise_operator = v); + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_LOGICAL_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_logical_operator = v); final Object insertSpaceBeforeClosingAngleBracketInParameterizedTypeReferenceOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_ANGLE_BRACKET_IN_PARAMETERIZED_TYPE_REFERENCE); if (insertSpaceBeforeClosingAngleBracketInParameterizedTypeReferenceOption != null) { this.insert_space_before_closing_angle_bracket_in_parameterized_type_reference = JavaCore.INSERT.equals(insertSpaceBeforeClosingAngleBracketInParameterizedTypeReferenceOption); @@ -2656,6 +2700,64 @@ public class DefaultCodeFormatterOptions { setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR, DefaultCodeFormatterConstants.TRUE, v -> this.wrap_before_logical_operator = v); } + + // add space before and after binary operator -> more granular settings + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_MULTIPLICATIVE_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_multiplicative_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ADDITIVE_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_additive_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_STRING_CONCATENATION) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_string_concatenation = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_SHIFT_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_shift_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_RELATIONAL_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_relational_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BITWISE_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_bitwise_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_LOGICAL_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_before_logical_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_MULTIPLICATIVE_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_multiplicative_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ADDITIVE_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_additive_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_STRING_CONCATENATION) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_string_concatenation = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_SHIFT_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_shift_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_RELATIONAL_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_relational_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BITWISE_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_bitwise_operator = v); + } + if (settings.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_LOGICAL_OPERATOR) == null) { + setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_BINARY_OPERATOR, JavaCore.INSERT, + v -> this.insert_space_after_logical_operator = v); + } } public void setDefaultSettings() { @@ -2798,7 +2900,13 @@ public class DefaultCodeFormatterOptions { this.insert_space_after_assignment_operator = true; this.insert_space_after_at_in_annotation = false; this.insert_space_after_at_in_annotation_type_declaration = false; - this.insert_space_after_binary_operator = true; + this.insert_space_after_multiplicative_operator = true; + this.insert_space_after_additive_operator = true; + this.insert_space_after_string_concatenation = true; + this.insert_space_after_shift_operator = true; + this.insert_space_after_relational_operator = true; + this.insert_space_after_bitwise_operator = true; + this.insert_space_after_logical_operator = true; this.insert_space_after_closing_angle_bracket_in_type_arguments = false; this.insert_space_after_closing_angle_bracket_in_type_parameters = true; this.insert_space_after_closing_paren_in_cast = true; @@ -2859,7 +2967,13 @@ public class DefaultCodeFormatterOptions { this.insert_space_before_and_in_type_parameter = true; this.insert_space_before_at_in_annotation_type_declaration = true; this.insert_space_before_assignment_operator = true; - this.insert_space_before_binary_operator = true; + this.insert_space_before_multiplicative_operator = true; + this.insert_space_before_additive_operator = true; + this.insert_space_before_string_concatenation = true; + this.insert_space_before_shift_operator = true; + this.insert_space_before_relational_operator = true; + this.insert_space_before_bitwise_operator = true; + this.insert_space_before_logical_operator = true; this.insert_space_before_closing_angle_bracket_in_parameterized_type_reference = false; this.insert_space_before_closing_angle_bracket_in_type_arguments = false; this.insert_space_before_closing_angle_bracket_in_type_parameters = false; @@ -3134,7 +3248,13 @@ public class DefaultCodeFormatterOptions { this.insert_space_after_assignment_operator = true; this.insert_space_after_at_in_annotation = false; this.insert_space_after_at_in_annotation_type_declaration = false; - this.insert_space_after_binary_operator = true; + this.insert_space_after_multiplicative_operator = true; + this.insert_space_after_additive_operator = true; + this.insert_space_after_string_concatenation = true; + this.insert_space_after_shift_operator = true; + this.insert_space_after_relational_operator = true; + this.insert_space_after_bitwise_operator = true; + this.insert_space_after_logical_operator = true; this.insert_space_after_closing_angle_bracket_in_type_arguments = false; this.insert_space_after_closing_angle_bracket_in_type_parameters = true; this.insert_space_after_closing_paren_in_cast = true; @@ -3195,7 +3315,13 @@ public class DefaultCodeFormatterOptions { this.insert_space_before_and_in_type_parameter = true; this.insert_space_before_at_in_annotation_type_declaration = true; this.insert_space_before_assignment_operator = true; - this.insert_space_before_binary_operator = true; + this.insert_space_before_multiplicative_operator = true; + this.insert_space_before_additive_operator = true; + this.insert_space_before_string_concatenation = true; + this.insert_space_before_shift_operator = true; + this.insert_space_before_relational_operator = true; + this.insert_space_before_bitwise_operator = true; + this.insert_space_before_logical_operator = true; this.insert_space_before_closing_angle_bracket_in_parameterized_type_reference = false; this.insert_space_before_closing_angle_bracket_in_type_arguments = false; this.insert_space_before_closing_angle_bracket_in_type_parameters = false; diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java index 96353d1bfa..f194800322 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/SpacePreparator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2018 Mateusz Matela and others. + * Copyright (c) 2014, 2019 Mateusz Matela and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -18,7 +18,12 @@ package org.eclipse.jdt.internal.formatter; import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.*; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.function.Predicate; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; @@ -54,6 +59,7 @@ import org.eclipse.jdt.core.dom.ForStatement; import org.eclipse.jdt.core.dom.IfStatement; import org.eclipse.jdt.core.dom.ImportDeclaration; import org.eclipse.jdt.core.dom.InfixExpression; +import org.eclipse.jdt.core.dom.InfixExpression.Operator; import org.eclipse.jdt.core.dom.InstanceofExpression; import org.eclipse.jdt.core.dom.IntersectionType; import org.eclipse.jdt.core.dom.LabeledStatement; @@ -72,7 +78,6 @@ import org.eclipse.jdt.core.dom.ParenthesizedExpression; import org.eclipse.jdt.core.dom.PostfixExpression; import org.eclipse.jdt.core.dom.PrefixExpression; import org.eclipse.jdt.core.dom.ProvidesDirective; -import org.eclipse.jdt.core.dom.PrefixExpression.Operator; import org.eclipse.jdt.core.dom.ReturnStatement; import org.eclipse.jdt.core.dom.SingleMemberAnnotation; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; @@ -99,6 +104,43 @@ import org.eclipse.jdt.core.dom.WildcardType; import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; public class SpacePreparator extends ASTVisitor { + + private static final Map<Operator, Predicate<DefaultCodeFormatterOptions>> SPACE_BEFORE_OPERATOR; + private static final Map<Operator, Predicate<DefaultCodeFormatterOptions>> SPACE_AFTER_OPERATOR; + + static { + Map<Operator, Predicate<DefaultCodeFormatterOptions>> spaceBeforeOperator = new HashMap<>(); + Map<Operator, Predicate<DefaultCodeFormatterOptions>> spaceAfterOperator = new HashMap<>(); + for (Operator op : Arrays.asList(Operator.TIMES, Operator.DIVIDE, Operator.REMAINDER)) { + spaceBeforeOperator.put(op, o -> o.insert_space_before_multiplicative_operator); + spaceAfterOperator.put(op, o -> o.insert_space_after_multiplicative_operator); + } + for (Operator op : Arrays.asList(Operator.PLUS, Operator.MINUS)) { + spaceBeforeOperator.put(op, o -> o.insert_space_before_additive_operator); + spaceAfterOperator.put(op, o -> o.insert_space_after_additive_operator); + } + for (Operator op : Arrays.asList(Operator.LEFT_SHIFT, Operator.RIGHT_SHIFT_SIGNED, + Operator.RIGHT_SHIFT_UNSIGNED)) { + spaceBeforeOperator.put(op, o -> o.insert_space_before_shift_operator); + spaceAfterOperator.put(op, o -> o.insert_space_after_shift_operator); + } + for (Operator op : Arrays.asList(Operator.LESS, Operator.GREATER, Operator.LESS_EQUALS, + Operator.GREATER_EQUALS, Operator.EQUALS, Operator.NOT_EQUALS)) { + spaceBeforeOperator.put(op, o -> o.insert_space_before_relational_operator); + spaceAfterOperator.put(op, o -> o.insert_space_after_relational_operator); + } + for (Operator op : Arrays.asList(Operator.AND, Operator.XOR, Operator.OR)) { + spaceBeforeOperator.put(op, o -> o.insert_space_before_bitwise_operator); + spaceAfterOperator.put(op, o -> o.insert_space_after_bitwise_operator); + } + for (Operator op : Arrays.asList(Operator.CONDITIONAL_AND, Operator.CONDITIONAL_OR)) { + spaceBeforeOperator.put(op, o -> o.insert_space_before_logical_operator); + spaceAfterOperator.put(op, o -> o.insert_space_after_logical_operator); + } + SPACE_BEFORE_OPERATOR = Collections.unmodifiableMap(spaceBeforeOperator); + SPACE_AFTER_OPERATOR = Collections.unmodifiableMap(spaceAfterOperator); + } + TokenManager tm; private DefaultCodeFormatterOptions options; @@ -710,21 +752,26 @@ public class SpacePreparator extends ASTVisitor { @Override public boolean visit(InfixExpression node) { - String operator = node.getOperator().toString(); - handleOperator(operator, node.getRightOperand(), this.options.insert_space_before_binary_operator, - this.options.insert_space_after_binary_operator); + Operator operator = node.getOperator(); + boolean spaceBefore = SPACE_BEFORE_OPERATOR.get(operator).test(this.options); + boolean spaceAfter = SPACE_AFTER_OPERATOR.get(operator).test(this.options); + if (this.tm.isStringConcatenation(node)) { + spaceBefore = this.options.insert_space_before_string_concatenation; + spaceAfter = this.options.insert_space_after_string_concatenation; + } + handleOperator(operator.toString(), node.getRightOperand(), spaceBefore, spaceAfter); List<Expression> extendedOperands = node.extendedOperands(); for (Expression operand : extendedOperands) { - handleOperator(operator, operand, this.options.insert_space_before_binary_operator, - this.options.insert_space_after_binary_operator); + handleOperator(operator.toString(), operand, spaceBefore, spaceAfter); } return true; } @Override public boolean visit(PrefixExpression node) { - Operator operator = node.getOperator(); - if (operator.equals(Operator.INCREMENT) || operator.equals(Operator.DECREMENT)) { + PrefixExpression.Operator operator = node.getOperator(); + if (operator.equals(PrefixExpression.Operator.INCREMENT) + || operator.equals(PrefixExpression.Operator.DECREMENT)) { handleOperator(operator.toString(), node.getOperand(), this.options.insert_space_before_prefix_operator, this.options.insert_space_after_prefix_operator); @@ -782,8 +829,8 @@ public class SpacePreparator extends ASTVisitor { public boolean visit(IntersectionType node) { List<Type> types = node.types(); for (int i = 1; i < types.size(); i++) - handleTokenBefore(types.get(i), TokenNameAND, this.options.insert_space_before_binary_operator, - this.options.insert_space_after_binary_operator); + handleTokenBefore(types.get(i), TokenNameAND, this.options.insert_space_before_bitwise_operator, + this.options.insert_space_after_bitwise_operator); return true; } @@ -910,8 +957,8 @@ public class SpacePreparator extends ASTVisitor { public boolean visit(UnionType node) { List<Type> types = node.types(); for (int i = 1; i < types.size(); i++) - handleTokenBefore(types.get(i), TokenNameOR, this.options.insert_space_before_binary_operator, - this.options.insert_space_after_binary_operator); + handleTokenBefore(types.get(i), TokenNameOR, this.options.insert_space_before_bitwise_operator, + this.options.insert_space_after_bitwise_operator); return true; } diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/TokenManager.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/TokenManager.java index 4e42073ab8..f05462943a 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/TokenManager.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/TokenManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2018 Mateusz Matela and others. + * Copyright (c) 2014, 2019 Mateusz Matela and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -26,6 +26,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.InfixExpression; +import org.eclipse.jdt.core.dom.StringLiteral; +import org.eclipse.jdt.core.dom.InfixExpression.Operator; import org.eclipse.jdt.internal.formatter.Token.WrapMode; import org.eclipse.jdt.internal.formatter.linewrap.CommentWrapExecutor; @@ -386,6 +390,21 @@ public class TokenManager implements Iterable<Token> { && get(index).originalEnd <= node.getStartPosition() + node.getLength(); } + public boolean isStringConcatenation(InfixExpression node) { + if (!node.getOperator().equals(Operator.PLUS)) + return false; + List<Expression> operands = new ArrayList<Expression>(node.extendedOperands()); + operands.add(node.getLeftOperand()); + operands.add(node.getRightOperand()); + for (Expression o : operands) { + if (o instanceof StringLiteral) + return true; + if ((o instanceof InfixExpression) && isStringConcatenation((InfixExpression) o)) + return true; + } + return false; + } + public void addNLSAlignIndex(int index, int align) { if (this.tokenIndexToNLSAlign == null) this.tokenIndexToNLSAlign = new HashMap<Integer, Integer>(); diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java index c4130435dd..75595ce35c 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2018 Mateusz Matela and others. + * Copyright (c) 2014, 2019 Mateusz Matela and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -90,7 +90,6 @@ import org.eclipse.jdt.core.dom.QualifiedName; import org.eclipse.jdt.core.dom.SingleMemberAnnotation; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.Statement; -import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.SuperConstructorInvocation; import org.eclipse.jdt.core.dom.SuperFieldAccess; import org.eclipse.jdt.core.dom.SuperMethodInvocation; @@ -616,7 +615,7 @@ public class WrapPreparator extends ASTVisitor { int wrappingOption = OPERATOR_WRAPPING_OPTION.get(node.getOperator()).applyAsInt(this.options); boolean wrapBeforeOperator = OPERATOR_WRAP_BEFORE_OPTION.get(node.getOperator()).test(this.options); - if (isStringConcatenation(node)) { + if (this.tm.isStringConcatenation(node)) { wrappingOption = this.options.alignment_for_string_concatenation; wrapBeforeOperator = this.options.wrap_before_string_concatenation; } @@ -673,21 +672,6 @@ public class WrapPreparator extends ASTVisitor { } } - private boolean isStringConcatenation(InfixExpression node) { - if (!node.getOperator().equals(Operator.PLUS)) - return false; - List<Expression> operands = new ArrayList<Expression>(node.extendedOperands()); - operands.add(node.getLeftOperand()); - operands.add(node.getRightOperand()); - for (Expression o : operands) { - if (o instanceof StringLiteral) - return true; - if ((o instanceof InfixExpression) && isStringConcatenation((InfixExpression) o)) - return true; - } - return false; - } - private boolean samePrecedence(InfixExpression expression1, InfixExpression expression2) { Integer precedence1 = OPERATOR_PRECEDENCE.get(expression1.getOperator()); Integer precedence2 = OPERATOR_PRECEDENCE.get(expression2.getOperator()); |