### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java,v
retrieving revision 1.95
diff -u -r1.95 DefaultCodeFormatterConstants.java
--- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 4 Dec 2008 16:36:01 -0000 1.95
+++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 8 Dec 2008 14:48:38 -0000
@@ -3115,14 +3115,57 @@
public static final String FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE = JavaCore.PLUGIN_ID + ".formatter.number_of_empty_lines_to_preserve"; //$NON-NLS-1$
/**
*
- * FORMATTER / Option to specify whether the formatter should preserve existing line breaks or not
- * - option id: "org.eclipse.jdt.core.formatter.preserve_existing_line_breaks"
+ * FORMATTER / Option to specify whether the formatter can join wrapped lines or not
+ *
+ * For example, the wrapped lines of method foo return statement in following test case:
+ * class X {
+ * String foo() {
+ * return "select x "
+ * + "from y "
+ * + "where z=a";
+ * }
+ * }
+ *
+ * will be preserved by the formatter when the new preference is used
+ * even if the maximum line width would give it enough space to join the lines.
+ * Hence produces the following output:
+ * class X {
+ * String foo() {
+ * return "select x "
+ * + "from y "
+ * + "where z=a";
+ * }
+ * }
+ *
+ * - option id: "org.eclipse.jdt.core.formatter.join_wrapped_lines"
* - possible values: { TRUE, FALSE }
- * - default: FALSE
+ * - default: TRUE
+ *
+ * @since 3.5
+ */
+ public static final String FORMATTER_JOIN_WRAPPED_LINES = JavaCore.PLUGIN_ID + ".formatter.join_wrapped_lines"; //$NON-NLS-1$
+ /**
+ *
+ * FORMATTER / Option to specify whether the formatter can join text lines in comments or not
+ *
+ * For example, the following comment:
+ * /**
+ * * The foo method.
+ * * foo is a substitute for bar.
+ * */
+ * public class X {
+ * }
+ *
+ * will be unchanged by the formatter when this new preference is used,
+ * even if the maximum line width would give it enough space to join the lines.
+ *
+ * - option id: "org.eclipse.jdt.core.formatter.join_lines_in_comments"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
*
* @since 3.5
*/
- public static final String FORMATTER_PRESERVE_EXISTING_LINE_BREAKS = JavaCore.PLUGIN_ID + ".formatter.preserve_existing_line_breaks"; //$NON-NLS-1$
+ public static final String FORMATTER_JOIN_LINES_IN_COMMENTS = JavaCore.PLUGIN_ID + ".formatter.join_lines_in_comments"; //$NON-NLS-1$
/**
*
* FORMATTER / Option to specify whether or not empty statement should be on a new line
Index: buildnotes_jdt-core.html
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v
retrieving revision 1.6790
diff -u -r1.6790 buildnotes_jdt-core.html
--- buildnotes_jdt-core.html 8 Dec 2008 12:54:44 -0000 1.6790
+++ buildnotes_jdt-core.html 8 Dec 2008 14:48:36 -0000
@@ -50,7 +50,71 @@
eclipse.exe -vmArgs -Dorg.eclipse.jdt.core.javamodelcache.ratio=1.5
+
+
+As users may want to have different behavior in comments, the new formatter
+preference to preserve line breaks is now controlled by two different options:
+
+- for the already wrapped code lines:
+DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES
+
+/**
+ * FORMATTER / Option to specify whether the formatter can join wrapped lines or not
+ *
+ * For example, the wrapped lines of method foo return statement in following test case:
+ * class X {
+ * String foo() {
+ * return "select x "
+ * + "from y "
+ * + "where z=a";
+ * }
+ * }
+ *
+ * will be preserved by the formatter when the new preference is used
+ * even if the maximum line width would give it enough space to join the lines.
+ * Hence produces the following output:
+ * class X {
+ * String foo() {
+ * return "select x "
+ * + "from y "
+ * + "where z=a";
+ * }
+ * }
+ *
+ * - option id: "org.eclipse.jdt.core.formatter.join_wrapped_lines"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ *
+ * @since 3.5
+ */
+
+
+- for the lines in comments:
+DefaultCodeFormatterConstants.FORMATTER_JOIN_LINES_IN_COMMENTS
+
+/**
+ * FORMATTER / Option to specify whether the formatter can join text lines in comments or not
+ *
+ * For example, the following comment:
+ * /**
+ * * The foo method.
+ * * foo is a substitute for bar.
+ * */
+ * public class X {
+ * }
+ *
+ * will be unchanged by the formatter when this new preference is used,
+ * even if the maximum line width would give it enough space to join the lines.
+ *
+ * - option id: "org.eclipse.jdt.core.formatter.join_lines_in_comments"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ *
+ * @since 3.5
+ */
+
+
Problem Reports Fixed
Index: formatter/org/eclipse/jdt/internal/formatter/Scribe.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java,v
retrieving revision 1.155
diff -u -r1.155 Scribe.java
--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 4 Dec 2008 16:36:02 -0000 1.155
+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 8 Dec 2008 14:48:43 -0000
@@ -936,7 +936,7 @@
if (count == 0) {
// preserve line breaks in wrapping if specified
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074
- if (this.currentAlignment != null && this.formatter.preferences.preserve_existing_line_breaks) {
+ if (this.currentAlignment != null && !this.formatter.preferences.join_wrapped_lines) {
int savedIndentation = this.indentationLevel;
StringBuffer buffer = new StringBuffer(getNewLine());
this.indentationLevel = this.currentAlignment.breakIndentationLevel;
@@ -1427,7 +1427,7 @@
int hasTextOnFirstLine = 0;
boolean firstWord = true;
boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_block_comment;
- boolean preserveBreakLines = this.formatter.preferences.preserve_existing_line_breaks;
+ boolean joinLines = this.formatter.preferences.join_lines_in_comments;
int scannerLine = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, 0, this.maxLines);
int firstLine = scannerLine;
int lineNumber = scannerLine;
@@ -1534,7 +1534,7 @@
// insert one blank line before root tags
linesGap = 2;
}
- max = preserveBreakLines ? 0 : 1;
+ max = joinLines ? 1 : 0;
}
if (linesGap > max) {
if (clearBlankLines) {
@@ -1542,7 +1542,7 @@
if (token == TerminalTokens.TokenNameAT) {
linesGap = 1;
} else {
- linesGap = max==0 || preserveBreakLines ? 1 : 0;
+ linesGap = (max==0 || !joinLines) ? 1 : 0;
}
}
for (int i=0; i (previousEnd+1)) {
- if (!clearBlankLines || preserveBreakLines) {
+ if (!clearBlankLines || !joinLines) {
int startLine = Util.getLineNumber(nodeStart, this.lineEnds, previousLine-1, this.maxLines);
int gapLine = previousLine;
- if (!preserveBreakLines) gapLine++; // if not preserving line break then gap must be at least of one line
+ if (joinLines) gapLine++; // if not preserving line break then gap must be at least of one line
if (startLine > gapLine) {
newLines = startLine - previousLine;
}
@@ -3324,7 +3324,7 @@
private void printJavadocText(FormatJavadocText text, FormatJavadocBlock block, boolean textOnNewLine) {
boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment;
- boolean preserveBreakLines = this.formatter.preferences.preserve_existing_line_breaks;
+ boolean joinLines = this.formatter.preferences.join_lines_in_comments;
StringBuffer buffer = new StringBuffer();
int textStart = text.sourceStart;
int nextStart = textStart;
@@ -3347,11 +3347,11 @@
// Replace with current buffer if there are several empty lines between text lines
nextStart = (int) text.separators[idx];
- if (!clearBlankLines || preserveBreakLines) {
+ if (!clearBlankLines || !joinLines) {
int endLine = Util.getLineNumber(end, this.lineEnds, startLine-1, this.maxLines);
startLine = Util.getLineNumber(nextStart, this.lineEnds, endLine-1, this.maxLines);
int gapLine = endLine;
- if (!preserveBreakLines) gapLine++; // if not preserving line break then gap must be at least of one line
+ if (joinLines) gapLine++; // if not preserving line break then gap must be at least of one line
if (startLine > gapLine) {
addReplaceEdit(textStart, end, buffer.toString());
textStart = nextStart;
Index: formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java,v
retrieving revision 1.93
diff -u -r1.93 DefaultCodeFormatterOptions.java
--- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 4 Dec 2008 16:36:02 -0000 1.93
+++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 8 Dec 2008 14:48:40 -0000
@@ -302,7 +302,8 @@
public boolean never_indent_block_comments_on_first_column;
public boolean never_indent_line_comments_on_first_column;
public int number_of_empty_lines_to_preserve;
- public boolean preserve_existing_line_breaks;
+ public boolean join_wrapped_lines;
+ public boolean join_lines_in_comments;
public boolean put_empty_statement_on_new_line;
public int tab_size;
public final char filling_space = ' ';
@@ -580,7 +581,8 @@
options.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, this.never_indent_block_comments_on_first_column ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, this.never_indent_line_comments_on_first_column ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, Integer.toString(this.number_of_empty_lines_to_preserve));
- options.put(DefaultCodeFormatterConstants.FORMATTER_PRESERVE_EXISTING_LINE_BREAKS, this.preserve_existing_line_breaks ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, this.join_wrapped_lines ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_LINES_IN_COMMENTS, this.join_lines_in_comments ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, this.put_empty_statement_on_new_line ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, Integer.toString(this.page_width));
switch(this.tab_char) {
@@ -1848,9 +1850,13 @@
this.number_of_empty_lines_to_preserve = 0;
}
}
- final Object preserveExistingLineBreaksOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_PRESERVE_EXISTING_LINE_BREAKS);
- if (preserveExistingLineBreaksOption != null) {
- this.preserve_existing_line_breaks = DefaultCodeFormatterConstants.TRUE.equals(preserveExistingLineBreaksOption);
+ final Object joinLinesInCommentsOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_JOIN_LINES_IN_COMMENTS);
+ if (joinLinesInCommentsOption != null) {
+ this.join_lines_in_comments = DefaultCodeFormatterConstants.TRUE.equals(joinLinesInCommentsOption);
+ }
+ final Object joinWrappedLinesOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES);
+ if (joinWrappedLinesOption != null) {
+ this.join_wrapped_lines = DefaultCodeFormatterConstants.TRUE.equals(joinWrappedLinesOption);
}
final Object putEmptyStatementOnNewLineOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE);
if (putEmptyStatementOnNewLineOption != null) {
@@ -2191,7 +2197,8 @@
this.never_indent_block_comments_on_first_column = false;
this.never_indent_line_comments_on_first_column = false;
this.number_of_empty_lines_to_preserve = 1;
- this.preserve_existing_line_breaks = false;
+ this.join_lines_in_comments = true;
+ this.join_wrapped_lines = true;
this.put_empty_statement_on_new_line = false;
this.tab_size = 4;
this.page_width = 80;
@@ -2456,7 +2463,8 @@
this.never_indent_block_comments_on_first_column = false;
this.never_indent_line_comments_on_first_column = false;
this.number_of_empty_lines_to_preserve = 1;
- this.preserve_existing_line_breaks = false;
+ this.join_lines_in_comments = true;
+ this.join_wrapped_lines = true;
this.put_empty_statement_on_new_line = true;
this.tab_size = 8;
this.page_width = 80;
#P org.eclipse.jdt.core.tests.model
Index: src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java,v
retrieving revision 1.31
diff -u -r1.31 FormatterCommentsBugsTest.java
--- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 4 Dec 2008 16:35:57 -0000 1.31
+++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 8 Dec 2008 14:48:46 -0000
@@ -2346,7 +2346,7 @@
);
}
public void testBug239130_preserveLineBreaks() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_lines_in_comments = false;
String source =
"public class X {\n" +
"\n" +
@@ -2372,7 +2372,7 @@
);
}
public void testBug239130_clearBlankLines_preserveLineBreaks() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_lines_in_comments = false;
this.formatterPrefs.comment_clear_blank_lines_in_javadoc_comment = true;
String source =
"public class X {\n" +
@@ -2432,7 +2432,7 @@
);
}
public void testBug239130_196124() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_lines_in_comments = false;
String source =
"public class X {\n" +
"\n" +
@@ -2485,6 +2485,7 @@
formatSource(source, source);
}
public void testBug239130_96696_block_clearBlankLines() throws JavaModelException {
+ this.formatterPrefs.join_wrapped_lines = false;
this.formatterPrefs.comment_clear_blank_lines_in_block_comment = true;
String source =
"public class Test {\n" +
@@ -2514,7 +2515,7 @@
);
}
public void testBug239130_96696_block_clearBlankLines_preserveLineBreaks() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_lines_in_comments = false;
this.formatterPrefs.comment_clear_blank_lines_in_block_comment = true;
String source =
"public class Test {\n" +
@@ -2591,7 +2592,7 @@
);
}
public void testBug239130_96696_javadoc_clearBlankLines_preserveLineBreaks() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_lines_in_comments = false;
this.formatterPrefs.comment_clear_blank_lines_in_javadoc_comment = true;
String source =
"public class Test {\n" +
Index: src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java,v
retrieving revision 1.238
diff -u -r1.238 FormatterRegressionTests.java
--- src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 4 Dec 2008 16:35:57 -0000 1.238
+++ src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 8 Dec 2008 14:48:54 -0000
@@ -10575,7 +10575,7 @@
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074"
*/
public void testBug198074() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_wrapped_lines = false;
String source =
"public class Test {\n" +
"\n" +
@@ -10598,7 +10598,7 @@
}
// another test case put in bug's comment 1
public void testBug198074_c1() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_wrapped_lines = false;
String source =
"public class Test {\n" +
"\n" +
@@ -10628,7 +10628,7 @@
}
// another test case put in bug's comment 3
public void testBug198074_c3() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_wrapped_lines = false;
String source =
"public class Test {\n" +
"\n" +
@@ -10656,9 +10656,29 @@
"}\n"
);
}
+public void testBug198074_comments() throws JavaModelException {
+ this.formatterPrefs.join_lines_in_comments = false;
+ String source =
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ "String x = \"select x \"\n" +
+ " + \"from y \"\n" +
+ " + \"where z=a\";\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "public class Test {\n" +
+ "\n" +
+ " void foo() {\n" +
+ " String x = \"select x \" + \"from y \" + \"where z=a\";\n" +
+ " }\n" +
+ "}\n"
+ );
+}
// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=201022
public void testBug201022() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_wrapped_lines = false;
String source =
"public class Test {\n" +
"\n" +
@@ -10685,7 +10705,7 @@
}
// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
public void testBug208541() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_wrapped_lines = false;
String source =
"public class MyTest {\n" +
"\n" +
@@ -10712,7 +10732,7 @@
}
// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=213700
public void testBug213700() throws JavaModelException {
- this.formatterPrefs.preserve_existing_line_breaks = true;
+ this.formatterPrefs.join_wrapped_lines = false;
String source =
"public class Test {\n" +
"\n" +