author | briangoetz |
Wed, 18 Dec 2013 16:05:18 -0500 | |
changeset 22163 | 3651128c74eb |
parent 22153 | f9f06fcca59d |
child 23114 | 7fe55d6324d5 |
permissions | -rw-r--r-- |
11315 | 1 |
/* |
15043
4aae62f3b9a8
8006037: extra space in javac -help for -J and @ options
jjg
parents:
15031
diff
changeset
|
2 |
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. |
11315 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javac.main; |
|
27 |
||
14960 | 28 |
import java.io.File; |
29 |
import java.io.FileWriter; |
|
30 |
import java.io.PrintWriter; |
|
11315 | 31 |
import java.util.Collections; |
14960 | 32 |
import java.util.EnumSet; |
33 |
import java.util.LinkedHashMap; |
|
34 |
import java.util.Map; |
|
35 |
import java.util.Set; |
|
36 |
||
37 |
import javax.lang.model.SourceVersion; |
|
38 |
||
39 |
import com.sun.tools.doclint.DocLint; |
|
11315 | 40 |
import com.sun.tools.javac.code.Lint; |
41 |
import com.sun.tools.javac.code.Source; |
|
42 |
import com.sun.tools.javac.code.Type; |
|
15724 | 43 |
import com.sun.tools.javac.jvm.Profile; |
11315 | 44 |
import com.sun.tools.javac.jvm.Target; |
14960 | 45 |
import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
46 |
import com.sun.tools.javac.util.Log; |
|
47 |
import com.sun.tools.javac.util.Log.PrefixKind; |
|
48 |
import com.sun.tools.javac.util.Log.WriterKind; |
|
11315 | 49 |
import com.sun.tools.javac.util.Options; |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19670
diff
changeset
|
50 |
import com.sun.tools.javac.util.StringUtils; |
11315 | 51 |
import static com.sun.tools.javac.main.Option.ChoiceKind.*; |
14960 | 52 |
import static com.sun.tools.javac.main.Option.OptionGroup.*; |
11315 | 53 |
import static com.sun.tools.javac.main.Option.OptionKind.*; |
54 |
||
55 |
/** |
|
56 |
* Options for javac. The specific Option to handle a command-line option |
|
57 |
* is identified by searching the members of this enum in order, looking |
|
58 |
* the first {@link #matches match}. The action for an Option is performed |
|
59 |
* by calling {@link #process process}, and by providing a suitable |
|
60 |
* {@link OptionHelper} to provide access the compiler state. |
|
61 |
* |
|
62 |
* <p><b>This is NOT part of any supported API. |
|
63 |
* If you write code that depends on this, you do so at your own |
|
64 |
* risk. This code and its internal interfaces are subject to change |
|
65 |
* or deletion without notice.</b></p> |
|
66 |
*/ |
|
67 |
public enum Option { |
|
68 |
G("-g", "opt.g", STANDARD, BASIC), |
|
69 |
||
70 |
G_NONE("-g:none", "opt.g.none", STANDARD, BASIC) { |
|
71 |
@Override |
|
72 |
public boolean process(OptionHelper helper, String option) { |
|
73 |
helper.put("-g:", "none"); |
|
74 |
return false; |
|
75 |
} |
|
76 |
}, |
|
77 |
||
78 |
G_CUSTOM("-g:", "opt.g.lines.vars.source", |
|
79 |
STANDARD, BASIC, ANYOF, "lines", "vars", "source"), |
|
80 |
||
81 |
XLINT("-Xlint", "opt.Xlint", EXTENDED, BASIC), |
|
82 |
||
83 |
XLINT_CUSTOM("-Xlint:", "opt.Xlint.suboptlist", |
|
84 |
EXTENDED, BASIC, ANYOF, getXLintChoices()), |
|
85 |
||
14960 | 86 |
XDOCLINT("-Xdoclint", "opt.Xdoclint", EXTENDED, BASIC), |
87 |
||
88 |
XDOCLINT_CUSTOM("-Xdoclint:", "opt.Xdoclint.subopts", "opt.Xdoclint.custom", EXTENDED, BASIC) { |
|
89 |
@Override |
|
90 |
public boolean matches(String option) { |
|
91 |
return DocLint.isValidOption( |
|
92 |
option.replace(XDOCLINT_CUSTOM.text, DocLint.XMSGS_CUSTOM_PREFIX)); |
|
93 |
} |
|
94 |
||
95 |
@Override |
|
96 |
public boolean process(OptionHelper helper, String option) { |
|
97 |
String prev = helper.get(XDOCLINT_CUSTOM); |
|
98 |
String next = (prev == null) ? option : (prev + " " + option); |
|
99 |
helper.put(XDOCLINT_CUSTOM.text, next); |
|
100 |
return false; |
|
101 |
} |
|
102 |
}, |
|
103 |
||
11315 | 104 |
// -nowarn is retained for command-line backward compatibility |
105 |
NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC) { |
|
106 |
@Override |
|
107 |
public boolean process(OptionHelper helper, String option) { |
|
108 |
helper.put("-Xlint:none", option); |
|
109 |
return false; |
|
110 |
} |
|
111 |
}, |
|
112 |
||
113 |
VERBOSE("-verbose", "opt.verbose", STANDARD, BASIC), |
|
114 |
||
115 |
// -deprecation is retained for command-line backward compatibility |
|
116 |
DEPRECATION("-deprecation", "opt.deprecation", STANDARD, BASIC) { |
|
117 |
@Override |
|
118 |
public boolean process(OptionHelper helper, String option) { |
|
119 |
helper.put("-Xlint:deprecation", option); |
|
120 |
return false; |
|
121 |
} |
|
122 |
}, |
|
123 |
||
124 |
CLASSPATH("-classpath", "opt.arg.path", "opt.classpath", STANDARD, FILEMANAGER), |
|
125 |
||
126 |
CP("-cp", "opt.arg.path", "opt.classpath", STANDARD, FILEMANAGER) { |
|
127 |
@Override |
|
128 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
129 |
return super.process(helper, "-classpath", arg); |
|
130 |
} |
|
131 |
}, |
|
132 |
||
133 |
SOURCEPATH("-sourcepath", "opt.arg.path", "opt.sourcepath", STANDARD, FILEMANAGER), |
|
134 |
||
135 |
BOOTCLASSPATH("-bootclasspath", "opt.arg.path", "opt.bootclasspath", STANDARD, FILEMANAGER) { |
|
136 |
@Override |
|
137 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
138 |
helper.remove("-Xbootclasspath/p:"); |
|
139 |
helper.remove("-Xbootclasspath/a:"); |
|
140 |
return super.process(helper, option, arg); |
|
141 |
} |
|
142 |
}, |
|
143 |
||
144 |
XBOOTCLASSPATH_PREPEND("-Xbootclasspath/p:", "opt.arg.path", "opt.Xbootclasspath.p", EXTENDED, FILEMANAGER), |
|
145 |
||
146 |
XBOOTCLASSPATH_APPEND("-Xbootclasspath/a:", "opt.arg.path", "opt.Xbootclasspath.a", EXTENDED, FILEMANAGER), |
|
147 |
||
148 |
XBOOTCLASSPATH("-Xbootclasspath:", "opt.arg.path", "opt.bootclasspath", EXTENDED, FILEMANAGER) { |
|
149 |
@Override |
|
150 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
151 |
helper.remove("-Xbootclasspath/p:"); |
|
152 |
helper.remove("-Xbootclasspath/a:"); |
|
153 |
return super.process(helper, "-bootclasspath", arg); |
|
154 |
} |
|
155 |
}, |
|
156 |
||
157 |
EXTDIRS("-extdirs", "opt.arg.dirs", "opt.extdirs", STANDARD, FILEMANAGER), |
|
158 |
||
159 |
DJAVA_EXT_DIRS("-Djava.ext.dirs=", "opt.arg.dirs", "opt.extdirs", EXTENDED, FILEMANAGER) { |
|
160 |
@Override |
|
161 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
162 |
return super.process(helper, "-extdirs", arg); |
|
163 |
} |
|
164 |
}, |
|
165 |
||
166 |
ENDORSEDDIRS("-endorseddirs", "opt.arg.dirs", "opt.endorseddirs", STANDARD, FILEMANAGER), |
|
167 |
||
168 |
DJAVA_ENDORSED_DIRS("-Djava.endorsed.dirs=", "opt.arg.dirs", "opt.endorseddirs", EXTENDED, FILEMANAGER) { |
|
169 |
@Override |
|
170 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
171 |
return super.process(helper, "-endorseddirs", arg); |
|
172 |
} |
|
173 |
}, |
|
174 |
||
175 |
PROC("-proc:", "opt.proc.none.only", STANDARD, BASIC, ONEOF, "none", "only"), |
|
176 |
||
177 |
PROCESSOR("-processor", "opt.arg.class.list", "opt.processor", STANDARD, BASIC), |
|
178 |
||
179 |
PROCESSORPATH("-processorpath", "opt.arg.path", "opt.processorpath", STANDARD, FILEMANAGER), |
|
180 |
||
15031
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14960
diff
changeset
|
181 |
PARAMETERS("-parameters","opt.parameters", STANDARD, BASIC), |
c4fad55a5681
8004727: Add compiler support for parameter reflection
jjg
parents:
14960
diff
changeset
|
182 |
|
11315 | 183 |
D("-d", "opt.arg.directory", "opt.d", STANDARD, FILEMANAGER), |
184 |
||
185 |
S("-s", "opt.arg.directory", "opt.sourceDest", STANDARD, FILEMANAGER), |
|
186 |
||
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
11317
diff
changeset
|
187 |
H("-h", "opt.arg.directory", "opt.headerDest", STANDARD, FILEMANAGER), |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
11317
diff
changeset
|
188 |
|
11315 | 189 |
IMPLICIT("-implicit:", "opt.implicit", STANDARD, BASIC, ONEOF, "none", "class"), |
190 |
||
191 |
ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER) { |
|
192 |
@Override |
|
193 |
public boolean process(OptionHelper helper, String option, String operand) { |
|
194 |
return super.process(helper, option, operand); |
|
195 |
} |
|
196 |
||
197 |
}, |
|
198 |
||
199 |
SOURCE("-source", "opt.arg.release", "opt.source", STANDARD, BASIC) { |
|
200 |
@Override |
|
201 |
public boolean process(OptionHelper helper, String option, String operand) { |
|
202 |
Source source = Source.lookup(operand); |
|
203 |
if (source == null) { |
|
204 |
helper.error("err.invalid.source", operand); |
|
205 |
return true; |
|
206 |
} |
|
207 |
return super.process(helper, option, operand); |
|
208 |
} |
|
209 |
}, |
|
210 |
||
211 |
TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) { |
|
212 |
@Override |
|
213 |
public boolean process(OptionHelper helper, String option, String operand) { |
|
214 |
Target target = Target.lookup(operand); |
|
215 |
if (target == null) { |
|
216 |
helper.error("err.invalid.target", operand); |
|
217 |
return true; |
|
218 |
} |
|
219 |
return super.process(helper, option, operand); |
|
220 |
} |
|
221 |
}, |
|
222 |
||
15724 | 223 |
PROFILE("-profile", "opt.arg.profile", "opt.profile", STANDARD, BASIC) { |
224 |
@Override |
|
225 |
public boolean process(OptionHelper helper, String option, String operand) { |
|
226 |
Profile profile = Profile.lookup(operand); |
|
227 |
if (profile == null) { |
|
228 |
helper.error("err.invalid.profile", operand); |
|
229 |
return true; |
|
230 |
} |
|
231 |
return super.process(helper, option, operand); |
|
232 |
} |
|
233 |
}, |
|
234 |
||
11315 | 235 |
VERSION("-version", "opt.version", STANDARD, INFO) { |
236 |
@Override |
|
237 |
public boolean process(OptionHelper helper, String option) { |
|
238 |
Log log = helper.getLog(); |
|
239 |
String ownName = helper.getOwnName(); |
|
240 |
log.printLines(PrefixKind.JAVAC, "version", ownName, JavaCompiler.version()); |
|
241 |
return super.process(helper, option); |
|
242 |
} |
|
243 |
}, |
|
244 |
||
245 |
FULLVERSION("-fullversion", null, HIDDEN, INFO) { |
|
246 |
@Override |
|
247 |
public boolean process(OptionHelper helper, String option) { |
|
248 |
Log log = helper.getLog(); |
|
249 |
String ownName = helper.getOwnName(); |
|
11317
72a4280ef5b2
7121681: compiler message file broken for javac -fullversion
jjg
parents:
11316
diff
changeset
|
250 |
log.printLines(PrefixKind.JAVAC, "fullVersion", ownName, JavaCompiler.fullVersion()); |
11315 | 251 |
return super.process(helper, option); |
252 |
} |
|
253 |
}, |
|
254 |
||
255 |
DIAGS("-XDdiags=", null, HIDDEN, INFO) { |
|
256 |
@Override |
|
257 |
public boolean process(OptionHelper helper, String option) { |
|
258 |
option = option.substring(option.indexOf('=') + 1); |
|
259 |
String diagsOption = option.contains("%") ? |
|
260 |
"-XDdiagsFormat=" : |
|
261 |
"-XDdiags="; |
|
262 |
diagsOption += option; |
|
263 |
if (XD.matches(diagsOption)) |
|
264 |
return XD.process(helper, diagsOption); |
|
265 |
else |
|
266 |
return false; |
|
267 |
} |
|
268 |
}, |
|
269 |
||
270 |
HELP("-help", "opt.help", STANDARD, INFO) { |
|
271 |
@Override |
|
272 |
public boolean process(OptionHelper helper, String option) { |
|
273 |
Log log = helper.getLog(); |
|
274 |
String ownName = helper.getOwnName(); |
|
275 |
log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName); |
|
276 |
for (Option o: getJavaCompilerOptions()) { |
|
277 |
o.help(log, OptionKind.STANDARD); |
|
278 |
} |
|
279 |
log.printNewline(); |
|
280 |
return super.process(helper, option); |
|
281 |
} |
|
282 |
}, |
|
283 |
||
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
284 |
A("-A", "opt.arg.key.equals.value", "opt.A", STANDARD, BASIC, true) { |
11315 | 285 |
@Override |
286 |
public boolean matches(String arg) { |
|
287 |
return arg.startsWith("-A"); |
|
288 |
} |
|
289 |
||
290 |
@Override |
|
291 |
public boolean hasArg() { |
|
292 |
return false; |
|
293 |
} |
|
294 |
// Mapping for processor options created in |
|
295 |
// JavacProcessingEnvironment |
|
296 |
@Override |
|
297 |
public boolean process(OptionHelper helper, String option) { |
|
298 |
int argLength = option.length(); |
|
299 |
if (argLength == 2) { |
|
300 |
helper.error("err.empty.A.argument"); |
|
301 |
return true; |
|
302 |
} |
|
303 |
int sepIndex = option.indexOf('='); |
|
304 |
String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) ); |
|
305 |
if (!JavacProcessingEnvironment.isValidOptionName(key)) { |
|
306 |
helper.error("err.invalid.A.key", option); |
|
307 |
return true; |
|
308 |
} |
|
309 |
return process(helper, option, option); |
|
310 |
} |
|
311 |
}, |
|
312 |
||
313 |
X("-X", "opt.X", STANDARD, INFO) { |
|
314 |
@Override |
|
315 |
public boolean process(OptionHelper helper, String option) { |
|
316 |
Log log = helper.getLog(); |
|
317 |
for (Option o: getJavaCompilerOptions()) { |
|
318 |
o.help(log, OptionKind.EXTENDED); |
|
319 |
} |
|
320 |
log.printNewline(); |
|
321 |
log.printLines(PrefixKind.JAVAC, "msg.usage.nonstandard.footer"); |
|
322 |
return super.process(helper, option); |
|
323 |
} |
|
324 |
}, |
|
325 |
||
326 |
// This option exists only for the purpose of documenting itself. |
|
327 |
// It's actually implemented by the launcher. |
|
15043
4aae62f3b9a8
8006037: extra space in javac -help for -J and @ options
jjg
parents:
15031
diff
changeset
|
328 |
J("-J", "opt.arg.flag", "opt.J", STANDARD, INFO, true) { |
11315 | 329 |
@Override |
330 |
public boolean process(OptionHelper helper, String option) { |
|
331 |
throw new AssertionError |
|
332 |
("the -J flag should be caught by the launcher."); |
|
333 |
} |
|
334 |
}, |
|
335 |
||
336 |
MOREINFO("-moreinfo", null, HIDDEN, BASIC) { |
|
337 |
@Override |
|
338 |
public boolean process(OptionHelper helper, String option) { |
|
339 |
Type.moreInfo = true; |
|
340 |
return super.process(helper, option); |
|
341 |
} |
|
342 |
}, |
|
343 |
||
344 |
// treat warnings as errors |
|
345 |
WERROR("-Werror", "opt.Werror", STANDARD, BASIC), |
|
346 |
||
347 |
// prompt after each error |
|
348 |
// new Option("-prompt", "opt.prompt"), |
|
349 |
PROMPT("-prompt", null, HIDDEN, BASIC), |
|
350 |
||
351 |
// dump stack on error |
|
352 |
DOE("-doe", null, HIDDEN, BASIC), |
|
353 |
||
354 |
// output source after type erasure |
|
355 |
PRINTSOURCE("-printsource", null, HIDDEN, BASIC), |
|
356 |
||
357 |
// display warnings for generic unchecked operations |
|
358 |
WARNUNCHECKED("-warnunchecked", null, HIDDEN, BASIC) { |
|
359 |
@Override |
|
360 |
public boolean process(OptionHelper helper, String option) { |
|
361 |
helper.put("-Xlint:unchecked", option); |
|
362 |
return false; |
|
363 |
} |
|
364 |
}, |
|
365 |
||
366 |
XMAXERRS("-Xmaxerrs", "opt.arg.number", "opt.maxerrs", EXTENDED, BASIC), |
|
367 |
||
368 |
XMAXWARNS("-Xmaxwarns", "opt.arg.number", "opt.maxwarns", EXTENDED, BASIC), |
|
369 |
||
11316
4dcad625e72e
7111022: javac no long prints last round of processing
jjg
parents:
11315
diff
changeset
|
370 |
XSTDOUT("-Xstdout", "opt.arg.file", "opt.Xstdout", EXTENDED, INFO) { |
11315 | 371 |
@Override |
372 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
373 |
try { |
|
374 |
Log log = helper.getLog(); |
|
375 |
// TODO: this file should be closed at the end of compilation |
|
376 |
log.setWriters(new PrintWriter(new FileWriter(arg), true)); |
|
377 |
} catch (java.io.IOException e) { |
|
378 |
helper.error("err.error.writing.file", arg, e); |
|
379 |
return true; |
|
380 |
} |
|
381 |
return super.process(helper, option, arg); |
|
382 |
} |
|
383 |
}, |
|
384 |
||
385 |
XPRINT("-Xprint", "opt.print", EXTENDED, BASIC), |
|
386 |
||
387 |
XPRINTROUNDS("-XprintRounds", "opt.printRounds", EXTENDED, BASIC), |
|
388 |
||
389 |
XPRINTPROCESSORINFO("-XprintProcessorInfo", "opt.printProcessorInfo", EXTENDED, BASIC), |
|
390 |
||
391 |
XPREFER("-Xprefer:", "opt.prefer", EXTENDED, BASIC, ONEOF, "source", "newer"), |
|
392 |
||
19670
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
393 |
// see enum PkgInfo |
11315 | 394 |
XPKGINFO("-Xpkginfo:", "opt.pkginfo", EXTENDED, BASIC, ONEOF, "always", "legacy", "nonempty"), |
395 |
||
396 |
/* -O is a no-op, accepted for backward compatibility. */ |
|
397 |
O("-O", null, HIDDEN, BASIC), |
|
398 |
||
399 |
/* -Xjcov produces tables to support the code coverage tool jcov. */ |
|
400 |
XJCOV("-Xjcov", null, HIDDEN, BASIC), |
|
401 |
||
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
402 |
PLUGIN("-Xplugin:", "opt.arg.plugin", "opt.plugin", EXTENDED, BASIC) { |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
403 |
@Override |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
404 |
public boolean process(OptionHelper helper, String option) { |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
405 |
String p = option.substring(option.indexOf(':') + 1); |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
406 |
String prev = helper.get(PLUGIN); |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
407 |
helper.put(PLUGIN.text, (prev == null) ? p : prev + '\0' + p.trim()); |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
408 |
return false; |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
409 |
} |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
410 |
}, |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
12213
diff
changeset
|
411 |
|
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
15724
diff
changeset
|
412 |
XDIAGS("-Xdiags:", "opt.diags", EXTENDED, BASIC, ONEOF, "compact", "verbose"), |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
15724
diff
changeset
|
413 |
|
11315 | 414 |
/* This is a back door to the compiler's option table. |
415 |
* -XDx=y sets the option x to the value y. |
|
416 |
* -XDx sets the option x to the value x. |
|
417 |
*/ |
|
418 |
XD("-XD", null, HIDDEN, BASIC) { |
|
419 |
@Override |
|
420 |
public boolean matches(String s) { |
|
421 |
return s.startsWith(text); |
|
422 |
} |
|
423 |
@Override |
|
424 |
public boolean process(OptionHelper helper, String option) { |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
425 |
option = option.substring(text.length()); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
426 |
int eq = option.indexOf('='); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
427 |
String key = (eq < 0) ? option : option.substring(0, eq); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
428 |
String value = (eq < 0) ? option : option.substring(eq+1); |
11315 | 429 |
helper.put(key, value); |
430 |
return false; |
|
431 |
} |
|
432 |
}, |
|
433 |
||
434 |
// This option exists only for the purpose of documenting itself. |
|
435 |
// It's actually implemented by the CommandLine class. |
|
15043
4aae62f3b9a8
8006037: extra space in javac -help for -J and @ options
jjg
parents:
15031
diff
changeset
|
436 |
AT("@", "opt.arg.file", "opt.AT", STANDARD, INFO, true) { |
11315 | 437 |
@Override |
438 |
public boolean process(OptionHelper helper, String option) { |
|
439 |
throw new AssertionError("the @ flag should be caught by CommandLine."); |
|
440 |
} |
|
441 |
}, |
|
442 |
||
443 |
/* |
|
444 |
* TODO: With apt, the matches method accepts anything if |
|
445 |
* -XclassAsDecls is used; code elsewhere does the lookup to |
|
446 |
* see if the class name is both legal and found. |
|
447 |
* |
|
448 |
* In apt, the process method adds the candidate class file |
|
449 |
* name to a separate list. |
|
450 |
*/ |
|
451 |
SOURCEFILE("sourcefile", null, HIDDEN, INFO) { |
|
452 |
@Override |
|
453 |
public boolean matches(String s) { |
|
454 |
return s.endsWith(".java") // Java source file |
|
455 |
|| SourceVersion.isName(s); // Legal type name |
|
456 |
} |
|
457 |
@Override |
|
458 |
public boolean process(OptionHelper helper, String option) { |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
459 |
if (option.endsWith(".java") ) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
460 |
File f = new File(option); |
11315 | 461 |
if (!f.exists()) { |
462 |
helper.error("err.file.not.found", f); |
|
463 |
return true; |
|
464 |
} |
|
465 |
if (!f.isFile()) { |
|
466 |
helper.error("err.file.not.file", f); |
|
467 |
return true; |
|
468 |
} |
|
469 |
helper.addFile(f); |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
470 |
} else { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
471 |
helper.addClassName(option); |
11315 | 472 |
} |
473 |
return false; |
|
474 |
} |
|
475 |
}; |
|
476 |
||
477 |
/** The kind of an Option. This is used by the -help and -X options. */ |
|
478 |
public enum OptionKind { |
|
479 |
/** A standard option, documented by -help. */ |
|
480 |
STANDARD, |
|
481 |
/** An extended option, documented by -X. */ |
|
482 |
EXTENDED, |
|
483 |
/** A hidden option, not documented. */ |
|
484 |
HIDDEN, |
|
485 |
} |
|
486 |
||
487 |
/** The group for an Option. This determines the situations in which the |
|
488 |
* option is applicable. */ |
|
489 |
enum OptionGroup { |
|
490 |
/** A basic option, available for use on the command line or via the |
|
491 |
* Compiler API. */ |
|
492 |
BASIC, |
|
493 |
/** An option for javac's standard JavaFileManager. Other file managers |
|
494 |
* may or may not support these options. */ |
|
495 |
FILEMANAGER, |
|
496 |
/** A command-line option that requests information, such as -help. */ |
|
497 |
INFO, |
|
498 |
/** A command-line "option" representing a file or class name. */ |
|
499 |
OPERAND |
|
500 |
} |
|
501 |
||
502 |
/** The kind of choice for "choice" options. */ |
|
503 |
enum ChoiceKind { |
|
504 |
/** The expected value is exactly one of the set of choices. */ |
|
505 |
ONEOF, |
|
506 |
/** The expected value is one of more of the set of choices. */ |
|
507 |
ANYOF |
|
508 |
} |
|
509 |
||
510 |
public final String text; |
|
511 |
||
512 |
final OptionKind kind; |
|
513 |
||
514 |
final OptionGroup group; |
|
515 |
||
516 |
/** Documentation key for arguments. |
|
517 |
*/ |
|
518 |
final String argsNameKey; |
|
519 |
||
520 |
/** Documentation key for description. |
|
521 |
*/ |
|
522 |
final String descrKey; |
|
523 |
||
524 |
/** Suffix option (-foo=bar or -foo:bar) |
|
525 |
*/ |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
526 |
final boolean hasSuffix; |
11315 | 527 |
|
528 |
/** The kind of choices for this option, if any. |
|
529 |
*/ |
|
530 |
final ChoiceKind choiceKind; |
|
531 |
||
532 |
/** The choices for this option, if any, and whether or not the choices |
|
533 |
* are hidden |
|
534 |
*/ |
|
535 |
final Map<String,Boolean> choices; |
|
536 |
||
537 |
||
538 |
Option(String text, String descrKey, |
|
539 |
OptionKind kind, OptionGroup group) { |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
540 |
this(text, null, descrKey, kind, group, null, null, false); |
11315 | 541 |
} |
542 |
||
543 |
Option(String text, String argsNameKey, String descrKey, |
|
544 |
OptionKind kind, OptionGroup group) { |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
545 |
this(text, argsNameKey, descrKey, kind, group, null, null, false); |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
546 |
} |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
547 |
|
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
548 |
Option(String text, String argsNameKey, String descrKey, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
549 |
OptionKind kind, OptionGroup group, boolean doHasSuffix) { |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
550 |
this(text, argsNameKey, descrKey, kind, group, null, null, doHasSuffix); |
11315 | 551 |
} |
552 |
||
553 |
Option(String text, String descrKey, |
|
554 |
OptionKind kind, OptionGroup group, |
|
555 |
ChoiceKind choiceKind, Map<String,Boolean> choices) { |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
556 |
this(text, null, descrKey, kind, group, choiceKind, choices, false); |
11315 | 557 |
} |
558 |
||
559 |
Option(String text, String descrKey, |
|
560 |
OptionKind kind, OptionGroup group, |
|
561 |
ChoiceKind choiceKind, String... choices) { |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
562 |
this(text, null, descrKey, kind, group, choiceKind, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
563 |
createChoices(choices), false); |
11315 | 564 |
} |
565 |
// where |
|
566 |
private static Map<String,Boolean> createChoices(String... choices) { |
|
22163 | 567 |
Map<String,Boolean> map = new LinkedHashMap<>(); |
11315 | 568 |
for (String c: choices) |
569 |
map.put(c, false); |
|
570 |
return map; |
|
571 |
} |
|
572 |
||
573 |
private Option(String text, String argsNameKey, String descrKey, |
|
574 |
OptionKind kind, OptionGroup group, |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
575 |
ChoiceKind choiceKind, Map<String,Boolean> choices, |
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
576 |
boolean doHasSuffix) { |
11315 | 577 |
this.text = text; |
578 |
this.argsNameKey = argsNameKey; |
|
579 |
this.descrKey = descrKey; |
|
580 |
this.kind = kind; |
|
581 |
this.group = group; |
|
582 |
this.choiceKind = choiceKind; |
|
583 |
this.choices = choices; |
|
584 |
char lastChar = text.charAt(text.length()-1); |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
585 |
this.hasSuffix = doHasSuffix || lastChar == ':' || lastChar == '='; |
11315 | 586 |
} |
587 |
||
588 |
public String getText() { |
|
589 |
return text; |
|
590 |
} |
|
591 |
||
592 |
public OptionKind getKind() { |
|
593 |
return kind; |
|
594 |
} |
|
595 |
||
596 |
public boolean hasArg() { |
|
597 |
return argsNameKey != null && !hasSuffix; |
|
598 |
} |
|
599 |
||
600 |
public boolean matches(String option) { |
|
601 |
if (!hasSuffix) |
|
602 |
return option.equals(text); |
|
603 |
||
604 |
if (!option.startsWith(text)) |
|
605 |
return false; |
|
606 |
||
607 |
if (choices != null) { |
|
608 |
String arg = option.substring(text.length()); |
|
609 |
if (choiceKind == ChoiceKind.ONEOF) |
|
610 |
return choices.keySet().contains(arg); |
|
611 |
else { |
|
612 |
for (String a: arg.split(",+")) { |
|
613 |
if (!choices.keySet().contains(a)) |
|
614 |
return false; |
|
615 |
} |
|
616 |
} |
|
617 |
} |
|
618 |
||
619 |
return true; |
|
620 |
} |
|
621 |
||
622 |
public boolean process(OptionHelper helper, String option, String arg) { |
|
623 |
if (choices != null) { |
|
624 |
if (choiceKind == ChoiceKind.ONEOF) { |
|
625 |
// some clients like to see just one of option+choice set |
|
626 |
for (String s: choices.keySet()) |
|
627 |
helper.remove(option + s); |
|
628 |
String opt = option + arg; |
|
629 |
helper.put(opt, opt); |
|
630 |
// some clients like to see option (without trailing ":") |
|
631 |
// set to arg |
|
632 |
String nm = option.substring(0, option.length() - 1); |
|
633 |
helper.put(nm, arg); |
|
634 |
} else { |
|
635 |
// set option+word for each word in arg |
|
636 |
for (String a: arg.split(",+")) { |
|
637 |
String opt = option + a; |
|
638 |
helper.put(opt, opt); |
|
639 |
} |
|
640 |
} |
|
641 |
} |
|
642 |
helper.put(option, arg); |
|
643 |
return false; |
|
644 |
} |
|
645 |
||
646 |
public boolean process(OptionHelper helper, String option) { |
|
647 |
if (hasSuffix) |
|
648 |
return process(helper, text, option.substring(text.length())); |
|
649 |
else |
|
650 |
return process(helper, option, option); |
|
651 |
} |
|
652 |
||
653 |
void help(Log log, OptionKind kind) { |
|
654 |
if (this.kind != kind) |
|
655 |
return; |
|
656 |
||
657 |
log.printRawLines(WriterKind.NOTICE, |
|
658 |
String.format(" %-26s %s", |
|
659 |
helpSynopsis(log), |
|
660 |
log.localize(PrefixKind.JAVAC, descrKey))); |
|
661 |
||
662 |
} |
|
663 |
||
664 |
private String helpSynopsis(Log log) { |
|
665 |
StringBuilder sb = new StringBuilder(); |
|
666 |
sb.append(text); |
|
667 |
if (argsNameKey == null) { |
|
668 |
if (choices != null) { |
|
669 |
String sep = "{"; |
|
670 |
for (Map.Entry<String,Boolean> e: choices.entrySet()) { |
|
671 |
if (!e.getValue()) { |
|
672 |
sb.append(sep); |
|
673 |
sb.append(e.getKey()); |
|
674 |
sep = ","; |
|
675 |
} |
|
676 |
} |
|
677 |
sb.append("}"); |
|
678 |
} |
|
679 |
} else { |
|
680 |
if (!hasSuffix) |
|
681 |
sb.append(" "); |
|
682 |
sb.append(log.localize(PrefixKind.JAVAC, argsNameKey)); |
|
683 |
||
684 |
} |
|
685 |
||
686 |
return sb.toString(); |
|
687 |
} |
|
688 |
||
689 |
// For -XpkgInfo:value |
|
690 |
public enum PkgInfo { |
|
19670
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
691 |
/** |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
692 |
* Always generate package-info.class for every package-info.java file. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
693 |
* The file may be empty if there annotations with a RetentionPolicy |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
694 |
* of CLASS or RUNTIME. This option may be useful in conjunction with |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
695 |
* build systems (such as Ant) that expect javac to generate at least |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
696 |
* one .class file for every .java file. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
697 |
*/ |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
698 |
ALWAYS, |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
699 |
/** |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
700 |
* Generate a package-info.class file if package-info.java contains |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
701 |
* annotations. The file may be empty if all the annotations have |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
702 |
* a RetentionPolicy of SOURCE. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
703 |
* This value is just for backwards compatibility with earlier behavior. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
704 |
* Either of the other two values are to be preferred to using this one. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
705 |
*/ |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
706 |
LEGACY, |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
707 |
/** |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
708 |
* Generate a package-info.class file if and only if there are annotations |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
709 |
* in package-info.java to be written into it. |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
710 |
*/ |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
711 |
NONEMPTY; |
197392292aad
8022744: javac -Xpkginfo command's documentation is sparse
jjg
parents:
17582
diff
changeset
|
712 |
|
11315 | 713 |
public static PkgInfo get(Options options) { |
714 |
String v = options.get(XPKGINFO); |
|
715 |
return (v == null |
|
716 |
? PkgInfo.LEGACY |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
19670
diff
changeset
|
717 |
: PkgInfo.valueOf(StringUtils.toUpperCase(v))); |
11315 | 718 |
} |
719 |
} |
|
720 |
||
721 |
private static Map<String,Boolean> getXLintChoices() { |
|
22163 | 722 |
Map<String,Boolean> choices = new LinkedHashMap<>(); |
11315 | 723 |
choices.put("all", false); |
724 |
for (Lint.LintCategory c : Lint.LintCategory.values()) |
|
725 |
choices.put(c.option, c.hidden); |
|
726 |
for (Lint.LintCategory c : Lint.LintCategory.values()) |
|
727 |
choices.put("-" + c.option, c.hidden); |
|
728 |
choices.put("none", false); |
|
729 |
return choices; |
|
730 |
} |
|
731 |
||
732 |
static Set<Option> getJavaCompilerOptions() { |
|
733 |
return EnumSet.allOf(Option.class); |
|
734 |
} |
|
735 |
||
736 |
public static Set<Option> getJavacFileManagerOptions() { |
|
737 |
return getOptions(EnumSet.of(FILEMANAGER)); |
|
738 |
} |
|
739 |
||
740 |
public static Set<Option> getJavacToolOptions() { |
|
741 |
return getOptions(EnumSet.of(BASIC)); |
|
742 |
} |
|
743 |
||
744 |
static Set<Option> getOptions(Set<OptionGroup> desired) { |
|
745 |
Set<Option> options = EnumSet.noneOf(Option.class); |
|
746 |
for (Option option : Option.values()) |
|
747 |
if (desired.contains(option.group)) |
|
748 |
options.add(option); |
|
749 |
return Collections.unmodifiableSet(options); |
|
750 |
} |
|
751 |
||
752 |
} |