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