### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: buildnotes_jdt-core.html
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v
retrieving revision 1.7338
diff -u -r1.7338 buildnotes_jdt-core.html
--- buildnotes_jdt-core.html 1 Mar 2010 06:50:28 -0000 1.7338
+++ buildnotes_jdt-core.html 1 Mar 2010 16:44:01 -0000
@@ -122,6 +122,40 @@
String[] getBoundsSignatures() throws JavaModelException;
+
+Added a new formatter preference to enable or disable the formatting of line
+comments that start on the first column.
+Note that the indentation of line comments will also be disabled when activating
+this option, as otherwise the formatter could not produce stable outputs...
+
+The default is to format these comments to have a backward compatible behavior.
+
+This new preferences is controlled with the options:
+DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN
+
+/**
+ * FORMATTER / Option to format line comments that start on the first column
+ * - option id: "org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ *
+ * Note that this option is ignored if the formatter is created with the mode {@link ToolFactory#M_FORMAT_NEW}.
+ * @see #TRUE
+ * @see #FALSE
+ * @see ToolFactory#createCodeFormatter(Map, int)
+ * @since 3.6
+ */
+
+For example, the following snippet:
+
+public class X01 {
+// int a = 1;
+// int b = 2;
+}
+
+will be untouched by the formatter if both options are activated.
+See bug 251133 for more details.
+
Problem Reports Fixed
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.105
diff -u -r1.105 DefaultCodeFormatterConstants.java
--- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 23 Feb 2010 15:04:49 -0000 1.105
+++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 1 Mar 2010 16:44:02 -0000
@@ -652,6 +652,20 @@
* @since 3.3
*/
public final static String FORMATTER_COMMENT_FORMAT_LINE_COMMENT = "org.eclipse.jdt.core.formatter.comment.format_line_comments"; //$NON-NLS-1$
+ /**
+ *
+ * FORMATTER / Option to format line comments that start on the first column
+ * - option id: "org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column"
+ * - possible values: { TRUE, FALSE }
+ * - default: TRUE
+ *
+ * Note that this option is ignored if the formatter is created with the mode {@link ToolFactory#M_FORMAT_NEW}.
+ * @see #TRUE
+ * @see #FALSE
+ * @see ToolFactory#createCodeFormatter(Map, int)
+ * @since 3.6
+ */
+ public static final String FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN = JavaCore.PLUGIN_ID + ".formatter.format_line_comment_starting_on_first_column"; //$NON-NLS-1$
/**
*
@@ -3157,7 +3171,12 @@
* - possible values: { TRUE, FALSE }
* - default: FALSE
*
- * Note that this option is ignored if the formatter is created with the mode {@link ToolFactory#M_FORMAT_NEW}.
+ * Note that:
+ *
+ * - this option is ignored if the formatter is created with the mode {@link ToolFactory#M_FORMAT_NEW}
+ * - even with this option activated, the formatter still can ignore line comments starting at first column
+ * if the option {@link #FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN} is set to {@value #FALSE}
+ *
* @see #TRUE
* @see #FALSE
* @see ToolFactory#createCodeFormatter(Map, int)
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.101
diff -u -r1.101 DefaultCodeFormatterOptions.java
--- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 23 Feb 2010 15:04:52 -0000 1.101
+++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 1 Mar 2010 16:44:03 -0000
@@ -105,6 +105,7 @@
public boolean comment_new_lines_at_javadoc_boundaries;
public boolean comment_format_javadoc_comment;
public boolean comment_format_line_comment;
+ public boolean comment_format_line_comment_starting_on_first_column;
public boolean comment_format_block_comment;
public boolean comment_format_header;
public boolean comment_format_html;
@@ -375,11 +376,12 @@
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, this.comment_clear_blank_lines_in_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEW_LINES_AT_BLOCK_BOUNDARIES, this.comment_new_lines_at_block_boundaries ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEW_LINES_AT_JAVADOC_BOUNDARIES, this.comment_new_lines_at_javadoc_boundaries ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
- options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, this.comment_format_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
- options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, this.comment_format_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT, this.comment_format_block_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER, this.comment_format_header ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HTML, this.comment_format_html ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, this.comment_format_javadoc_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, this.comment_format_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
+ options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN, this.comment_format_line_comment_starting_on_first_column ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_SOURCE, this.comment_format_source ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_PARAMETER_DESCRIPTION, this.comment_indent_parameter_description ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_INDENT_ROOT_TAGS, this.comment_indent_root_tags ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
@@ -1079,6 +1081,10 @@
if (commentFormatLineCommentOption != null) {
this.comment_format_line_comment = DefaultCodeFormatterConstants.TRUE.equals(commentFormatLineCommentOption);
}
+ final Object formatLineCommentStartingOnFirstColumnOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN);
+ if (formatLineCommentStartingOnFirstColumnOption != null) {
+ this.comment_format_line_comment_starting_on_first_column = DefaultCodeFormatterConstants.TRUE.equals(formatLineCommentStartingOnFirstColumnOption);
+ }
final Object commentFormatHeaderOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER);
if (commentFormatHeaderOption != null) {
this.comment_format_header = DefaultCodeFormatterConstants.TRUE.equals(commentFormatHeaderOption);
@@ -2030,6 +2036,7 @@
this.comment_format_block_comment = true;
this.comment_format_javadoc_comment = true;
this.comment_format_line_comment = true;
+ this.comment_format_line_comment_starting_on_first_column = true;
this.comment_format_header = false;
this.comment_format_html = true;
this.comment_format_source = true;
@@ -2300,6 +2307,7 @@
this.comment_format_block_comment = true;
this.comment_format_javadoc_comment = true;
this.comment_format_line_comment = true;
+ this.comment_format_line_comment_starting_on_first_column = true;
this.comment_format_header = false;
this.comment_format_html = true;
this.comment_format_source = true;
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.194
diff -u -r1.194 Scribe.java
--- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 23 Feb 2010 11:35:53 -0000 1.194
+++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 1 Mar 2010 16:44:04 -0000
@@ -2406,11 +2406,14 @@
// Print comment line indentation
int commentIndentationLevel;
+ boolean onFirstColumn = isOnFirstColumn(start);
if (this.indentationLevel == 0) {
commentIndentationLevel = this.column - 1;
} else {
- if (this.formatter.preferences.never_indent_line_comments_on_first_column &&
- isOnFirstColumn(start)) {
+ if (onFirstColumn &&
+ (!this.formatter.preferences.comment_format_line_comment_starting_on_first_column ||
+ this.formatter.preferences.never_indent_line_comments_on_first_column)
+ ) {
commentIndentationLevel = this.column - 1;
} else {
// Indentation may be specific for contiguous comment
@@ -2469,7 +2472,7 @@
this.pendingSpace = false;
int previousStart = currentTokenStartPosition;
- if (!isNlsTag && includesLineComments) {
+ if (!isNlsTag && includesLineComments && (!onFirstColumn || this.formatter.preferences.comment_format_line_comment_starting_on_first_column)) {
printLineComment(currentTokenStartPosition, currentTokenEndPosition-1);
} else {
// do nothing!?
Index: model/org/eclipse/jdt/core/ToolFactory.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/ToolFactory.java,v
retrieving revision 1.79
diff -u -r1.79 ToolFactory.java
--- model/org/eclipse/jdt/core/ToolFactory.java 27 Jun 2008 16:04:01 -0000 1.79
+++ model/org/eclipse/jdt/core/ToolFactory.java 1 Mar 2010 16:44:04 -0000
@@ -162,6 +162,8 @@
if (options == null) options = JavaCore.getOptions();
Map currentOptions = new HashMap(options);
if (mode == M_FORMAT_NEW) {
+ // disable the option for not formatting comments starting on first column
+ currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.TRUE);
// disable the option for not indenting comments starting on first column
currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
#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.55
diff -u -r1.55 FormatterCommentsBugsTest.java
--- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 23 Feb 2010 11:35:45 -0000 1.55
+++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 1 Mar 2010 16:44:06 -0000
@@ -3621,6 +3621,58 @@
}
/**
+ * @bug 251133: [formatter] Automatic formatting single line comments is incoherent among tools
+ * @test Test the new formatter capability to completely ignore line comments starting at first column
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=251133"
+ */
+public void testBug251133_Line01() throws JavaModelException {
+ String source =
+ "public class X01 {\n" +
+ "// int a = 1;\n" +
+ "// int b = 2;\n" +
+ "}";
+ formatSource(source,
+ "public class X01 {\n" +
+ " // int a = 1;\n" +
+ " // int b = 2;\n" +
+ "}"
+ );
+}
+public void testBug251133_Line02() throws JavaModelException {
+ this.formatterPrefs.never_indent_line_comments_on_first_column = true;
+ String source =
+ "public class X01 {\n" +
+ "// int a = 1;\n" +
+ "// int b = 2;\n" +
+ "}";
+ formatSource(source,
+ "public class X01 {\n" +
+ "// int a = 1;\n" +
+ "// int b = 2;\n" +
+ "}"
+ );
+}
+public void testBug251133_Line03() throws JavaModelException {
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = false;
+ String source =
+ "public class X01 {\n" +
+ "// int a = 1;\n" +
+ "// int b = 2;\n" +
+ "}";
+ formatSource(source);
+}
+public void testBug251133_Line04() throws JavaModelException {
+ this.formatterPrefs.never_indent_line_comments_on_first_column = false;
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = false;
+ String source =
+ "public class X01 {\n" +
+ "// int a = 1;\n" +
+ "// int b = 2;\n" +
+ "}";
+ formatSource(source);
+}
+
+/**
* @bug 256799: [formatter] Formatter wrongly adds space to //$FALL-THROUGH$
* @test Ensure that the comment formatter preserve $FALL-THROUGH$ tag leading spaces
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=256799"