### 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.7442 diff -u -r1.7442 buildnotes_jdt-core.html --- buildnotes_jdt-core.html 4 May 2010 19:15:29 -0000 1.7442 +++ buildnotes_jdt-core.html 6 May 2010 09:22:59 -0000 @@ -48,6 +48,25 @@
Project org.eclipse.jdt.core v_A50 (cvs).

What's new in this drop

+

Problem Reports Fixed

302295 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.110 diff -u -r1.110 DefaultCodeFormatterConstants.java --- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 4 Mar 2010 16:48:50 -0000 1.110 +++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 6 May 2010 09:23:01 -0000 @@ -860,15 +860,29 @@ public static final String FORMATTER_CONTINUATION_INDENTATION_FOR_ARRAY_INITIALIZER = JavaCore.PLUGIN_ID + ".formatter.continuation_indentation_for_array_initializer"; //$NON-NLS-1$ /** *
+	 * FORMATTER / Option to use the disabling and enabling tags defined respectively by the {@link #FORMATTER_DISABLING_TAG} and the {@link #FORMATTER_ENABLING_TAG} options.
+	 *     - option id:         "org.eclipse.jdt.core.formatter.use_on_off_tags"
+	 *     - possible values:   TRUE / FALSE
+	 *     - default:           FALSE
+	 * 
+ * @since 3.6 + */ + public static final String FORMATTER_USE_ON_OFF_TAGS = JavaCore.PLUGIN_ID + ".formatter.use_on_off_tags"; //$NON-NLS-1$ + /** + *
 	 * FORMATTER / Option to define the tag to put in a comment to disable the formatting.
-	 * See the {@link #FORMATTER_ENABLING_TAG} option to re-enable it.
+	 *     - option id:         "org.eclipse.jdt.core.formatter.disabling_tag"
 	 *     - possible values:   String, with constraints mentioned below
 	 *     - default:           ""
+	 * 
+	 * See the {@link #FORMATTER_ENABLING_TAG} option to re-enable it.
 	 * 
* *

* Note that: *

    + *
  1. This tag is used by the formatter only if the + * {@link #FORMATTER_USE_ON_OFF_TAGS} option is set to {@link #TRUE}.
  2. *
  3. The tag name will be trimmed. Hence if it does contain white spaces * at the beginning or at the end, they will not be taken into account while * searching for the tag in the comments
  4. @@ -945,8 +959,7 @@ public static final String FORMATTER_DISABLING_TAG = JavaCore.PLUGIN_ID + ".formatter.disabling_tag"; //$NON-NLS-1$ /** *
    -	 * FORMATTER / Option to define the tag to put in a comment to re-enable the
    -	 * formatting after it has been disabled (see {@link #FORMATTER_DISABLING_TAG})
    +	 * FORMATTER / Option to define the tag to put in a comment to re-enable the formatting after it has been disabled (see {@link #FORMATTER_DISABLING_TAG})
     	 *     - option id:         "org.eclipse.jdt.core.formatter.enabling_tag"
     	 *     - possible values:   String, with constraints mentioned below
     	 *     - default:           ""
    @@ -955,6 +968,8 @@
     	 * 

    * Note that: *

      + *
    1. This tag is used by the formatter only if the + * {@link #FORMATTER_USE_ON_OFF_TAGS} option is set to {@link #TRUE}.
    2. *
    3. The tag name will be trimmed. Hence if it does contain white spaces * at the beginning or at the end, they will not be taken into account while * searching for the tag in the comments
    4. 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.105 diff -u -r1.105 DefaultCodeFormatterOptions.java --- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 3 Mar 2010 11:16:59 -0000 1.105 +++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 6 May 2010 09:23:03 -0000 @@ -117,6 +117,7 @@ public boolean comment_insert_new_line_for_parameter; public int comment_line_length; + public boolean use_tags; public char[] disabling_tag; public char[] enabling_tag; @@ -618,6 +619,7 @@ options.put(DefaultCodeFormatterConstants.FORMATTER_WRAP_BEFORE_BINARY_OPERATOR, this.wrap_before_binary_operator ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, this.disabling_tag == null ? Util.EMPTY_STRING : new String(this.disabling_tag)); options.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, this.enabling_tag == null ? Util.EMPTY_STRING : new String(this.enabling_tag)); + options.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, this.use_tags ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); return options; } @@ -1955,6 +1957,10 @@ if (wrapBeforeBinaryOperatorOption != null) { this.wrap_before_binary_operator = DefaultCodeFormatterConstants.TRUE.equals(wrapBeforeBinaryOperatorOption); } + final Object useTags = settings.get(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS); + if (useTags != null) { + this.use_tags = DefaultCodeFormatterConstants.TRUE.equals(useTags); + } final Object disableTagOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG); if (disableTagOption != null) { if (disableTagOption instanceof String) { @@ -2299,6 +2305,7 @@ 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.use_tags = false; } public void setEclipseDefaultSettings() { @@ -2570,5 +2577,6 @@ this.tab_char = MIXED; this.use_tabs_only_for_leading_indentations = false; this.wrap_before_binary_operator = true; + this.use_tags = false; } } 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.207 diff -u -r1.207 Scribe.java --- formatter/org/eclipse/jdt/internal/formatter/Scribe.java 4 May 2010 08:45:55 -0000 1.207 +++ formatter/org/eclipse/jdt/internal/formatter/Scribe.java 6 May 2010 09:23:05 -0000 @@ -106,7 +106,8 @@ int blank_lines_between_import_groups = -1; /** disabling */ - boolean editsEnabled = true; + boolean editsEnabled; + boolean useTags; /* Comments formatting */ private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT; @@ -1382,21 +1383,23 @@ } private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) { - this.disablingTag = preferences.disabling_tag; - this.enablingTag = preferences.enabling_tag; - char[][] taskTags; - if (this.disablingTag == null) { - if (this.enablingTag == null) { - taskTags = null; + this.useTags = preferences.use_tags; + char[][] taskTags = null; + if (this.useTags) { + this.disablingTag = preferences.disabling_tag; + this.enablingTag = preferences.enabling_tag; + if (this.disablingTag == null) { + if (this.enablingTag != null) { + taskTags = new char[][] { this.enablingTag }; + } + } else if (this.enablingTag == null) { + taskTags = new char[][] { this.disablingTag }; } else { - taskTags = new char[][] { this.enablingTag }; + taskTags = new char[][] { this.disablingTag, this.enablingTag }; } - } else if (this.enablingTag == null) { - taskTags = new char[][] { this.disablingTag }; - } else { - taskTags = new char[][] { this.disablingTag, this.enablingTag }; } this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, taskTags, null/*taskPriorities*/, true/*taskCaseSensitive*/); + this.editsEnabled = true; } private void initFormatterCommentParser() { @@ -2453,7 +2456,7 @@ currentTokenStartPosition = this.scanner.currentPosition; break; case TerminalTokens.TokenNameCOMMENT_LINE : - if (this.editsEnabled && foundTaskCount > previousFoundTaskCount) { + if (this.useTags && this.editsEnabled && foundTaskCount > previousFoundTaskCount) { setEditsEnabled(foundTaskCount, previousFoundTaskCount); if (!this.editsEnabled && this.editsIndex > 1) { OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; @@ -2478,12 +2481,12 @@ currentTokenStartPosition = this.scanner.currentPosition; hasLineComment = true; lines = 0; - if (!this.editsEnabled && foundTaskCount > previousFoundTaskCount) { + if (this.useTags && !this.editsEnabled && foundTaskCount > previousFoundTaskCount) { setEditsEnabled(foundTaskCount, previousFoundTaskCount); } break; case TerminalTokens.TokenNameCOMMENT_BLOCK : - if (this.editsEnabled && foundTaskCount > previousFoundTaskCount) { + if (this.useTags && this.editsEnabled && foundTaskCount > previousFoundTaskCount) { setEditsEnabled(foundTaskCount, previousFoundTaskCount); if (!this.editsEnabled && this.editsIndex > 1) { OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; @@ -2515,12 +2518,12 @@ hasLineComment = false; hasComment = true; lines = 0; - if (!this.editsEnabled && foundTaskCount > previousFoundTaskCount) { + if (this.useTags && !this.editsEnabled && foundTaskCount > previousFoundTaskCount) { setEditsEnabled(foundTaskCount, previousFoundTaskCount); } break; case TerminalTokens.TokenNameCOMMENT_JAVADOC : - if (this.editsEnabled && foundTaskCount > previousFoundTaskCount) { + if (this.useTags && this.editsEnabled && foundTaskCount > previousFoundTaskCount) { setEditsEnabled(foundTaskCount, previousFoundTaskCount); if (!this.editsEnabled && this.editsIndex > 1) { OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; @@ -2552,7 +2555,7 @@ } else { printBlockComment(true); } - if (!this.editsEnabled && foundTaskCount > previousFoundTaskCount) { + if (this.useTags && !this.editsEnabled && foundTaskCount > previousFoundTaskCount) { setEditsEnabled(foundTaskCount, previousFoundTaskCount); } printNewLine(); #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java,v retrieving revision 1.27 diff -u -r1.27 FormatterBugsTests.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 23 Apr 2010 10:04:33 -0000 1.27 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java 6 May 2010 09:23:09 -0000 @@ -101,6 +101,7 @@ ); } public void testBug027079a1() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -130,6 +131,7 @@ ); } public void testBug027079a2() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -159,6 +161,7 @@ ); } public void testBug027079a3() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -188,6 +191,7 @@ ); } public void testBug027079a4() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -218,6 +222,7 @@ ); } public void testBug027079b() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -256,6 +261,7 @@ ); } public void testBug027079c() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -305,6 +311,7 @@ ); } public void testBug027079c2() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -352,6 +359,7 @@ ); } public void testBug027079d() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -386,6 +394,7 @@ true/*repeat*/); } public void testBug027079d2() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -420,6 +429,7 @@ true/*repeat*/); } public void testBug027079d3() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -454,6 +464,7 @@ true/*repeat*/); } public void testBug027079d4() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); String source = @@ -488,6 +499,7 @@ true/*repeat*/); } public void testBug027079e() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "format: off".toCharArray(); this.formatterPrefs.enabling_tag = "format: on".toCharArray(); String source = @@ -517,6 +529,7 @@ ); } public void testBug027079f() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "format: off".toCharArray(); this.formatterPrefs.enabling_tag = "format: on".toCharArray(); String source = @@ -546,6 +559,7 @@ ); } public void testBug027079f2() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "format: off".toCharArray(); this.formatterPrefs.enabling_tag = "format: on".toCharArray(); String source = @@ -575,6 +589,7 @@ ); } public void testBug027079f3() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = " format: off ".toCharArray(); this.formatterPrefs.enabling_tag = " format: on ".toCharArray(); String source = @@ -604,6 +619,7 @@ ); } public void testBug027079f4() throws JavaModelException { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = " format: off ".toCharArray(); this.formatterPrefs.enabling_tag = " format: on ".toCharArray(); String source = @@ -5839,6 +5855,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304529" */ public void testBug304529() { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = "off".toCharArray(); this.formatterPrefs.enabling_tag = null; String source = @@ -5851,6 +5868,7 @@ formatSource(source); } public void testBug304529b() { + this.formatterPrefs.use_tags = true; this.formatterPrefs.disabling_tag = null; this.formatterPrefs.enabling_tag = "on".toCharArray(); String source = @@ -5871,6 +5889,7 @@ } public void testBug304529c() { this.formatterPrefs = null; + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE); this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "off"); this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, ""); String source = @@ -5884,6 +5903,7 @@ } public void testBug304529d() { this.formatterPrefs = null; + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE); this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, ""); this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "on"); String source = @@ -5904,6 +5924,7 @@ } public void testBug304529e() { this.formatterPrefs = null; + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE); this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "off"); this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "on"); String source = @@ -5986,4 +6007,60 @@ ); } +/** + * @bug 311582: [formatter] Master switch to enable/disable on/off tags + * @test Ensure that the formatter does not take care of formatting tags by default + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=311582" + */ +public void testBug0311582a() throws JavaModelException { + this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray(); + this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray(); + String source = + "public class X01 {\n" + + "\n" + + "/* disable-formatter */\n" + + "void foo( ) { \n" + + " // unformatted comment\n" + + "}\n" + + "/* enable-formatter */\n" + + "void bar( ) { \n" + + " // formatted comment\n" + + "}\n" + + "}\n"; + formatSource(source, + "public class X01 {\n" + + "\n" + + " /* disable-formatter */\n" + + " void foo() {\n" + + " // unformatted comment\n" + + " }\n" + + "\n" + + " /* enable-formatter */\n" + + " void bar() {\n" + + " // formatted comment\n" + + " }\n" + + "}\n" + ); +} +public void testBug0311582b() { + this.formatterPrefs = null; + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "off"); + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, ""); + String source = + "/* off */\n" + + "public class X01 {\n" + + "void foo( ) { \n" + + " // unformatted area\n" + + "}\n" + + "}\n"; + formatSource(source, + "/* off */\n" + + "public class X01 {\n" + + " void foo() {\n" + + " // unformatted area\n" + + " }\n" + + "}\n" + ); +} + } 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.64 diff -u -r1.64 FormatterCommentsBugsTest.java --- src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 25 Apr 2010 18:23:04 -0000 1.64 +++ src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java 6 May 2010 09:23:10 -0000 @@ -6262,6 +6262,7 @@ */ public void testBug305281() { this.formatterPrefs = null; + this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_USE_ON_OFF_TAGS, DefaultCodeFormatterConstants.TRUE); this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "format: OFF"); this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "format: ON"); String source =