Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java116
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test419/A_in.java11
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test419/A_out.java11
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test420/A_in.java5
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test420/A_out.java4
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/A_out.java22
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/B_out.java22
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/C_out.java19
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/D_out.java22
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/E_out.java19
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/F_out.java22
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/G_out.java21
-rw-r--r--org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/in.java17
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java178
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java167
-rw-r--r--org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java112
17 files changed, 657 insertions, 113 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
index 4c859824cf..7372b2b857 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
@@ -11216,7 +11216,7 @@ public void testBug472009() {
* https://bugs.eclipse.org/474629 - [save actions][clean up] Exceptions thrown
*/
public void testBug474629() {
- this.formatterPrefs.alignment_for_binary_expression |= Alignment.M_INDENT_ON_COLUMN;
+ this.formatterPrefs.alignment_for_additive_operator |= Alignment.M_INDENT_ON_COLUMN;
String source = "aaaaa + bbbb";
formatSource(source, source, CodeFormatter.K_EXPRESSION, 0, true);
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
index 53c4de2adf..704a97c3d5 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
@@ -4706,7 +4706,7 @@ public class FormatterRegressionTests extends AbstractJavaModelTests {
public void test356() {
Map options = DefaultCodeFormatterConstants.getEclipse21Settings();
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
- options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT, DefaultCodeFormatterConstants.INDENT_DEFAULT));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_MULTIPLICATIVE_OPERATOR, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_COMPACT, DefaultCodeFormatterConstants.INDENT_DEFAULT));
DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
runTest(codeFormatter, "test356", "A.java", CodeFormatter.K_COMPILATION_UNIT);//$NON-NLS-1$ //$NON-NLS-2$
@@ -5561,31 +5561,6 @@ public class FormatterRegressionTests extends AbstractJavaModelTests {
}
/**
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49162
- */
- public void _test419() {
- Map options = DefaultCodeFormatterConstants.getEclipse21Settings();
- options.put(
- DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
- DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT));
- DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
- preferences.tab_char = DefaultCodeFormatterOptions.TAB;
- DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
- runTest(codeFormatter, "test419", "A.java", CodeFormatter.K_COMPILATION_UNIT);//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=49623
- */
- public void _test420() {
- DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
- preferences.tab_char = DefaultCodeFormatterOptions.TAB;
- preferences.align_type_members_on_columns = true;
- DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
- runTest(codeFormatter, "test420", "A.java", CodeFormatter.K_COMPILATION_UNIT);//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=49298
*/
public void test421() {
@@ -6106,7 +6081,7 @@ public class FormatterRegressionTests extends AbstractJavaModelTests {
DefaultCodeFormatterConstants.INDENT_BY_ONE
));
options.put(
- DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION,
DefaultCodeFormatterConstants.createAlignmentValue(
false,
DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
@@ -6123,7 +6098,7 @@ public class FormatterRegressionTests extends AbstractJavaModelTests {
public void test460() {
Map options = DefaultCodeFormatterConstants.getEclipse21Settings();
options.put(
- DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ADDITIVE_OPERATOR,
DefaultCodeFormatterConstants.createAlignmentValue(
false,
DefaultCodeFormatterConstants.WRAP_COMPACT,
@@ -8809,8 +8784,10 @@ public class FormatterRegressionTests extends AbstractJavaModelTests {
// Binary expression
public void test601() {
Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
- options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
- DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT));
+ String alignment = DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ADDITIVE_OPERATOR, alignment);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_MULTIPLICATIVE_OPERATOR, alignment);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_LOGICAL_OPERATOR, alignment);
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
options.put(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS, DefaultCodeFormatterConstants.TRUE);
options.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "60");
@@ -9032,7 +9009,7 @@ public class FormatterRegressionTests extends AbstractJavaModelTests {
String resourcePath = getResource("test617", "formatter.xml");
Map options = DecodeCodeFormatterPreferences.decodeCodeFormatterOptions(resourcePath, "JRK");
assertNotNull("No preferences", options);
- options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION,
DefaultCodeFormatterConstants.createAlignmentValue(
true,
DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
@@ -9171,7 +9148,7 @@ public class FormatterRegressionTests extends AbstractJavaModelTests {
public void test625() {
Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
options.put(
- DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION,
DefaultCodeFormatterConstants.createAlignmentValue(
true,
DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
@@ -9591,13 +9568,13 @@ public class FormatterRegressionTests extends AbstractJavaModelTests {
DefaultCodeFormatterConstants.INDENT_BY_ONE
));
options.put(
- DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION,
DefaultCodeFormatterConstants.createAlignmentValue(
false,
DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
DefaultCodeFormatterConstants.INDENT_BY_ONE
));
- options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR, DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_STRING_CONCATENATION, DefaultCodeFormatterConstants.FALSE);
DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
runTest(codeFormatter, "test664", "A.java", CodeFormatter.K_STATEMENTS);//$NON-NLS-1$ //$NON-NLS-2$
@@ -14660,4 +14637,75 @@ public void testBug541133d() {
" * something\n" +
" */");
}
+
+/**
+ * https://bugs.eclipse.org/543079 - [formatter] wrapping binary expressions: separate options for operator types
+ */
+public void testBug543079a() throws JavaModelException {
+ this.formatterPrefs.page_width = 80;
+ this.formatterPrefs.alignment_for_multiplicative_operator = Alignment.M_ONE_PER_LINE_SPLIT + Alignment.M_FORCE + Alignment.M_INDENT_ON_COLUMN;
+ this.formatterPrefs.wrap_before_multiplicative_operator = false;
+ String input = getCompilationUnit("Formatter", "", "test543079", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543079", "A_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543079 - [formatter] wrapping binary expressions: separate options for operator types
+ */
+public void testBug543079b() throws JavaModelException {
+ this.formatterPrefs.page_width = 80;
+ this.formatterPrefs.alignment_for_additive_operator = Alignment.M_ONE_PER_LINE_SPLIT + Alignment.M_FORCE + Alignment.M_INDENT_ON_COLUMN;
+ this.formatterPrefs.wrap_before_additive_operator = false;
+ String input = getCompilationUnit("Formatter", "", "test543079", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543079", "B_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543079 - [formatter] wrapping binary expressions: separate options for operator types
+ */
+public void testBug543079c() throws JavaModelException {
+ this.formatterPrefs.page_width = 80;
+ this.formatterPrefs.alignment_for_string_concatenation = Alignment.M_ONE_PER_LINE_SPLIT + Alignment.M_FORCE + Alignment.M_INDENT_ON_COLUMN;
+ this.formatterPrefs.wrap_before_string_concatenation = false;
+ String input = getCompilationUnit("Formatter", "", "test543079", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543079", "C_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543079 - [formatter] wrapping binary expressions: separate options for operator types
+ */
+public void testBug543079d() throws JavaModelException {
+ this.formatterPrefs.page_width = 80;
+ this.formatterPrefs.alignment_for_shift_operator = Alignment.M_ONE_PER_LINE_SPLIT + Alignment.M_FORCE + Alignment.M_INDENT_ON_COLUMN;
+ this.formatterPrefs.wrap_before_shift_operator = false;
+ String input = getCompilationUnit("Formatter", "", "test543079", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543079", "D_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543079 - [formatter] wrapping binary expressions: separate options for operator types
+ */
+public void testBug543079e() throws JavaModelException {
+ this.formatterPrefs.page_width = 80;
+ this.formatterPrefs.alignment_for_relational_operator = Alignment.M_ONE_PER_LINE_SPLIT + Alignment.M_FORCE + Alignment.M_INDENT_ON_COLUMN;
+ this.formatterPrefs.wrap_before_relational_operator = false;
+ String input = getCompilationUnit("Formatter", "", "test543079", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543079", "E_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543079 - [formatter] wrapping binary expressions: separate options for operator types
+ */
+public void testBug543079f() throws JavaModelException {
+ this.formatterPrefs.page_width = 80;
+ this.formatterPrefs.alignment_for_bitwise_operator = Alignment.M_ONE_PER_LINE_SPLIT + Alignment.M_FORCE + Alignment.M_INDENT_ON_COLUMN;
+ this.formatterPrefs.wrap_before_bitwise_operator = false;
+ String input = getCompilationUnit("Formatter", "", "test543079", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543079", "F_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/543079 - [formatter] wrapping binary expressions: separate options for operator types
+ */
+public void testBug543079g() throws JavaModelException {
+ this.formatterPrefs.page_width = 80;
+ this.formatterPrefs.alignment_for_logical_operator = Alignment.M_ONE_PER_LINE_SPLIT + Alignment.M_FORCE + Alignment.M_INDENT_ON_COLUMN;
+ this.formatterPrefs.wrap_before_logical_operator = false;
+ String input = getCompilationUnit("Formatter", "", "test543079", "in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test543079", "G_out.java").getSource());
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test419/A_in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test419/A_in.java
deleted file mode 100644
index 046da3534c..0000000000
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test419/A_in.java
+++ /dev/null
@@ -1,11 +0,0 @@
-public class A {
- private static final String EMPID_TEMPLATE =
- "<?xml version =\"1.0\"?>\r\n" +
- "<Request name=\"IAT.GetEmployee\">\r\n" +
- " <Input>\r\n" +
- " <DEMOREC1>\r\n" +
- " <EMPID>0</EMPID>\r\n" +
- " </DEMOREC1>\r\n" +
- " </Input>\r\n" +
- "</Request>";
-} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test419/A_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test419/A_out.java
deleted file mode 100644
index 50f5adcb95..0000000000
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test419/A_out.java
+++ /dev/null
@@ -1,11 +0,0 @@
-public class A {
- private static final String EMPID_TEMPLATE =
- "<?xml version =\"1.0\"?>\r\n"
- + "<Request name=\"IAT.GetEmployee\">\r\n"
- + " <Input>\r\n"
- + " <DEMOREC1>\r\n"
- + " <EMPID>0</EMPID>\r\n"
- + " </DEMOREC1>\r\n"
- + " </Input>\r\n"
- + "</Request>";
-} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test420/A_in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test420/A_in.java
deleted file mode 100644
index bfd640d2e0..0000000000
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test420/A_in.java
+++ /dev/null
@@ -1,5 +0,0 @@
-public class A
-{
- private static final UnsupportedOperationException exception = new UnsupportedOperationException();
- protected Object m_snapshotDate = null; //null indicates that its not snapshot view
-}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test420/A_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test420/A_out.java
deleted file mode 100644
index ab33eca85d..0000000000
--- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test420/A_out.java
+++ /dev/null
@@ -1,4 +0,0 @@
-public class A {
- private static final UnsupportedOperationException exception = new UnsupportedOperationException();
- protected Object m_snapshotDate = null; //null indicates that its not snapshot view
-} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/A_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/A_out.java
new file mode 100644
index 0000000000..e0f117b14a
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/A_out.java
@@ -0,0 +1,22 @@
+class C {
+
+ boolean firstIsGreater = 11111111 + 22222222 + 33333333 + 44444444
+ + 55555555 + 66666666 > 1.11111111 *
+ 2.22222222 *
+ 3.33333333 *
+ 4.44444444 *
+ 5.55555555 *
+ 6.66666666;
+
+ String concatenatedString = "one two three four " + "five six seven eight "
+ + "nine ten eleven twelve";
+
+ int shiftedInteger = 0xCAFEFACE >>> 0x00000001 >>> 0x00000002 << 0x00000003 >>> 0x00000004;
+
+ int bitAritmetic = 0xCAFEFACE
+ | 0x01010101 & 0x02020202 ^ 0x03030303 ^ 0x04040404 | 0x05050505;
+
+ boolean multipleConditions = conditionOne && conditionTwo
+ || conditionThree && conditionFour || conditionFive;
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/B_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/B_out.java
new file mode 100644
index 0000000000..f0d489752f
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/B_out.java
@@ -0,0 +1,22 @@
+class C {
+
+ boolean firstIsGreater = 11111111 +
+ 22222222 +
+ 33333333 +
+ 44444444 +
+ 55555555 +
+ 66666666 > 1.11111111 * 2.22222222 * 3.33333333
+ * 4.44444444 * 5.55555555 * 6.66666666;
+
+ String concatenatedString = "one two three four " + "five six seven eight "
+ + "nine ten eleven twelve";
+
+ int shiftedInteger = 0xCAFEFACE >>> 0x00000001 >>> 0x00000002 << 0x00000003 >>> 0x00000004;
+
+ int bitAritmetic = 0xCAFEFACE
+ | 0x01010101 & 0x02020202 ^ 0x03030303 ^ 0x04040404 | 0x05050505;
+
+ boolean multipleConditions = conditionOne && conditionTwo
+ || conditionThree && conditionFour || conditionFive;
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/C_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/C_out.java
new file mode 100644
index 0000000000..c58f223597
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/C_out.java
@@ -0,0 +1,19 @@
+class C {
+
+ boolean firstIsGreater = 11111111 + 22222222 + 33333333 + 44444444
+ + 55555555 + 66666666 > 1.11111111 * 2.22222222 * 3.33333333
+ * 4.44444444 * 5.55555555 * 6.66666666;
+
+ String concatenatedString = "one two three four " +
+ "five six seven eight " +
+ "nine ten eleven twelve";
+
+ int shiftedInteger = 0xCAFEFACE >>> 0x00000001 >>> 0x00000002 << 0x00000003 >>> 0x00000004;
+
+ int bitAritmetic = 0xCAFEFACE
+ | 0x01010101 & 0x02020202 ^ 0x03030303 ^ 0x04040404 | 0x05050505;
+
+ boolean multipleConditions = conditionOne && conditionTwo
+ || conditionThree && conditionFour || conditionFive;
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/D_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/D_out.java
new file mode 100644
index 0000000000..8f192d79a0
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/D_out.java
@@ -0,0 +1,22 @@
+class C {
+
+ boolean firstIsGreater = 11111111 + 22222222 + 33333333 + 44444444
+ + 55555555 + 66666666 > 1.11111111 * 2.22222222 * 3.33333333
+ * 4.44444444 * 5.55555555 * 6.66666666;
+
+ String concatenatedString = "one two three four " + "five six seven eight "
+ + "nine ten eleven twelve";
+
+ int shiftedInteger = 0xCAFEFACE >>>
+ 0x00000001 >>>
+ 0x00000002 <<
+ 0x00000003 >>>
+ 0x00000004;
+
+ int bitAritmetic = 0xCAFEFACE
+ | 0x01010101 & 0x02020202 ^ 0x03030303 ^ 0x04040404 | 0x05050505;
+
+ boolean multipleConditions = conditionOne && conditionTwo
+ || conditionThree && conditionFour || conditionFive;
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/E_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/E_out.java
new file mode 100644
index 0000000000..26cc8d1fce
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/E_out.java
@@ -0,0 +1,19 @@
+class C {
+
+ boolean firstIsGreater = 11111111 + 22222222 + 33333333 + 44444444
+ + 55555555 + 66666666 >
+ 1.11111111 * 2.22222222 * 3.33333333
+ * 4.44444444 * 5.55555555 * 6.66666666;
+
+ String concatenatedString = "one two three four " + "five six seven eight "
+ + "nine ten eleven twelve";
+
+ int shiftedInteger = 0xCAFEFACE >>> 0x00000001 >>> 0x00000002 << 0x00000003 >>> 0x00000004;
+
+ int bitAritmetic = 0xCAFEFACE
+ | 0x01010101 & 0x02020202 ^ 0x03030303 ^ 0x04040404 | 0x05050505;
+
+ boolean multipleConditions = conditionOne && conditionTwo
+ || conditionThree && conditionFour || conditionFive;
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/F_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/F_out.java
new file mode 100644
index 0000000000..f07ec12bd1
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/F_out.java
@@ -0,0 +1,22 @@
+class C {
+
+ boolean firstIsGreater = 11111111 + 22222222 + 33333333 + 44444444
+ + 55555555 + 66666666 > 1.11111111 * 2.22222222 * 3.33333333
+ * 4.44444444 * 5.55555555 * 6.66666666;
+
+ String concatenatedString = "one two three four " + "five six seven eight "
+ + "nine ten eleven twelve";
+
+ int shiftedInteger = 0xCAFEFACE >>> 0x00000001 >>> 0x00000002 << 0x00000003 >>> 0x00000004;
+
+ int bitAritmetic = 0xCAFEFACE |
+ 0x01010101 &
+ 0x02020202 ^
+ 0x03030303 ^
+ 0x04040404 |
+ 0x05050505;
+
+ boolean multipleConditions = conditionOne && conditionTwo
+ || conditionThree && conditionFour || conditionFive;
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/G_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/G_out.java
new file mode 100644
index 0000000000..7bdd701612
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/G_out.java
@@ -0,0 +1,21 @@
+class C {
+
+ boolean firstIsGreater = 11111111 + 22222222 + 33333333 + 44444444
+ + 55555555 + 66666666 > 1.11111111 * 2.22222222 * 3.33333333
+ * 4.44444444 * 5.55555555 * 6.66666666;
+
+ String concatenatedString = "one two three four " + "five six seven eight "
+ + "nine ten eleven twelve";
+
+ int shiftedInteger = 0xCAFEFACE >>> 0x00000001 >>> 0x00000002 << 0x00000003 >>> 0x00000004;
+
+ int bitAritmetic = 0xCAFEFACE
+ | 0x01010101 & 0x02020202 ^ 0x03030303 ^ 0x04040404 | 0x05050505;
+
+ boolean multipleConditions = conditionOne &&
+ conditionTwo ||
+ conditionThree &&
+ conditionFour ||
+ conditionFive;
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/in.java
new file mode 100644
index 0000000000..0de7ba9572
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test543079/in.java
@@ -0,0 +1,17 @@
+class C {
+
+boolean firstIsGreater = 11111111 + 22222222 +
+33333333 + 44444444 + 55555555 + 66666666
+>
+1.11111111 * 2.22222222 * 3.33333333
+* 4.44444444 * 5.55555555 * 6.66666666;
+
+String concatenatedString = "one two three four " + "five six seven eight " + "nine ten eleven twelve";
+
+int shiftedInteger = 0xCAFEFACE >>> 0x00000001 >>> 0x00000002 << 0x00000003 >>> 0x00000004;
+
+int bitAritmetic = 0xCAFEFACE | 0x01010101 & 0x02020202 ^ 0x03030303 ^ 0x04040404 | 0x05050505;
+
+boolean multipleConditions = conditionOne && conditionTwo || conditionThree && conditionFour || conditionFive;
+
+}
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 a11b118c7c..60fb2e7e30 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
@@ -192,7 +192,7 @@ public class DefaultCodeFormatterConstants {
public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION = JavaCore.PLUGIN_ID + ".formatter.alignment_for_arguments_in_qualified_allocation_expression"; //$NON-NLS-1$
/**
* <pre>
- * FORMATTER / Option for alignment of assignment
+ * FORMATTER / Option for alignment of assignment (=, +=, -=, *=, /=, %=, &=, ^=, |=, <<=, >>=, >>>=)
* - option id: "org.eclipse.jdt.core.formatter.alignment_for_assignment"
* - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
* - default: createAlignmentValue(false, WRAP_NO_SPLIT, INDENT_DEFAULT)
@@ -203,13 +203,94 @@ public class DefaultCodeFormatterConstants {
public static final String FORMATTER_ALIGNMENT_FOR_ASSIGNMENT = JavaCore.PLUGIN_ID + ".formatter.alignment_for_assignment"; //$NON-NLS-1$
/**
* <pre>
+ * FORMATTER / Option for alignment of expressions with multiplicative operators (*, /, %)
+ * - option id: "org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator"
+ * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
+ * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
+ * </pre>
+ * @see #createAlignmentValue(boolean, int, int)
+ * @since 3.17
+ */
+ public static final String FORMATTER_ALIGNMENT_FOR_MULTIPLICATIVE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.alignment_for_multiplicative_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option for alignment of expressions with additive operators (+, -)
+ * - option id: "org.eclipse.jdt.core.formatter.alignment_for_additive_operator"
+ * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
+ * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
+ * </pre>
+ * @see #createAlignmentValue(boolean, int, int)
+ * @since 3.17
+ */
+ public static final String FORMATTER_ALIGNMENT_FOR_ADDITIVE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.alignment_for_additive_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option for alignment of string concatenation expressions
+ * - option id: "org.eclipse.jdt.core.formatter.alignment_for_string_concatenation"
+ * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
+ * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
+ * </pre>
+ * @see #createAlignmentValue(boolean, int, int)
+ * @since 3.17
+ */
+ public static final String FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION = JavaCore.PLUGIN_ID + ".formatter.alignment_for_string_concatenation"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option for alignment of expressions with shift operators (<<, >>, >>>)
+ * - option id: "org.eclipse.jdt.core.formatter.alignment_for_shift_operator"
+ * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
+ * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
+ * </pre>
+ * @see #createAlignmentValue(boolean, int, int)
+ * @since 3.17
+ */
+ public static final String FORMATTER_ALIGNMENT_FOR_SHIFT_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.alignment_for_shift_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option for alignment of expressions with relational operators (<, >, <=, >=, ==, !=)
+ * - option id: "org.eclipse.jdt.core.formatter.alignment_for_relational_operator"
+ * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
+ * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
+ * </pre>
+ * @see #createAlignmentValue(boolean, int, int)
+ * @since 3.17
+ */
+ public static final String FORMATTER_ALIGNMENT_FOR_RELATIONAL_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.alignment_for_relational_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option for alignment of expressions with bitwise operators (&, ^, |)
+ * - option id: "org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator"
+ * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
+ * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
+ * </pre>
+ * @see #createAlignmentValue(boolean, int, int)
+ * @since 3.17
+ */
+ public static final String FORMATTER_ALIGNMENT_FOR_BITWISE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.alignment_for_bitwise_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option for alignment of expressions with logical operators (&&, ||)
+ * - option id: "org.eclipse.jdt.core.formatter.alignment_for_logical_operator"
+ * - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
+ * - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
+ * </pre>
+ * @see #createAlignmentValue(boolean, int, int)
+ * @since 3.17
+ */
+ public static final String FORMATTER_ALIGNMENT_FOR_LOGICAL_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.alignment_for_logical_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
* FORMATTER / Option for alignment of binary expression
* - option id: "org.eclipse.jdt.core.formatter.alignment_for_binary_expression"
* - possible values: values returned by <code>createAlignmentValue(boolean, int, int)</code> call
* - default: createAlignmentValue(false, WRAP_COMPACT, INDENT_DEFAULT)
* </pre>
+ *
* @see #createAlignmentValue(boolean, int, int)
* @since 3.0
+ * @deprecated Use new settings instead: {@link #FORMATTER_ALIGNMENT_FOR_MULTIPLICATIVE_OPERATOR},
+ * {@link #FORMATTER_ALIGNMENT_FOR_ADDITIVE_OPERATOR}, {@link #FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION},
+ * {@link #FORMATTER_ALIGNMENT_FOR_BITWISE_OPERATOR}, {@link #FORMATTER_ALIGNMENT_FOR_LOGICAL_OPERATOR}
*/
public static final String FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION = JavaCore.PLUGIN_ID + ".formatter.alignment_for_binary_expression"; //$NON-NLS-1$
/**
@@ -4380,6 +4461,98 @@ public class DefaultCodeFormatterConstants {
* @since 3.1
*/
public static final String FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS = JavaCore.PLUGIN_ID + ".formatter.use_tabs_only_for_leading_indentations"; //$NON-NLS-1$
+
+ /**
+ * <pre>
+ * FORMATTER / Option to wrap before the multiplicative operator (*, /, %)
+ * - option id: "org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ * </pre>
+ * This option is used only if the option {@link #FORMATTER_ALIGNMENT_FOR_MULTIPLE_FIELDS} is set.
+ * @see #TRUE
+ * @see #FALSE
+ * @since 3.17
+ */
+ public static final String FORMATTER_WRAP_BEFORE_MULTIPLICATIVE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.wrap_before_multiplicative_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to wrap before the additive operator (+, -)
+ * - option id: "org.eclipse.jdt.core.formatter.wrap_before_additive_operator"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ * </pre>
+ * This option is used only if the option {@link #FORMATTER_ALIGNMENT_FOR_ADDITIVE_OPERATOR} is set.
+ * @see #TRUE
+ * @see #FALSE
+ * @since 3.17
+ */
+ public static final String FORMATTER_WRAP_BEFORE_ADDITIVE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.wrap_before_additive_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to wrap before the string concatenation operator
+ * - option id: "org.eclipse.jdt.core.formatter.wrap_before_string_concatenation"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ * </pre>
+ * This option is used only if the option {@link #FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION} is set.
+ * @see #TRUE
+ * @see #FALSE
+ * @since 3.17
+ */
+ public static final String FORMATTER_WRAP_BEFORE_STRING_CONCATENATION = JavaCore.PLUGIN_ID + ".formatter.wrap_before_string_concatenation"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to wrap before the shift operator (<<, >>, >>>)
+ * - option id: "org.eclipse.jdt.core.formatter.wrap_before_shift_operator"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ * </pre>
+ * This option is used only if the option {@link #FORMATTER_ALIGNMENT_FOR_SHIFT_OPERATOR} is set.
+ * @see #TRUE
+ * @see #FALSE
+ * @since 3.17
+ */
+ public static final String FORMATTER_WRAP_BEFORE_SHIFT_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.wrap_before_shift_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to wrap before the relational operator (<, >, <=, >=, ==, !=)
+ * - option id: "org.eclipse.jdt.core.formatter.wrap_before_"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ * </pre>
+ * This option is used only if the option {@link #FORMATTER_ALIGNMENT_FOR_RELATIONAL_OPERATOR} is set.
+ * @see #TRUE
+ * @see #FALSE
+ * @since 3.17
+ */
+ public static final String FORMATTER_WRAP_BEFORE_RELATIONAL_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.wrap_before_relational_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to wrap before the bitwise operator (&, ^, |)
+ * - option id: "org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ * </pre>
+ * This option is used only if the option {@link #FORMATTER_ALIGNMENT_FOR_BITWISE_OPERATOR} is set.
+ * @see #TRUE
+ * @see #FALSE
+ * @since 3.17
+ */
+ public static final String FORMATTER_WRAP_BEFORE_BITWISE_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.wrap_before_bitwise_operator"; //$NON-NLS-1$
+ /**
+ * <pre>
+ * FORMATTER / Option to wrap before the logical operator (&&, ||)
+ * - option id: "org.eclipse.jdt.core.formatter.wrap_before_logical_operator"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ * </pre>
+ * This option is used only if the option {@link #FORMATTER_ALIGNMENT_FOR_LOGICAL_OPERATOR} is set.
+ * @see #TRUE
+ * @see #FALSE
+ * @since 3.17
+ */
+ public static final String FORMATTER_WRAP_BEFORE_LOGICAL_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.wrap_before_logical_operator"; //$NON-NLS-1$
/**
* <pre>
* FORMATTER / Option to wrap before the binary operator
@@ -4391,6 +4564,9 @@ public class DefaultCodeFormatterConstants {
* @see #TRUE
* @see #FALSE
* @since 3.3
+ * @deprecated Use the new options instead: {@link #FORMATTER_WRAP_BEFORE_MULTIPLICATIVE_OPERATOR},
+ * {@link #FORMATTER_WRAP_BEFORE_ADDITIVE_OPERATOR}, {@link #FORMATTER_WRAP_BEFORE_STRING_CONCATENATION},
+ * {@link #FORMATTER_WRAP_BEFORE_BITWISE_OPERATOR}, {@link #FORMATTER_WRAP_BEFORE_LOGICAL_OPERATOR}
*/
public static final String FORMATTER_WRAP_BEFORE_BINARY_OPERATOR = JavaCore.PLUGIN_ID + ".formatter.wrap_before_binary_operator"; //$NON-NLS-1$
/**
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 804b7351d6..a5ff4c5095 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
@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
+import java.util.function.IntConsumer;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
@@ -123,7 +124,13 @@ public class DefaultCodeFormatterOptions {
public int alignment_for_arguments_in_method_invocation;
public int alignment_for_arguments_in_qualified_allocation_expression;
public int alignment_for_assignment;
- public int alignment_for_binary_expression;
+ public int alignment_for_multiplicative_operator;
+ public int alignment_for_additive_operator;
+ public int alignment_for_string_concatenation;
+ public int alignment_for_shift_operator;
+ public int alignment_for_relational_operator;
+ public int alignment_for_bitwise_operator;
+ public int alignment_for_logical_operator;
public int alignment_for_compact_if;
public int alignment_for_compact_loop;
public int alignment_for_conditional_expression;
@@ -444,7 +451,13 @@ public class DefaultCodeFormatterOptions {
public int page_width;
public int tab_char;
public boolean use_tabs_only_for_leading_indentations;
- public boolean wrap_before_binary_operator;
+ public boolean wrap_before_multiplicative_operator;
+ public boolean wrap_before_additive_operator;
+ public boolean wrap_before_string_concatenation;
+ public boolean wrap_before_shift_operator;
+ public boolean wrap_before_relational_operator;
+ public boolean wrap_before_bitwise_operator;
+ public boolean wrap_before_logical_operator;
public boolean wrap_before_or_operator_multicatch;
public boolean wrap_before_conditional_operator;
public boolean wrap_before_assignment_operator;
@@ -483,7 +496,13 @@ public class DefaultCodeFormatterOptions {
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, getAlignment(this.alignment_for_arguments_in_method_invocation));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION, getAlignment(this.alignment_for_arguments_in_qualified_allocation_expression));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ASSIGNMENT, getAlignment(this.alignment_for_assignment));
- options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, getAlignment(this.alignment_for_binary_expression));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_MULTIPLICATIVE_OPERATOR ,getAlignment(this.alignment_for_multiplicative_operator));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ADDITIVE_OPERATOR ,getAlignment(this.alignment_for_additive_operator));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION ,getAlignment(this.alignment_for_string_concatenation));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SHIFT_OPERATOR ,getAlignment(this.alignment_for_shift_operator));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_RELATIONAL_OPERATOR ,getAlignment(this.alignment_for_relational_operator));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BITWISE_OPERATOR ,getAlignment(this.alignment_for_bitwise_operator));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_LOGICAL_OPERATOR ,getAlignment(this.alignment_for_logical_operator));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF, getAlignment(this.alignment_for_compact_if));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_LOOP, getAlignment(this.alignment_for_compact_loop));
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION, getAlignment(this.alignment_for_conditional_expression));
@@ -796,7 +815,13 @@ public class DefaultCodeFormatterOptions {
}
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, Integer.toString(this.tab_char == SPACE ? this.indentation_size : this.tab_size)); // reverse values swapping performed by IndentationTabPage
options.put(DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS, this.use_tabs_only_for_leading_indentations ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
- options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR, this.wrap_before_binary_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_MULTIPLICATIVE_OPERATOR, this.wrap_before_multiplicative_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_ADDITIVE_OPERATOR, this.wrap_before_additive_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_STRING_CONCATENATION, this.wrap_before_string_concatenation ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_SHIFT_OPERATOR, this.wrap_before_shift_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_RELATIONAL_OPERATOR, this.wrap_before_relational_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BITWISE_OPERATOR, this.wrap_before_bitwise_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_LOGICAL_OPERATOR, this.wrap_before_logical_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_OR_OPERATOR_MULTICATCH, this.wrap_before_or_operator_multicatch ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_CONDITIONAL_OPERATOR, this.wrap_before_conditional_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_ASSIGNMENT_OPERATOR, this.wrap_before_assignment_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
@@ -878,16 +903,20 @@ public class DefaultCodeFormatterOptions {
this.alignment_for_assignment = Alignment.M_ONE_PER_LINE_SPLIT;
}
}
- final Object alignmentForBinaryExpressionOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION);
- if (alignmentForBinaryExpressionOption != null) {
- try {
- this.alignment_for_binary_expression = Integer.parseInt((String) alignmentForBinaryExpressionOption);
- } catch (NumberFormatException e) {
- this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
- } catch (ClassCastException e) {
- this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
- }
- }
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_MULTIPLICATIVE_OPERATOR,
+ v-> this.alignment_for_multiplicative_operator = v);
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ADDITIVE_OPERATOR,
+ v -> this.alignment_for_additive_operator = v);
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION,
+ v -> this.alignment_for_string_concatenation = v);
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_SHIFT_OPERATOR,
+ v -> this.alignment_for_shift_operator = v);
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_RELATIONAL_OPERATOR,
+ v -> this.alignment_for_relational_operator = v);
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BITWISE_OPERATOR,
+ v -> this.alignment_for_bitwise_operator = v);
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_LOGICAL_OPERATOR,
+ v -> this.alignment_for_logical_operator = v);
final Object alignmentForCompactIfOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_COMPACT_IF);
if (alignmentForCompactIfOption != null) {
try {
@@ -2324,10 +2353,27 @@ public class DefaultCodeFormatterOptions {
this.tab_char = MIXED;
}
}
- final Object wrapBeforeBinaryOperatorOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR);
- if (wrapBeforeBinaryOperatorOption != null) {
- this.wrap_before_binary_operator = DefaultCodeFormatterConstants.TRUE.equals(wrapBeforeBinaryOperatorOption);
- }
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_MULTIPLICATIVE_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_multiplicative_operator = v);
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_ADDITIVE_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_additive_operator = v);
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_STRING_CONCATENATION, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_string_concatenation = v);
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_SHIFT_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_shift_operator = v);
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_RELATIONAL_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_relational_operator = v);
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BITWISE_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_bitwise_operator = v);
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_LOGICAL_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_logical_operator = v);
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_OR_OPERATOR_MULTICATCH, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_or_operator_multicatch = v);
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_CONDITIONAL_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_conditional_operator = v);
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_ASSIGNMENT_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_assignment_operator = v);
+
final Object wrapBeforeOrOperatorMulticatchOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_OR_OPERATOR_MULTICATCH);
if (wrapBeforeOrOperatorMulticatchOption != null) {
this.wrap_before_or_operator_multicatch = DefaultCodeFormatterConstants.TRUE.equals(wrapBeforeOrOperatorMulticatchOption);
@@ -2401,6 +2447,17 @@ public class DefaultCodeFormatterOptions {
return defaultValue;
}
+ private void setInt(Map<String, String> settings, String key, IntConsumer setter) {
+ String value = settings.get(key);
+ if (value != null) {
+ try {
+ setter.accept(Integer.parseInt(value));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Expected integer for setting " + key + ", got: " + value); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ }
+
private void setString(Map<String, String> settings, String key, List<String> allowedValues, Consumer<String> setter) {
Object value = settings.get(key);
if (value != null) {
@@ -2557,6 +2614,48 @@ public class DefaultCodeFormatterOptions {
setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION, JavaCore.INSERT,
v -> this.keep_type_declaration_on_one_line = insertToOneLine.get(v));
}
+
+ // alignment for binary expressions -> more granular settings
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_MULTIPLICATIVE_OPERATOR) == null) {
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ v-> this.alignment_for_multiplicative_operator = v);
+ }
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ADDITIVE_OPERATOR) == null) {
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ v -> this.alignment_for_additive_operator = v);
+ }
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_STRING_CONCATENATION) == null) {
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ v -> this.alignment_for_string_concatenation = v);
+ }
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BITWISE_OPERATOR) == null) {
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ v -> this.alignment_for_bitwise_operator = v);
+ }
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_LOGICAL_OPERATOR) == null) {
+ setInt(settings, DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION,
+ v -> this.alignment_for_logical_operator = v);
+ }
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_MULTIPLICATIVE_OPERATOR) == null) {
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_multiplicative_operator = v);
+ }
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_ADDITIVE_OPERATOR) == null) {
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_additive_operator = v);
+ }
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_STRING_CONCATENATION) == null) {
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_string_concatenation = v);
+ }
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BITWISE_OPERATOR) == null) {
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_bitwise_operator = v);
+ }
+ if (settings.get(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_LOGICAL_OPERATOR) == null) {
+ setBoolean(settings, DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR, DefaultCodeFormatterConstants.TRUE,
+ v -> this.wrap_before_logical_operator = v);
+ }
}
public void setDefaultSettings() {
@@ -2567,7 +2666,13 @@ public class DefaultCodeFormatterOptions {
this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
this.alignment_for_assignment = Alignment.M_NO_ALIGNMENT;
- this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_multiplicative_operator = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_additive_operator = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_string_concatenation = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_shift_operator = Alignment.M_NO_ALIGNMENT;
+ this.alignment_for_relational_operator = Alignment.M_NO_ALIGNMENT;
+ this.alignment_for_bitwise_operator = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_logical_operator = Alignment.M_COMPACT_SPLIT;
this.alignment_for_compact_if = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_INDENT_BY_ONE;
this.alignment_for_compact_loop = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_INDENT_BY_ONE;
this.alignment_for_conditional_expression = Alignment.M_ONE_PER_LINE_SPLIT;
@@ -2868,7 +2973,13 @@ public class DefaultCodeFormatterOptions {
this.page_width = 120;
this.tab_char = TAB; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49081
this.use_tabs_only_for_leading_indentations = false;
- this.wrap_before_binary_operator = true;
+ this.wrap_before_multiplicative_operator = true;
+ this.wrap_before_additive_operator = true;
+ this.wrap_before_string_concatenation = true;
+ this.wrap_before_shift_operator = true;
+ this.wrap_before_relational_operator = true;
+ this.wrap_before_bitwise_operator = true;
+ this.wrap_before_logical_operator = true;
this.wrap_before_or_operator_multicatch = true;
this.wrap_before_conditional_operator = true;
this.wrap_before_assignment_operator = false;
@@ -2892,7 +3003,13 @@ public class DefaultCodeFormatterOptions {
this.alignment_for_arguments_in_method_invocation = Alignment.M_COMPACT_SPLIT;
this.alignment_for_arguments_in_qualified_allocation_expression = Alignment.M_COMPACT_SPLIT;
this.alignment_for_assignment = Alignment.M_NO_ALIGNMENT;
- this.alignment_for_binary_expression = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_multiplicative_operator = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_additive_operator = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_string_concatenation = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_shift_operator = Alignment.M_NO_ALIGNMENT;
+ this.alignment_for_relational_operator = Alignment.M_NO_ALIGNMENT;
+ this.alignment_for_bitwise_operator = Alignment.M_COMPACT_SPLIT;
+ this.alignment_for_logical_operator = Alignment.M_COMPACT_SPLIT;
this.alignment_for_compact_if = Alignment.M_COMPACT_SPLIT;
this.alignment_for_compact_loop = Alignment.M_COMPACT_SPLIT;
this.alignment_for_conditional_expression = Alignment.M_NEXT_PER_LINE_SPLIT;
@@ -3192,7 +3309,13 @@ public class DefaultCodeFormatterOptions {
this.page_width = 120;
this.tab_char = MIXED;
this.use_tabs_only_for_leading_indentations = false;
- this.wrap_before_binary_operator = true;
+ this.wrap_before_multiplicative_operator = true;
+ this.wrap_before_additive_operator = true;
+ this.wrap_before_string_concatenation = true;
+ this.wrap_before_shift_operator = true;
+ this.wrap_before_relational_operator = true;
+ this.wrap_before_bitwise_operator = true;
+ this.wrap_before_logical_operator = true;
this.wrap_before_or_operator_multicatch = true;
this.wrap_before_conditional_operator = true;
this.wrap_before_assignment_operator = false;
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 6054c232e2..c4130435dd 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
@@ -43,10 +43,13 @@ import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNamew
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNamewith;
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 java.util.function.ToIntFunction;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
@@ -87,6 +90,7 @@ 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;
@@ -156,23 +160,60 @@ public class WrapPreparator extends ASTVisitor {
}
}
- private final static Map<Operator, Integer> OPERATOR_PRECEDENCE;
+ private static final Map<Operator, Integer> OPERATOR_PRECEDENCE;
+ private static final Map<Operator, ToIntFunction<DefaultCodeFormatterOptions>> OPERATOR_WRAPPING_OPTION;
+ private static final Map<Operator, Predicate<DefaultCodeFormatterOptions>> OPERATOR_WRAP_BEFORE_OPTION;
static {
- HashMap<Operator, Integer> precedence = new HashMap<Operator, Integer>();
- precedence.put(Operator.TIMES, 1);
- precedence.put(Operator.DIVIDE, 1);
- precedence.put(Operator.REMAINDER, 1);
- precedence.put(Operator.PLUS, 2);
- precedence.put(Operator.MINUS, 2);
- // shift and comparison operators left out intentionally for compatibility with
- // the legacy formatter, which did not wrap these operators
+ HashMap<Operator, Integer> precedence = new HashMap<>();
+ HashMap<Operator, ToIntFunction<DefaultCodeFormatterOptions>> wrappingOption = new HashMap<>();
+ HashMap<Operator, Predicate<DefaultCodeFormatterOptions>> wrapBeforeOption = new HashMap<>();
+ for (Operator op : Arrays.asList(Operator.TIMES, Operator.DIVIDE, Operator.REMAINDER)) {
+ precedence.put(op, 1);
+ wrappingOption.put(op, o -> o.alignment_for_multiplicative_operator);
+ wrapBeforeOption.put(op, o -> o.wrap_before_multiplicative_operator);
+ }
+ for (Operator op : Arrays.asList(Operator.PLUS, Operator.MINUS)) {
+ precedence.put(op, 2);
+ wrappingOption.put(op, o -> o.alignment_for_additive_operator);
+ wrapBeforeOption.put(op, o -> o.wrap_before_additive_operator);
+ }
+ for (Operator op : Arrays.asList(Operator.LEFT_SHIFT, Operator.RIGHT_SHIFT_SIGNED,
+ Operator.RIGHT_SHIFT_UNSIGNED)) {
+ precedence.put(op, 3);
+ wrappingOption.put(op, o -> o.alignment_for_shift_operator);
+ wrapBeforeOption.put(op, o -> o.wrap_before_shift_operator);
+ }
+ for (Operator op : Arrays.asList(Operator.LESS, Operator.GREATER, Operator.LESS_EQUALS,
+ Operator.GREATER_EQUALS)) {
+ precedence.put(op, 4);
+ wrappingOption.put(op, o -> o.alignment_for_relational_operator);
+ wrapBeforeOption.put(op, o -> o.wrap_before_relational_operator);
+ }
+ for (Operator op : Arrays.asList(Operator.EQUALS, Operator.NOT_EQUALS)) {
+ precedence.put(op, 5);
+ wrappingOption.put(op, o -> o.alignment_for_relational_operator);
+ wrapBeforeOption.put(op, o -> o.wrap_before_relational_operator);
+ }
+
precedence.put(Operator.AND, 6);
precedence.put(Operator.XOR, 7);
precedence.put(Operator.OR, 8);
+ for (Operator op : Arrays.asList(Operator.AND, Operator.XOR, Operator.OR)) {
+ wrappingOption.put(op, o -> o.alignment_for_bitwise_operator);
+ wrapBeforeOption.put(op, o -> o.wrap_before_bitwise_operator);
+ }
+
precedence.put(Operator.CONDITIONAL_AND, 9);
precedence.put(Operator.CONDITIONAL_OR, 10);
+ for (Operator op : Arrays.asList(Operator.CONDITIONAL_AND, Operator.CONDITIONAL_OR)) {
+ wrappingOption.put(op, o -> o.alignment_for_logical_operator);
+ wrapBeforeOption.put(op, o -> o.wrap_before_logical_operator);
+ }
// ternary and assignment operators not relevant to infix expressions
+
OPERATOR_PRECEDENCE = Collections.unmodifiableMap(precedence);
+ OPERATOR_WRAPPING_OPTION = Collections.unmodifiableMap(wrappingOption);
+ OPERATOR_WRAP_BEFORE_OPTION = Collections.unmodifiableMap(wrapBeforeOption);
}
/** Penalty multiplier for wraps that are preferred */
@@ -573,11 +614,17 @@ public class WrapPreparator extends ASTVisitor {
if ((parent instanceof InfixExpression) && samePrecedence(node, (InfixExpression) parent))
return true; // this node has been handled higher in the AST
- findTokensToWrap(node, 0);
+ 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)) {
+ wrappingOption = this.options.alignment_for_string_concatenation;
+ wrapBeforeOperator = this.options.wrap_before_string_concatenation;
+ }
+
+ findTokensToWrap(node, wrapBeforeOperator, 0);
this.wrapParentIndex = this.wrapIndexes.remove(0);
this.wrapGroupEnd = this.tm.lastIndexIn(node, -1);
- if ((this.options.alignment_for_binary_expression & Alignment.M_INDENT_ON_COLUMN) != 0
- && this.wrapParentIndex > 0)
+ if ((wrappingOption & Alignment.M_INDENT_ON_COLUMN) != 0 && this.wrapParentIndex > 0)
this.wrapParentIndex--;
for (int i = this.wrapParentIndex; i >= 0; i--) {
if (!this.tm.get(i).isComment()) {
@@ -585,16 +632,16 @@ public class WrapPreparator extends ASTVisitor {
break;
}
}
- handleWrap(this.options.alignment_for_binary_expression, node);
+ handleWrap(wrappingOption, !wrapBeforeOperator, node);
return true;
}
- private void findTokensToWrap(InfixExpression node, int depth) {
+ private void findTokensToWrap(InfixExpression node, boolean wrapBeforeOperator, int depth) {
Expression left = node.getLeftOperand();
if (left instanceof InfixExpression && samePrecedence(node, (InfixExpression) left)) {
- findTokensToWrap((InfixExpression) left, depth + 1);
+ findTokensToWrap((InfixExpression) left, wrapBeforeOperator, depth + 1);
} else if (this.wrapIndexes.isEmpty() // always add first operand, it will be taken as wrap parent
- || !this.options.wrap_before_binary_operator) {
+ || !wrapBeforeOperator) {
this.wrapIndexes.add(this.tm.firstIndexIn(left, -1));
}
@@ -603,19 +650,19 @@ public class WrapPreparator extends ASTVisitor {
for (int i = -1; i < extended.size(); i++) {
Expression operand = (i == -1) ? right : extended.get(i);
if (operand instanceof InfixExpression && samePrecedence(node, (InfixExpression) operand)) {
- findTokensToWrap((InfixExpression) operand, depth + 1);
+ findTokensToWrap((InfixExpression) operand, wrapBeforeOperator, depth + 1);
}
int indexBefore = this.tm.firstIndexBefore(operand, -1);
while (this.tm.get(indexBefore).isComment())
indexBefore--;
assert node.getOperator().toString().equals(this.tm.toString(indexBefore));
int indexAfter = this.tm.firstIndexIn(operand, -1);
- this.wrapIndexes.add(this.options.wrap_before_binary_operator ? indexBefore : indexAfter);
- this.secondaryWrapIndexes.add(this.options.wrap_before_binary_operator ? indexAfter : indexBefore);
+ this.wrapIndexes.add(wrapBeforeOperator ? indexBefore : indexAfter);
+ this.secondaryWrapIndexes.add(wrapBeforeOperator ? indexAfter : indexBefore);
if (!this.options.join_wrapped_lines) {
// TODO there should be an option for never joining wraps on opposite side of the operator
- if (this.options.wrap_before_binary_operator) {
+ if (wrapBeforeOperator) {
if (this.tm.countLineBreaksBetween(this.tm.get(indexAfter - 1), this.tm.get(indexAfter)) > 0)
this.wrapIndexes.add(indexAfter);
} else {
@@ -626,6 +673,21 @@ 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());
@@ -1055,14 +1117,18 @@ public class WrapPreparator extends ASTVisitor {
}
private void handleWrap(int wrappingOption, ASTNode parentNode) {
- doHandleWrap(wrappingOption, parentNode);
+ handleWrap(wrappingOption, true, parentNode);
+ }
+
+ private void handleWrap(int wrappingOption, boolean wrapPreceedingComments, ASTNode parentNode) {
+ doHandleWrap(wrappingOption, wrapPreceedingComments, parentNode);
this.wrapIndexes.clear();
this.secondaryWrapIndexes.clear();
this.wrapPenalties.clear();
this.wrapParentIndex = this.wrapGroupEnd = -1;
}
- private void doHandleWrap(int wrappingOption, ASTNode parentNode) {
+ private void doHandleWrap(int wrappingOption, boolean wrapPreceedingComments, ASTNode parentNode) {
if (this.wrapIndexes.isEmpty())
return;
assert this.wrapParentIndex >= 0 && this.wrapParentIndex < this.wrapIndexes.get(0);
@@ -1085,8 +1151,6 @@ public class WrapPreparator extends ASTVisitor {
setTokenWrapPolicy(0, policy, true);
- boolean wrapPreceedingComments = !(parentNode instanceof InfixExpression)
- || !this.options.wrap_before_binary_operator;
for (int i = 1; i < this.wrapIndexes.size(); i++) {
penalty = this.wrapPenalties.size() > i ? this.wrapPenalties.get(i) : 1;
if (penalty != policy.penaltyMultiplier || i == 1)

Back to the top