Lines 49-65
Link Here
|
49 |
public class ToolFactory { |
49 |
public class ToolFactory { |
50 |
|
50 |
|
51 |
/** |
51 |
/** |
52 |
* If set, this mode tells the default code formatter to honor the options that |
52 |
* This mode is used for formatting new code when some formatter options should not be used. |
53 |
* never indent comments on first column. Note that if these options are disabled, |
53 |
* In particular, options that preserve the indentation of comments are not used. |
54 |
* then they remain disabled even if this mode is set. |
54 |
* In the future, newly added options may be ignored as well. |
55 |
* If this mode is not set, these options are ignored, even if they are enabled. |
55 |
* <p>Clients that are formatting new code are recommended to use this mode. |
|
|
56 |
* </p> |
57 |
* |
58 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN |
59 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN |
60 |
* @see #createCodeFormatter(Map, int) |
61 |
* @since 3.3 |
62 |
*/ |
63 |
public static final int M_FORMAT_NEW= new Integer(0).intValue(); |
64 |
|
65 |
/** |
66 |
* This mode is used for formatting existing code when all formatter options should be used. |
67 |
* In particular, options that preserve the indentation of comments are used. |
68 |
* <p>Clients that are formatting existing code are recommended to use this mode. |
69 |
* </p> |
56 |
* |
70 |
* |
57 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN |
71 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN |
58 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN |
72 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN |
59 |
* @see #createCodeFormatter(Map, int) |
73 |
* @see #createCodeFormatter(Map, int) |
60 |
* @since 3.3 |
74 |
* @since 3.3 |
61 |
*/ |
75 |
*/ |
62 |
public static final int M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS = 0x01; |
76 |
public static final int M_FORMAT_EXISTING = new Integer(1).intValue(); |
63 |
|
77 |
|
64 |
/** |
78 |
/** |
65 |
* Create an instance of a code formatter. A code formatter implementation can be contributed via the |
79 |
* Create an instance of a code formatter. A code formatter implementation can be contributed via the |
Lines 105-112
Link Here
|
105 |
* ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). |
119 |
* ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). |
106 |
* Without these options, it is not possible for the code formatter to know what kind of source it needs to format. |
120 |
* Without these options, it is not possible for the code formatter to know what kind of source it needs to format. |
107 |
* </p><p> |
121 |
* </p><p> |
108 |
* Note this is equivalent to <code>createCodeFormatter(options, 0)</code>. Thus some code formatter options |
122 |
* Note this is equivalent to <code>createCodeFormatter(options, M_FORMAT_NEW)</code>. Thus some code formatter options |
109 |
* may be ignored since the corresponding mode is not set. |
123 |
* may be ignored. See @{link {@link #M_FORMAT_NEW} for more details. |
110 |
* </p> |
124 |
* </p> |
111 |
* @param options - the options map to use for formatting with the default code formatter. Recognized options |
125 |
* @param options - the options map to use for formatting with the default code formatter. Recognized options |
112 |
* are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use |
126 |
* are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use |
Lines 117-123
Link Here
|
117 |
* @since 3.0 |
131 |
* @since 3.0 |
118 |
*/ |
132 |
*/ |
119 |
public static CodeFormatter createCodeFormatter(Map options){ |
133 |
public static CodeFormatter createCodeFormatter(Map options){ |
120 |
return createCodeFormatter(options, 0); |
134 |
return createCodeFormatter(options, M_FORMAT_NEW); |
121 |
} |
135 |
} |
122 |
|
136 |
|
123 |
/** |
137 |
/** |
Lines 127-136
Link Here
|
127 |
* ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). |
141 |
* ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). |
128 |
* Without these options, it is not possible for the code formatter to know what kind of source it needs to format. |
142 |
* Without these options, it is not possible for the code formatter to know what kind of source it needs to format. |
129 |
* </p> |
143 |
* </p> |
130 |
* <p>The given mode is a bitwise value. It is used to determine what options should be enabled when |
144 |
* <p>The given mode determine what options should be enabled when formatting the code. It can have the following |
131 |
* formatting the code.</p> |
145 |
* values: {@link #M_FORMAT_NEW}, {@link #M_FORMAT_EXISTING}, but other values may be added in the future. |
132 |
* <p>The list of bits used to set the mode includes only {@link #M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS}, but |
146 |
* </p> |
133 |
* other bits are left for future use.</p> |
|
|
134 |
* |
147 |
* |
135 |
* @param options the options map to use for formatting with the default code formatter. Recognized options |
148 |
* @param options the options map to use for formatting with the default code formatter. Recognized options |
136 |
* are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use |
149 |
* are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use |
Lines 145-151
Link Here
|
145 |
public static CodeFormatter createCodeFormatter(Map options, int mode) { |
158 |
public static CodeFormatter createCodeFormatter(Map options, int mode) { |
146 |
if (options == null) options = JavaCore.getOptions(); |
159 |
if (options == null) options = JavaCore.getOptions(); |
147 |
Map currentOptions = new HashMap(options); |
160 |
Map currentOptions = new HashMap(options); |
148 |
if ((mode & M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS) == 0) { |
161 |
if (mode == M_FORMAT_NEW) { |
149 |
// disable the option for not indenting comments starting on first column |
162 |
// disable the option for not indenting comments starting on first column |
150 |
currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE); |
163 |
currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE); |
151 |
currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE); |
164 |
currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE); |