### 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.81 diff -u -r1.81 DefaultCodeFormatterConstants.java --- formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 23 Apr 2007 23:45:48 -0000 1.81 +++ formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java 22 May 2007 17:23:05 -0000 @@ -13,6 +13,7 @@ import java.util.Map; import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.ToolFactory; import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions; import org.eclipse.jdt.internal.formatter.align.Alignment; @@ -3035,10 +3036,13 @@ * FORMATTER / Option to indent block comments that start on the first column * - option id: "org.eclipse.jdt.core.formatter.formatter.never_indent_block_comments_on_first_column" * - possible values: { TRUE, FALSE } - * - default: TRUE + * - default: FALSE * + * Note that if the formatter is created without {@link ToolFactory#M_FORMAT_USE_EXISTING_COMMENT_POSITIONS} set, + * this option is ignored. * @see #TRUE * @see #FALSE + * @see ToolFactory#createCodeFormatter(Map, int) * @since 3.3 */ public static final String FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN = JavaCore.PLUGIN_ID + ".formatter.never_indent_block_comments_on_first_column"; //$NON-NLS-1$ @@ -3047,10 +3051,13 @@ * FORMATTER / Option to indent line comments that start on the first column * - option id: "org.eclipse.jdt.core.formatter.formatter.never_indent_line_comments_on_first_column" * - possible values: { TRUE, FALSE } - * - default: TRUE + * - default: FALSE * + * Note that if the formatter is created without {@link ToolFactory#M_FORMAT_USE_EXISTING_COMMENT_POSITIONS} set, + * this option is ignored. * @see #TRUE * @see #FALSE + * @see ToolFactory#createCodeFormatter(Map, int) * @since 3.3 */ public static final String FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN = JavaCore.PLUGIN_ID + ".formatter.never_indent_line_comments_on_first_column"; //$NON-NLS-1$ Index: formatter/org/eclipse/jdt/core/formatter/CodeFormatterApplication.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/core/formatter/CodeFormatterApplication.java,v retrieving revision 1.9 diff -u -r1.9 CodeFormatterApplication.java --- formatter/org/eclipse/jdt/core/formatter/CodeFormatterApplication.java 10 May 2007 16:10:34 -0000 1.9 +++ formatter/org/eclipse/jdt/core/formatter/CodeFormatterApplication.java 22 May 2007 17:23:05 -0000 @@ -27,7 +27,6 @@ import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; -import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.ToolFactory; import org.eclipse.jdt.internal.core.util.Util; import org.eclipse.jface.text.BadLocationException; @@ -376,30 +375,6 @@ System.out.println(Messages.bind(Messages.CommandLineStart)); } - // preserve existing default behavior - // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=20793 - if (this.options == null) { - this.options = JavaCore.getOptions(); - this.options.put( - DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, - DefaultCodeFormatterConstants.FALSE); - this.options.put( - DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, - DefaultCodeFormatterConstants.FALSE); - } else { - Object option = this.options.get(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN); - if (option == null) { - this.options.put( - DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, - DefaultCodeFormatterConstants.FALSE); - } - option = this.options.get(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN); - if (option == null) { - this.options.put( - DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, - DefaultCodeFormatterConstants.FALSE); - } - } final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(this.options); // format the list of files and/or directories for (int i = 0, max = filesToFormat.length; i < max; i++) { 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.72 diff -u -r1.72 ToolFactory.java --- model/org/eclipse/jdt/core/ToolFactory.java 29 Sep 2006 17:13:57 -0000 1.72 +++ model/org/eclipse/jdt/core/ToolFactory.java 22 May 2007 17:23:06 -0000 @@ -13,6 +13,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -21,6 +22,7 @@ import org.eclipse.core.runtime.*; import org.eclipse.jdt.core.compiler.IScanner; import org.eclipse.jdt.core.formatter.CodeFormatter; +import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; import org.eclipse.jdt.core.util.ClassFormatException; import org.eclipse.jdt.core.util.IClassFileReader; @@ -45,6 +47,18 @@ * @since 2.0 */ public class ToolFactory { + + /** + * If set, this mode tells the default code formatter to use the existing comment positions + * in order to format the code. If not set, the options that format the code keeping existing + * comment positions are ignored. + * + * @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN + * @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN + * @see #createCodeFormatter(Map, int) + * @since 3.3 + */ + public static int M_FORMAT_USE_EXISTING_COMMENT_POSITIONS = 0x01; /** * Create an instance of a code formatter. A code formatter implementation can be contributed via the @@ -89,6 +103,9 @@ * the compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform * ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). * Without these options, it is not possible for the code formatter to know what kind of source it needs to format. + *
+ * Note this is equivalent to createCodeFormatter(options, 0)
. Thus some code formatter options
+ * may be ignored since the corresponding mode is not set.
*
JavaCore#getDefaultOptions()
. If set to null
, then use
@@ -99,8 +116,40 @@
* @since 3.0
*/
public static CodeFormatter createCodeFormatter(Map options){
+ return createCodeFormatter(options, 0);
+ }
+
+ /**
+ * Create an instance of the built-in code formatter.
+ * The given options should at least provide the source level ({@link JavaCore#COMPILER_SOURCE}), + * the compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform + * ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). + * Without these options, it is not possible for the code formatter to know what kind of source it needs to format. + *
+ *The given mode is a bitwise value. It is used to determine what options should be enabled when + * formatting the code.
+ *The list of bits used to set the mode includes only {@link #M_FORMAT_USE_EXISTING_COMMENT_POSITIONS}, but + * other bits are left for future use.
+ * + * @param options the options map to use for formatting with the default code formatter. Recognized options + * are documented onJavaCore#getDefaultOptions()
. If set to null
, then use
+ * the current settings from JavaCore#getOptions
.
+ * @param mode the given mode to modify the given options.
+ *
+ * @return an instance of the built-in code formatter
+ * @see CodeFormatter
+ * @see JavaCore#getOptions()
+ * @since 3.3
+ */
+ public static CodeFormatter createCodeFormatter(Map options, int mode) {
if (options == null) options = JavaCore.getOptions();
- return new DefaultCodeFormatter(options);
+ Map currentOptions = new HashMap(options);
+ if ((mode & M_FORMAT_USE_EXISTING_COMMENT_POSITIONS) == 0) {
+ // 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);
+ }
+ return new DefaultCodeFormatter(currentOptions);
}
/**
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.84
diff -u -r1.84 DefaultCodeFormatterOptions.java
--- formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 23 Apr 2007 23:46:45 -0000 1.84
+++ formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java 22 May 2007 17:23:06 -0000
@@ -2172,8 +2172,6 @@
setJavaConventionsSettings();
this.tab_char = TAB;
this.tab_size = 4;
- this.never_indent_block_comments_on_first_column = true;
- this.never_indent_line_comments_on_first_column = true;
}
public void setJavaConventionsSettings() {