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