362260 - [formatter] New feature: count comment width from starting position
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 a7b2573..ba62f38 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13918,4 +13918,83 @@
String input = getCompilationUnit("Formatter", "", "test493296", "A_in.java").getSource();
formatSource(input, getCompilationUnit("Formatter", "", "test493296", "A_out.java").getSource());
}
+/**
+ * https://bugs.eclipse.org/362260 - [formatter] New feature: count comment width from starting position
+ */
+public void testBug362260a() throws JavaModelException {
+ setPageWidth80();
+ this.formatterPrefs.comment_line_length = 40;
+ this.formatterPrefs.comment_format_header = true;
+ this.formatterPrefs.comment_count_line_length_from_starting_position = true;
+ String input = getCompilationUnit("Formatter", "", "test362260", "A_in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test362260", "A_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/362260 - [formatter] New feature: count comment width from starting position
+ */
+public void testBug362260b() throws JavaModelException {
+ setPageWidth80();
+ this.formatterPrefs.comment_line_length = 40;
+ this.formatterPrefs.comment_format_header = true;
+ this.formatterPrefs.comment_count_line_length_from_starting_position = true;
+ String input = getCompilationUnit("Formatter", "", "test362260", "B_in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test362260", "B_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/362260 - [formatter] New feature: count comment width from starting position
+ */
+public void testBug362260c() throws JavaModelException {
+ setPageWidth80();
+ this.formatterPrefs.comment_line_length = 40;
+ this.formatterPrefs.comment_format_header = true;
+ this.formatterPrefs.comment_count_line_length_from_starting_position = true;
+ this.formatterPrefs.comment_new_lines_at_block_boundaries = false;
+ String input = getCompilationUnit("Formatter", "", "test362260", "C_in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test362260", "C_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/362260 - [formatter] New feature: count comment width from starting position
+ */
+public void testBug362260d() throws JavaModelException {
+ setPageWidth80();
+ this.formatterPrefs.comment_line_length = 40;
+ this.formatterPrefs.comment_format_header = true;
+ this.formatterPrefs.comment_count_line_length_from_starting_position = true;
+ String input = getCompilationUnit("Formatter", "", "test362260", "D_in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test362260", "D_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/362260 - [formatter] New feature: count comment width from starting position
+ */
+public void testBug362260e() throws JavaModelException {
+ setPageWidth80();
+ this.formatterPrefs.comment_line_length = 40;
+ this.formatterPrefs.comment_format_header = true;
+ this.formatterPrefs.comment_count_line_length_from_starting_position = true;
+ this.formatterPrefs.comment_new_lines_at_javadoc_boundaries = false;
+ String input = getCompilationUnit("Formatter", "", "test362260", "E_in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test362260", "E_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/362260 - [formatter] New feature: count comment width from starting position
+ */
+public void testBug362260f() throws JavaModelException {
+ setPageWidth80();
+ this.formatterPrefs.comment_line_length = 40;
+ this.formatterPrefs.comment_count_line_length_from_starting_position = true;
+ this.formatterPrefs.comment_preserve_white_space_between_code_and_line_comments = true;
+ String input = getCompilationUnit("Formatter", "", "test362260", "F_in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test362260", "F_out.java").getSource());
+}
+/**
+ * https://bugs.eclipse.org/362260 - [formatter] New feature: count comment width from starting position
+ */
+public void testBug362260g() throws JavaModelException {
+ setPageWidth80();
+ this.formatterPrefs.comment_line_length = 40;
+ this.formatterPrefs.comment_format_header = true;
+ this.formatterPrefs.comment_count_line_length_from_starting_position = true;
+ String input = getCompilationUnit("Formatter", "", "test362260", "G_in.java").getSource();
+ formatSource(input, getCompilationUnit("Formatter", "", "test362260", "G_out.java").getSource());
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/A_in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/A_in.java
new file mode 100644
index 0000000..58b7139
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/A_in.java
@@ -0,0 +1,25 @@
+// 45678901234567890123456789 1234567890 2
+// 45678901234567890123456789 12345678901
+class A {
+ // 45678901234567890123456789 1234567890 2
+ // 45678901234567890123456789 12345678901
+ int f() {
+ // 45678901234567890123456789 1234567890 2
+ // 45678901234567890123456789 12345678901
+
+ int a; // 45678901234567890123456789 1234567890 2
+ int b; // 45678901234567890123456789 12345678901
+
+ String c; // 45678901234567890123456789 1234567890 2
+ String d; // 45678901234567890123456789 12345678901
+
+ String e = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa"; // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
+
+ String f = "aaaaaa"; // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
+ String g = "aaaaaa"; //$NON-NLS-1$ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
+ String h = "aaaaaaaaaaaa"; //$NON-NLS-1$ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
+ String i = "aaaaaaaaaaaa"; // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 //$NON-NLS-1$
+
+ f(); // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/A_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/A_out.java
new file mode 100644
index 0000000..5aac587
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/A_out.java
@@ -0,0 +1,43 @@
+// 45678901234567890123456789 1234567890
+// 2
+// 45678901234567890123456789
+// 12345678901
+class A {
+ // 45678901234567890123456789 1234567890
+ // 2
+ // 45678901234567890123456789
+ // 12345678901
+ int f() {
+ // 45678901234567890123456789 1234567890
+ // 2
+ // 45678901234567890123456789
+ // 12345678901
+
+ int a; // 45678901234567890123456789 1234567890
+ // 2
+ int b; // 45678901234567890123456789
+ // 12345678901
+
+ String c; // 45678901234567890123456789 1234567890
+ // 2
+ String d; // 45678901234567890123456789
+ // 12345678901
+
+ String e = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa"; // 1 2 3 4 5 6 7 8 9
+ // 10 11 12 13 14 15
+ // 16 17 18 19 20
+
+ String f = "aaaaaa"; // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+ // 16 17 18 19 20
+ String g = "aaaaaa"; //$NON-NLS-1$ 1 2 3 4 5 6 7 8 9 10 11
+ // 12 13 14 15 16 17 18 19 20
+ String h = "aaaaaaaaaaaa"; //$NON-NLS-1$ 1 2 3 4 5 6 7 8 9 10 11
+ // 12 13 14 15 16 17 18 19 20
+ String i = "aaaaaaaaaaaa"; // 1 2 3 4 5 6 7 8 9 10 11 //$NON-NLS-1$
+ // 12 13 14 15 16 17 18 19 20
+
+ f(); // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ // 9 0 1 2 3 4 5 6 7 8 9 0
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/B_in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/B_in.java
new file mode 100644
index 0000000..7857bc7
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/B_in.java
@@ -0,0 +1,36 @@
+/* 45678901234567890123456789 1234567 */
+/* 45678901234567890123456789 12345678 */
+/* 45678901234567890123456789 1234567890 2 */
+/* 45678901234567890123456789 12345678901 */
+class A {
+ /* 45678901234567890123456789 1234567 */
+ /* 45678901234567890123456789 12345678 */
+ /* 45678901234567890123456789 1234567890 2 */
+ /* 45678901234567890123456789 12345678901 */
+ int f() {
+ /* 45678901234567890123456789 1234567 */
+ /* 45678901234567890123456789 12345678 */
+ /* 45678901234567890123456789 1234567890 2 */
+ /* 45678901234567890123456789 12345678901 */
+
+ int a; /* 45678901234567890123456789 1234567 */
+ int b; /* 45678901234567890123456789 12345678 */
+ int c; /* 45678901234567890123456789 1234567890 2 */
+ int d; /* 45678901234567890123456789 12345678901 */
+
+ String e; /* 45678901234567890123456789 1234567 */
+ Atring f; /* 45678901234567890123456789 12345678 */
+ String g; /* 45678901234567890123456789 1234567890 2 */
+ String h; /* 45678901234567890123456789 12345678901 */
+
+ String i = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String j = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 */
+ String k = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 */
+
+ String l = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String m = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String n = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+
+ f(); /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 */
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/B_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/B_out.java
new file mode 100644
index 0000000..73f8374
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/B_out.java
@@ -0,0 +1,96 @@
+/* 45678901234567890123456789 1234567 */
+/*
+ * 45678901234567890123456789 12345678
+ */
+/*
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+/*
+ * 45678901234567890123456789
+ * 12345678901
+ */
+class A {
+ /* 45678901234567890123456789 1234567 */
+ /*
+ * 45678901234567890123456789 12345678
+ */
+ /*
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+ /*
+ * 45678901234567890123456789
+ * 12345678901
+ */
+ int f() {
+ /* 45678901234567890123456789 1234567 */
+ /*
+ * 45678901234567890123456789 12345678
+ */
+ /*
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+ /*
+ * 45678901234567890123456789
+ * 12345678901
+ */
+
+ int a; /* 45678901234567890123456789 1234567 */
+ int b; /*
+ * 45678901234567890123456789 12345678
+ */
+ int c; /*
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+ int d; /*
+ * 45678901234567890123456789
+ * 12345678901
+ */
+
+ String e; /* 45678901234567890123456789 1234567 */
+ Atring f; /*
+ * 45678901234567890123456789 12345678
+ */
+ String g; /*
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+ String h; /*
+ * 45678901234567890123456789
+ * 12345678901
+ */
+
+ String i = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String j = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaa"; /*
+ * 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ */
+ String k = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaa"; /*
+ * 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ * 0
+ */
+
+ String l = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String m = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaaa"; /*
+ * 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
+ */
+ String n = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; /*
+ * 1 2 3 4 5 6 7 8 9 0 1
+ * 2 3 4 5 6 7
+ */
+
+ f(); /*
+ * 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ * 9 0 1 2 3 4 5 6 7 8 9 0
+ */
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/C_in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/C_in.java
new file mode 100644
index 0000000..7857bc7
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/C_in.java
@@ -0,0 +1,36 @@
+/* 45678901234567890123456789 1234567 */
+/* 45678901234567890123456789 12345678 */
+/* 45678901234567890123456789 1234567890 2 */
+/* 45678901234567890123456789 12345678901 */
+class A {
+ /* 45678901234567890123456789 1234567 */
+ /* 45678901234567890123456789 12345678 */
+ /* 45678901234567890123456789 1234567890 2 */
+ /* 45678901234567890123456789 12345678901 */
+ int f() {
+ /* 45678901234567890123456789 1234567 */
+ /* 45678901234567890123456789 12345678 */
+ /* 45678901234567890123456789 1234567890 2 */
+ /* 45678901234567890123456789 12345678901 */
+
+ int a; /* 45678901234567890123456789 1234567 */
+ int b; /* 45678901234567890123456789 12345678 */
+ int c; /* 45678901234567890123456789 1234567890 2 */
+ int d; /* 45678901234567890123456789 12345678901 */
+
+ String e; /* 45678901234567890123456789 1234567 */
+ Atring f; /* 45678901234567890123456789 12345678 */
+ String g; /* 45678901234567890123456789 1234567890 2 */
+ String h; /* 45678901234567890123456789 12345678901 */
+
+ String i = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String j = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 */
+ String k = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 */
+
+ String l = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String m = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String n = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+
+ f(); /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 */
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/C_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/C_out.java
new file mode 100644
index 0000000..d7bc0ca
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/C_out.java
@@ -0,0 +1,63 @@
+/* 45678901234567890123456789 1234567 */
+/* 45678901234567890123456789
+ * 12345678 */
+/* 45678901234567890123456789 1234567890
+ * 2 */
+/* 45678901234567890123456789
+ * 12345678901 */
+class A {
+ /* 45678901234567890123456789 1234567 */
+ /* 45678901234567890123456789
+ * 12345678 */
+ /* 45678901234567890123456789 1234567890
+ * 2 */
+ /* 45678901234567890123456789
+ * 12345678901 */
+ int f() {
+ /* 45678901234567890123456789 1234567 */
+ /* 45678901234567890123456789
+ * 12345678 */
+ /* 45678901234567890123456789 1234567890
+ * 2 */
+ /* 45678901234567890123456789
+ * 12345678901 */
+
+ int a; /* 45678901234567890123456789 1234567 */
+ int b; /* 45678901234567890123456789
+ * 12345678 */
+ int c; /* 45678901234567890123456789 1234567890
+ * 2 */
+ int d; /* 45678901234567890123456789
+ * 12345678901 */
+
+ String e; /* 45678901234567890123456789 1234567 */
+ Atring f; /* 45678901234567890123456789
+ * 12345678 */
+ String g; /* 45678901234567890123456789 1234567890
+ * 2 */
+ String h; /* 45678901234567890123456789
+ * 12345678901 */
+
+ String i = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String j = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
+ * 8 */
+ String k = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ * 0 */
+
+ String l = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String m = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
+ * 7 */
+ String n = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; /* 1 2 3 4 5 6 7 8 9 0 1
+ * 2 3 4 5 6 7 */
+
+ f(); /* 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ * 9 0 1 2 3 4 5 6 7 8 9 0 */
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/D_in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/D_in.java
new file mode 100644
index 0000000..71c9b44
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/D_in.java
@@ -0,0 +1,36 @@
+/** 5678901234567890123456789 1234567 */
+/** 45678901234567890123456789 1234567 */
+/** 45678901234567890123456789 1234567890 2 */
+/** 45678901234567890123456789 12345678901 */
+class A {
+ /** 5678901234567890123456789 1234567 */
+ /** 45678901234567890123456789 1234567 */
+ /** 45678901234567890123456789 1234567890 2 */
+ /** 45678901234567890123456789 12345678901 */
+ int f() {
+ /** 5678901234567890123456789 1234567 */
+ /** 45678901234567890123456789 1234567 */
+ /** 45678901234567890123456789 1234567890 2 */
+ /** 45678901234567890123456789 12345678901 */
+
+ int a; /** 5678901234567890123456789 1234567 */
+ int b; /** 45678901234567890123456789 1234567 */
+ int c; /** 45678901234567890123456789 1234567890 2 */
+ int d; /** 45678901234567890123456789 12345678901 */
+
+ String e; /** 5678901234567890123456789 1234567 */
+ String f; /** 45678901234567890123456789 1234567 */
+ String g; /** 45678901234567890123456789 1234567890 2 */
+ String h; /** 45678901234567890123456789 12345678901 */
+
+ String i = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String j = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 */
+ String k = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 */
+
+ String l = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String m = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String n = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+
+ f(); /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 */
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/D_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/D_out.java
new file mode 100644
index 0000000..7487134
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/D_out.java
@@ -0,0 +1,96 @@
+/** 5678901234567890123456789 1234567 */
+/**
+ * 45678901234567890123456789 1234567
+ */
+/**
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+/**
+ * 45678901234567890123456789
+ * 12345678901
+ */
+class A {
+ /** 5678901234567890123456789 1234567 */
+ /**
+ * 45678901234567890123456789 1234567
+ */
+ /**
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+ /**
+ * 45678901234567890123456789
+ * 12345678901
+ */
+ int f() {
+ /** 5678901234567890123456789 1234567 */
+ /**
+ * 45678901234567890123456789 1234567
+ */
+ /**
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+ /**
+ * 45678901234567890123456789
+ * 12345678901
+ */
+
+ int a; /** 5678901234567890123456789 1234567 */
+ int b; /**
+ * 45678901234567890123456789 1234567
+ */
+ int c; /**
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+ int d; /**
+ * 45678901234567890123456789
+ * 12345678901
+ */
+
+ String e; /** 5678901234567890123456789 1234567 */
+ String f; /**
+ * 45678901234567890123456789 1234567
+ */
+ String g; /**
+ * 45678901234567890123456789 1234567890
+ * 2
+ */
+ String h; /**
+ * 45678901234567890123456789
+ * 12345678901
+ */
+
+ String i = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String j = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaa"; /**
+ * 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ */
+ String k = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaa"; /**
+ * 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ * 0
+ */
+
+ String l = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String m = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaa"; /**
+ * 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
+ */
+ String n = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; /**
+ * 1 2 3 4 5 6 7 8 9 0 1
+ * 2 3 4 5 6 7
+ */
+
+ f(); /**
+ * 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ * 9 0 1 2 3 4 5 6 7 8 9 0
+ */
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/E_in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/E_in.java
new file mode 100644
index 0000000..b898959
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/E_in.java
@@ -0,0 +1,36 @@
+/** 5678901234567890123456789 1234567 */
+/** 5678901234567890123456789 12345678 */
+/** 5678901234567890123456789 1234567890 2 */
+/** 5678901234567890123456789 12345678901 */
+class A {
+ /** 5678901234567890123456789 1234567 */
+ /** 5678901234567890123456789 12345678 */
+ /** 5678901234567890123456789 1234567890 2 */
+ /** 5678901234567890123456789 12345678901 */
+ int f() {
+ /** 5678901234567890123456789 1234567 */
+ /** 5678901234567890123456789 12345678 */
+ /** 5678901234567890123456789 1234567890 2 */
+ /** 5678901234567890123456789 12345678901 */
+
+ int a; /** 5678901234567890123456789 1234567 */
+ int b; /** 5678901234567890123456789 12345678 */
+ int c; /** 5678901234567890123456789 1234567890 2 */
+ int d; /** 5678901234567890123456789 12345678901 */
+
+ String e; /** 5678901234567890123456789 1234567 */
+ String f; /** 5678901234567890123456789 12345678 */
+ String g; /** 5678901234567890123456789 1234567890 2 */
+ String h; /** 5678901234567890123456789 12345678901 */
+
+ String i = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String j = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 */
+ String k = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 */
+
+ String l = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String m = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String n = "aaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+
+ f(); /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 */
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/E_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/E_out.java
new file mode 100644
index 0000000..9dabac9
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/E_out.java
@@ -0,0 +1,63 @@
+/** 5678901234567890123456789 1234567 */
+/** 5678901234567890123456789
+ * 12345678 */
+/** 5678901234567890123456789 1234567890
+ * 2 */
+/** 5678901234567890123456789
+ * 12345678901 */
+class A {
+ /** 5678901234567890123456789 1234567 */
+ /** 5678901234567890123456789
+ * 12345678 */
+ /** 5678901234567890123456789 1234567890
+ * 2 */
+ /** 5678901234567890123456789
+ * 12345678901 */
+ int f() {
+ /** 5678901234567890123456789 1234567 */
+ /** 5678901234567890123456789
+ * 12345678 */
+ /** 5678901234567890123456789 1234567890
+ * 2 */
+ /** 5678901234567890123456789
+ * 12345678901 */
+
+ int a; /** 5678901234567890123456789 1234567 */
+ int b; /** 5678901234567890123456789
+ * 12345678 */
+ int c; /** 5678901234567890123456789 1234567890
+ * 2 */
+ int d; /** 5678901234567890123456789
+ * 12345678901 */
+
+ String e; /** 5678901234567890123456789 1234567 */
+ String f; /** 5678901234567890123456789
+ * 12345678 */
+ String g; /** 5678901234567890123456789 1234567890
+ * 2 */
+ String h; /** 5678901234567890123456789
+ * 12345678901 */
+
+ String i = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String j = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
+ * 8 */
+ String k = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ * 9 0 */
+
+ String l = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 */
+ String m = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
+ * 7 */
+ String n = "aaaaaaaaaaaaaaaa"
+ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; /** 1 2 3 4 5 6 7 8 9 0 1
+ * 2 3 4 5 6 7 */
+
+ f(); /** 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ * 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
+ * 8 9 0 1 2 3 4 5 6 7 8 9 0 */
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/F_in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/F_in.java
new file mode 100644
index 0000000..f03745c
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/F_in.java
@@ -0,0 +1,8 @@
+class A {
+ int a; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
+ int aaaaaaa; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
+ int aaaaaaaaaaaaaaaa; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
+
+ int aa; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
+ int aa; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/F_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/F_out.java
new file mode 100644
index 0000000..9842d13
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/F_out.java
@@ -0,0 +1,18 @@
+class A {
+ int a; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ // 9 0
+ int aaaaaaa; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ // 9 0
+ int aaaaaaaaaaaaaaaa; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ // 9 0
+
+ int aa; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ // 9 0
+ int aa; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+ // 9 0
+}
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/G_in.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/G_in.java
new file mode 100644
index 0000000..42b5909
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/G_in.java
@@ -0,0 +1,41 @@
+/**
+ * One two three four five six seven eight nine ten eleven twelve thirteen fourteen.
+ * <pre>
+ * int a = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0;
+ * </pre>
+ */
+class A {
+ class B {
+ class C {
+ class D {
+ class E {
+ class F {
+ class G {
+ /**
+ * One two three four five six seven eight nine ten eleven twelve thirteen fourteen.
+ * <pre>
+ * int a = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0;
+ * </pre>
+ */
+ class H {
+ class I {
+ class J {
+ class K {
+ /**
+ * One two three four five six seven eight nine ten eleven twelve thirteen fourteen.
+ * <pre>
+ * int a = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0;
+ * </pre>
+ */
+ int a;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/G_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/G_out.java
new file mode 100644
index 0000000..d6f35f3
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test362260/G_out.java
@@ -0,0 +1,53 @@
+/**
+ * One two three four five six seven
+ * eight nine ten eleven twelve thirteen
+ * fourteen.
+ *
+ * <pre>
+ * int a = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
+ * + 9 + 0;
+ * </pre>
+ */
+class A {
+ class B {
+ class C {
+ class D {
+ class E {
+ class F {
+ class G {
+ /**
+ * One two three four five six seven
+ * eight nine ten eleven twelve thirteen
+ * fourteen.
+ *
+ * <pre>
+ * int a = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
+ * + 9 + 0;
+ * </pre>
+ */
+ class H {
+ class I {
+ class J {
+ class K {
+ /**
+ * One two three four five six seven
+ * eight nine ten eleven twelve
+ * thirteen fourteen.
+ *
+ * <pre>
+ * int a = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
+ * + 9 + 0;
+ * </pre>
+ */
+ int a;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
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 987a744..9f9f186 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, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -1067,6 +1067,17 @@
/**
* <pre>
+ * FORMATTER / Option to control whether comments' line length will be counted from their starting position
+ * - option id: "org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position"
+ * - possible values: { TRUE, FALSE }
+ * - default: FALSE
+ * </pre>
+ * @since 3.13
+ */
+ public final static String FORMATTER_COMMENT_COUNT_LINE_LENGTH_FROM_STARTING_POSITION = "org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position"; //$NON-NLS-1$
+
+ /**
+ * <pre>
* FORMATTER / Option to control whether block comments will have new lines at boundaries
* - option id: "org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries"
* - possible values: { TRUE, FALSE }
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 45a9848..d35679a 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, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -200,6 +200,7 @@
public boolean comment_insert_new_line_for_parameter;
public boolean comment_preserve_white_space_between_code_and_line_comments;
public int comment_line_length;
+ public boolean comment_count_line_length_from_starting_position;
public boolean use_tags;
public char[] disabling_tag;
@@ -514,6 +515,7 @@
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INSERT_NEW_LINE_FOR_PARAMETER, this.comment_insert_new_line_for_parameter ? JavaCore.INSERT : JavaCore.DO_NOT_INSERT);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, this.comment_preserve_white_space_between_code_and_line_comments ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, Integer.toString(this.comment_line_length));
+ options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_COUNT_LINE_LENGTH_FROM_STARTING_POSITION, this.comment_count_line_length_from_starting_position ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, Integer.toString(this.continuation_indentation));
options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER, Integer.toString(this.continuation_indentation_for_array_initializer));
options.put(DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AFTER_IMPORTS, Integer.toString(this.blank_lines_after_imports));
@@ -1372,6 +1374,10 @@
this.comment_line_length = 80;
}
}
+ final Object commentCountLineLengthFromStartingPositionOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_COUNT_LINE_LENGTH_FROM_STARTING_POSITION);
+ if (commentCountLineLengthFromStartingPositionOption != null) {
+ this.comment_count_line_length_from_starting_position = DefaultCodeFormatterConstants.TRUE.equals(commentCountLineLengthFromStartingPositionOption);
+ }
final Object commentNewLinesAtBlockBoundariesOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEW_LINES_AT_BLOCK_BOUNDARIES);
if (commentNewLinesAtBlockBoundariesOption != null) {
this.comment_new_lines_at_block_boundaries = DefaultCodeFormatterConstants.TRUE.equals(commentNewLinesAtBlockBoundariesOption);
@@ -2478,6 +2484,7 @@
this.comment_new_lines_at_block_boundaries = true;
this.comment_new_lines_at_javadoc_boundaries = true;
this.comment_line_length = 80;
+ this.comment_count_line_length_from_starting_position = false;
this.comment_preserve_white_space_between_code_and_line_comments= false;
this.continuation_indentation = 2;
this.continuation_indentation_for_array_initializer = 2;
@@ -2787,6 +2794,7 @@
this.comment_new_lines_at_block_boundaries = true;
this.comment_new_lines_at_javadoc_boundaries = true;
this.comment_line_length = 80;
+ this.comment_count_line_length_from_starting_position = false;
this.comment_preserve_white_space_between_code_and_line_comments= false;
this.continuation_indentation = 2;
this.continuation_indentation_for_array_initializer = 2;
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/CommentWrapExecutor.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/CommentWrapExecutor.java
index 07333ee..3923553 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/CommentWrapExecutor.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/CommentWrapExecutor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2015 Mateusz Matela and others.
+ * Copyright (c) 2014, 2017 Mateusz Matela and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -36,6 +36,7 @@
private final ArrayList<Token> nlsTags = new ArrayList<>();
private int lineStartPosition;
+ private int lineLimit;
private boolean simulation;
private boolean wrapDisabled;
private boolean newLinesAtBoundries;
@@ -63,6 +64,7 @@
this.counter = startPosition;
commentToken.setIndent(this.tm.toIndent(startPosition, true));
this.lineStartPosition = commentToken.getIndent();
+ this.lineLimit = getLineLimit(startPosition);
this.simulation = simulate;
this.wrapDisabled = noWrap;
this.potentialWrapToken = this.potentialWrapTokenSubstitute = null;
@@ -109,7 +111,7 @@
if (i > 1 && (policy == null || policy == WrapPolicy.SUBSTITUTE_ONLY))
hasWrapPotential = true;
}
- if (position <= this.options.comment_line_length || noWrap || !hasWrapPotential)
+ if (position <= this.lineLimit || noWrap || !hasWrapPotential)
return position;
return -1;
}
@@ -136,6 +138,7 @@
this.lineCounter += lineBreaksBefore;
this.counter = positionIfNewLine;
this.potentialWrapToken = this.potentialWrapTokenSubstitute = null;
+ this.lineLimit = getLineLimit(this.lineStartPosition);
boolean isFormattedCode = token.getWrapPolicy() != null
&& token.getWrapPolicy() != WrapPolicy.SUBSTITUTE_ONLY;
@@ -177,6 +180,7 @@
this.counter = this.counterIfWrapped;
this.lineCounter++;
this.potentialWrapToken = this.potentialWrapTokenSubstitute = null;
+ this.lineLimit = getLineLimit(this.lineStartPosition);
}
if (isSpaceAfter()) {
@@ -188,8 +192,7 @@
}
private boolean shouldWrap() {
- int lineLenght = this.options.comment_line_length;
- if (this.wrapDisabled || this.counter <= lineLenght)
+ if (this.wrapDisabled || this.counter <= this.lineLimit)
return false;
if (getLineBreaksAfter() == 0 && getNext() != null && getNext().getWrapPolicy() == WrapPolicy.DISABLE_WRAP) {
// The next token cannot be wrapped, so there's no need to wrap now.
@@ -197,7 +200,7 @@
return false;
}
if (this.potentialWrapToken != null && this.potentialWrapTokenSubstitute != null
- && this.counterIfWrapped > lineLenght && this.counterIfWrappedSubstitute < this.counterIfWrapped) {
+ && this.counterIfWrapped > this.lineLimit && this.counterIfWrappedSubstitute < this.counterIfWrapped) {
// there is a normal token to wrap, but the line would overflow anyway - better use substitute
this.potentialWrapToken = null;
}
@@ -222,6 +225,7 @@
int position = startPosition;
startPosition = this.tm.toIndent(startPosition, true);
int indent = startPosition;
+ int limit = getLineLimit(position);
for (Token token : structure) {
if (token.hasNLSTag()) {
@@ -261,6 +265,7 @@
position++;
if (token.getLineBreaksBefore() > 0) {
position = startPosition;
+ limit = getLineLimit(position);
lineStartIndex = whitespace == null ? i : i + 1;
if (whitespace != null && token != whitespace) {
token.clearLineBreaksBefore();
@@ -269,7 +274,9 @@
}
}
position += this.tm.getLength(token, position);
- if (position > this.options.comment_line_length && i > lineStartIndex + 1) {
+ if (token.tokenType == TokenNameWHITESPACE)
+ limit = getLineLimit(position);
+ if (position > limit && i > lineStartIndex + 1) {
structure.add(i, prefix);
if (whitespace != null)
structure.add(i, whitespace);
@@ -282,4 +289,15 @@
}
this.nlsTags.clear();
}
+
+ private int getLineLimit(int startPosition) {
+ final int commentLength = this.options.comment_line_length;
+ if (!this.options.comment_count_line_length_from_starting_position)
+ return commentLength;
+ final int pageWidth = this.options.page_width;
+ int lineLength = startPosition + commentLength;
+ if (lineLength > pageWidth && commentLength <= pageWidth)
+ lineLength = pageWidth;
+ return lineLength;
+ }
}