Lines 13-26
Link Here
|
13 |
import java.io.File; |
13 |
import java.io.File; |
14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
15 |
import java.io.InputStream; |
15 |
import java.io.InputStream; |
|
|
16 |
import java.util.HashMap; |
16 |
import java.util.Map; |
17 |
import java.util.Map; |
17 |
import java.util.zip.ZipEntry; |
18 |
import java.util.zip.ZipEntry; |
18 |
import java.util.zip.ZipFile; |
19 |
import java.util.zip.ZipFile; |
19 |
|
20 |
|
20 |
import org.eclipse.core.resources.IFile; |
21 |
import org.eclipse.core.resources.IFile; |
21 |
import org.eclipse.core.runtime.*; |
22 |
import org.eclipse.core.runtime.CoreException; |
|
|
23 |
import org.eclipse.core.runtime.IConfigurationElement; |
24 |
import org.eclipse.core.runtime.IExtension; |
25 |
import org.eclipse.core.runtime.IExtensionPoint; |
26 |
import org.eclipse.core.runtime.Plugin; |
22 |
import org.eclipse.jdt.core.compiler.IScanner; |
27 |
import org.eclipse.jdt.core.compiler.IScanner; |
23 |
import org.eclipse.jdt.core.formatter.CodeFormatter; |
28 |
import org.eclipse.jdt.core.formatter.CodeFormatter; |
|
|
29 |
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
24 |
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; |
30 |
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; |
25 |
import org.eclipse.jdt.core.util.ClassFormatException; |
31 |
import org.eclipse.jdt.core.util.ClassFormatException; |
26 |
import org.eclipse.jdt.core.util.IClassFileReader; |
32 |
import org.eclipse.jdt.core.util.IClassFileReader; |
Lines 45-52
Link Here
|
45 |
* @since 2.0 |
51 |
* @since 2.0 |
46 |
*/ |
52 |
*/ |
47 |
public class ToolFactory { |
53 |
public class ToolFactory { |
|
|
54 |
/** |
55 |
* If set, this mode tells the default code formatter to honor the options that never indent comments on |
56 |
* first column. Note that if these options are disabled, then they remain disabled even if this mode is set. |
57 |
* If this mode is not set, these options are ignored, even if they are enabled. |
58 |
* <p>See also {@link #M_FORMAT_NEW} and {@link #M_REFORMAT} that combine all flags that are typically used for formatting |
59 |
* new or existing source</p> |
60 |
* |
61 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN |
62 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN |
63 |
* @see #createCodeFormatter(Map, int) |
64 |
* @since 3.3 |
65 |
*/ |
66 |
public static int M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS = 0x01; |
48 |
|
67 |
|
49 |
/** |
68 |
/** |
|
|
69 |
* This constant combines all modes to be used for formatting new code. In particular, options that preserve the indentation |
70 |
* of comments are not used. Clients that are formatting new code are recommended to use this flag over the specific ones. |
71 |
* |
72 |
* @see #M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS |
73 |
* @see #createCodeFormatter(Map, int) |
74 |
* @since 3.3 |
75 |
*/ |
76 |
public static int M_FORMAT_NEW= new Integer(0).intValue(); |
77 |
|
78 |
|
79 |
/** |
80 |
* This constant combines all modes to be used for (re-) formatting existing code. In particular, options that preserve the indentation |
81 |
* of comments are used. Clients that are (re-) formatting existing code are recommended to use this flag over the specific flags. |
82 |
* |
83 |
* @see #M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS |
84 |
* @see #createCodeFormatter(Map, int) |
85 |
* @since 3.3 |
86 |
*/ |
87 |
public static int M_REFORMAT = new Integer(M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS).intValue(); |
88 |
|
89 |
/** |
50 |
* Create an instance of a code formatter. A code formatter implementation can be contributed via the |
90 |
* Create an instance of a code formatter. A code formatter implementation can be contributed via the |
51 |
* extension point "org.eclipse.jdt.core.codeFormatter". If unable to find a registered extension, the factory |
91 |
* extension point "org.eclipse.jdt.core.codeFormatter". If unable to find a registered extension, the factory |
52 |
* will default to using the default code formatter. |
92 |
* will default to using the default code formatter. |
Lines 89-94
Link Here
|
89 |
* the compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform |
129 |
* the compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform |
90 |
* ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). |
130 |
* ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). |
91 |
* Without these options, it is not possible for the code formatter to know what kind of source it needs to format. |
131 |
* Without these options, it is not possible for the code formatter to know what kind of source it needs to format. |
|
|
132 |
* </p><p> |
133 |
* Note this is equivalent to <code>createCodeFormatter(options, M_FORMAT_NEW)</code>. Thus some code formatter options |
134 |
* may be ignored since the corresponding mode is not set. |
92 |
* </p> |
135 |
* </p> |
93 |
* @param options - the options map to use for formatting with the default code formatter. Recognized options |
136 |
* @param options - the options map to use for formatting with the default code formatter. Recognized options |
94 |
* are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use |
137 |
* are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use |
Lines 99-106
Link Here
|
99 |
* @since 3.0 |
142 |
* @since 3.0 |
100 |
*/ |
143 |
*/ |
101 |
public static CodeFormatter createCodeFormatter(Map options){ |
144 |
public static CodeFormatter createCodeFormatter(Map options){ |
|
|
145 |
return createCodeFormatter(options, 0); |
146 |
} |
147 |
|
148 |
/** |
149 |
* Create an instance of the built-in code formatter. |
150 |
* <p>The given options should at least provide the source level ({@link JavaCore#COMPILER_SOURCE}), |
151 |
* the compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform |
152 |
* ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). |
153 |
* Without these options, it is not possible for the code formatter to know what kind of source it needs to format. |
154 |
* </p> |
155 |
* <p>The given mode is a bitwise value. It is used to determine what options should be enabled when |
156 |
* formatting the code.</p> |
157 |
* <p>The list of bits used to set the mode includes {@link #M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS}, but |
158 |
* other bits are left for future use. {@link #M_FORMAT_NEW} and {@link #M_REFORMAT} combine the flags to be used when formatting |
159 |
* new or when formatting existing code.</p> |
160 |
* |
161 |
* @param options the options map to use for formatting with the default code formatter. Recognized options |
162 |
* are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use |
163 |
* the current settings from <code>JavaCore#getOptions</code>. |
164 |
* @param mode the given mode to modify the given options. |
165 |
* |
166 |
* @return an instance of the built-in code formatter |
167 |
* @see CodeFormatter |
168 |
* @see JavaCore#getOptions() |
169 |
* @since 3.3 |
170 |
*/ |
171 |
public static CodeFormatter createCodeFormatter(Map options, int mode) { |
102 |
if (options == null) options = JavaCore.getOptions(); |
172 |
if (options == null) options = JavaCore.getOptions(); |
103 |
return new DefaultCodeFormatter(options); |
173 |
Map currentOptions = new HashMap(options); |
|
|
174 |
if ((mode & M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS) == 0) { |
175 |
// disable the option for not indenting comments starting on first column |
176 |
currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE); |
177 |
currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE); |
178 |
} |
179 |
return new DefaultCodeFormatter(currentOptions); |
104 |
} |
180 |
} |
105 |
|
181 |
|
106 |
/** |
182 |
/** |