Lines 13-18
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; |
Lines 21-26
Link Here
|
21 |
import org.eclipse.core.runtime.*; |
22 |
import org.eclipse.core.runtime.*; |
22 |
import org.eclipse.jdt.core.compiler.IScanner; |
23 |
import org.eclipse.jdt.core.compiler.IScanner; |
23 |
import org.eclipse.jdt.core.formatter.CodeFormatter; |
24 |
import org.eclipse.jdt.core.formatter.CodeFormatter; |
|
|
25 |
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
24 |
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; |
26 |
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; |
25 |
import org.eclipse.jdt.core.util.ClassFormatException; |
27 |
import org.eclipse.jdt.core.util.ClassFormatException; |
26 |
import org.eclipse.jdt.core.util.IClassFileReader; |
28 |
import org.eclipse.jdt.core.util.IClassFileReader; |
Lines 45-50
Link Here
|
45 |
* @since 2.0 |
47 |
* @since 2.0 |
46 |
*/ |
48 |
*/ |
47 |
public class ToolFactory { |
49 |
public class ToolFactory { |
|
|
50 |
|
51 |
/** |
52 |
* If set, this mode tells the default code formatter to honor the options that |
53 |
* never indent comments on first column. Note that if these options are disabled, |
54 |
* then they remain disabled even if this mode is set. |
55 |
* If this mode is not set, these options are ignored, even if they are enabled. |
56 |
* |
57 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN |
58 |
* @see DefaultCodeFormatterConstants#FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN |
59 |
* @see #createCodeFormatter(Map, int) |
60 |
* @since 3.3 |
61 |
*/ |
62 |
public static final int M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS = 0x01; |
48 |
|
63 |
|
49 |
/** |
64 |
/** |
50 |
* Create an instance of a code formatter. A code formatter implementation can be contributed via the |
65 |
* Create an instance of a code formatter. A code formatter implementation can be contributed via the |
Lines 89-94
Link Here
|
89 |
* the compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform |
104 |
* the compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform |
90 |
* ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). |
105 |
* ({@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. |
106 |
* Without these options, it is not possible for the code formatter to know what kind of source it needs to format. |
|
|
107 |
* </p><p> |
108 |
* Note this is equivalent to <code>createCodeFormatter(options, 0)</code>. Thus some code formatter options |
109 |
* may be ignored since the corresponding mode is not set. |
92 |
* </p> |
110 |
* </p> |
93 |
* @param options - the options map to use for formatting with the default code formatter. Recognized options |
111 |
* @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 |
112 |
* are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use |
Lines 99-106
Link Here
|
99 |
* @since 3.0 |
117 |
* @since 3.0 |
100 |
*/ |
118 |
*/ |
101 |
public static CodeFormatter createCodeFormatter(Map options){ |
119 |
public static CodeFormatter createCodeFormatter(Map options){ |
|
|
120 |
return createCodeFormatter(options, 0); |
121 |
} |
122 |
|
123 |
/** |
124 |
* Create an instance of the built-in code formatter. |
125 |
* <p>The given options should at least provide the source level ({@link JavaCore#COMPILER_SOURCE}), |
126 |
* the compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform |
127 |
* ({@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. |
129 |
* </p> |
130 |
* <p>The given mode is a bitwise value. It is used to determine what options should be enabled when |
131 |
* formatting the code.</p> |
132 |
* <p>The list of bits used to set the mode includes only {@link #M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS}, but |
133 |
* other bits are left for future use.</p> |
134 |
* |
135 |
* @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 |
137 |
* the current settings from <code>JavaCore#getOptions</code>. |
138 |
* @param mode the given mode to modify the given options. |
139 |
* |
140 |
* @return an instance of the built-in code formatter |
141 |
* @see CodeFormatter |
142 |
* @see JavaCore#getOptions() |
143 |
* @since 3.3 |
144 |
*/ |
145 |
public static CodeFormatter createCodeFormatter(Map options, int mode) { |
102 |
if (options == null) options = JavaCore.getOptions(); |
146 |
if (options == null) options = JavaCore.getOptions(); |
103 |
return new DefaultCodeFormatter(options); |
147 |
Map currentOptions = new HashMap(options); |
|
|
148 |
if ((mode & M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS) == 0) { |
149 |
// 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); |
151 |
currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE); |
152 |
} |
153 |
return new DefaultCodeFormatter(currentOptions); |
104 |
} |
154 |
} |
105 |
|
155 |
|
106 |
/** |
156 |
/** |