author | jjg |
Mon, 07 Mar 2011 13:45:06 -0800 | |
changeset 8637 | be1b564b50aa |
parent 7681 | 1f0819a3341f |
child 9087 | e9e44877cd18 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
7681 | 2 |
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.main; |
|
27 |
||
168 | 28 |
import com.sun.tools.javac.code.Lint; |
10 | 29 |
import com.sun.tools.javac.code.Source; |
30 |
import com.sun.tools.javac.code.Type; |
|
31 |
import com.sun.tools.javac.jvm.Target; |
|
32 |
import com.sun.tools.javac.main.JavacOption.HiddenOption; |
|
33 |
import com.sun.tools.javac.main.JavacOption.Option; |
|
34 |
import com.sun.tools.javac.main.JavacOption.XOption; |
|
35 |
import com.sun.tools.javac.util.ListBuffer; |
|
36 |
import com.sun.tools.javac.util.Options; |
|
37 |
import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
|
38 |
import java.io.File; |
|
39 |
import java.io.FileWriter; |
|
40 |
import java.io.PrintWriter; |
|
41 |
import java.util.EnumSet; |
|
3661 | 42 |
import java.util.LinkedHashMap; |
43 |
import java.util.Map; |
|
10 | 44 |
import java.util.Set; |
45 |
import javax.lang.model.SourceVersion; |
|
46 |
||
47 |
import static com.sun.tools.javac.main.OptionName.*; |
|
48 |
||
49 |
/** |
|
50 |
* TODO: describe com.sun.tools.javac.main.RecognizedOptions |
|
51 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
52 |
* <p><b>This is NOT part of any supported API. |
10 | 53 |
* If you write code that depends on this, you do so at your own |
54 |
* risk. This code and its internal interfaces are subject to change |
|
55 |
* or deletion without notice.</b></p> |
|
56 |
*/ |
|
57 |
public class RecognizedOptions { |
|
58 |
||
59 |
private RecognizedOptions() {} |
|
60 |
||
61 |
public interface OptionHelper { |
|
62 |
||
63 |
void setOut(PrintWriter out); |
|
64 |
||
65 |
void error(String key, Object... args); |
|
66 |
||
67 |
void printVersion(); |
|
68 |
||
69 |
void printFullVersion(); |
|
70 |
||
71 |
void printHelp(); |
|
72 |
||
73 |
void printXhelp(); |
|
74 |
||
75 |
void addFile(File f); |
|
76 |
||
77 |
void addClassName(String s); |
|
78 |
||
79 |
} |
|
80 |
||
81 |
public static class GrumpyHelper implements OptionHelper { |
|
82 |
||
83 |
public void setOut(PrintWriter out) { |
|
84 |
throw new IllegalArgumentException(); |
|
85 |
} |
|
86 |
||
87 |
public void error(String key, Object... args) { |
|
88 |
throw new IllegalArgumentException(Main.getLocalizedString(key, args)); |
|
89 |
} |
|
90 |
||
91 |
public void printVersion() { |
|
92 |
throw new IllegalArgumentException(); |
|
93 |
} |
|
94 |
||
95 |
public void printFullVersion() { |
|
96 |
throw new IllegalArgumentException(); |
|
97 |
} |
|
98 |
||
99 |
public void printHelp() { |
|
100 |
throw new IllegalArgumentException(); |
|
101 |
} |
|
102 |
||
103 |
public void printXhelp() { |
|
104 |
throw new IllegalArgumentException(); |
|
105 |
} |
|
106 |
||
107 |
public void addFile(File f) { |
|
108 |
throw new IllegalArgumentException(f.getPath()); |
|
109 |
} |
|
110 |
||
111 |
public void addClassName(String s) { |
|
112 |
throw new IllegalArgumentException(s); |
|
113 |
} |
|
114 |
||
115 |
} |
|
116 |
||
117 |
static Set<OptionName> javacOptions = EnumSet.of( |
|
118 |
G, |
|
119 |
G_NONE, |
|
120 |
G_CUSTOM, |
|
121 |
XLINT, |
|
122 |
XLINT_CUSTOM, |
|
123 |
NOWARN, |
|
124 |
VERBOSE, |
|
125 |
DEPRECATION, |
|
126 |
CLASSPATH, |
|
127 |
CP, |
|
128 |
SOURCEPATH, |
|
129 |
BOOTCLASSPATH, |
|
130 |
XBOOTCLASSPATH_PREPEND, |
|
131 |
XBOOTCLASSPATH_APPEND, |
|
132 |
XBOOTCLASSPATH, |
|
133 |
EXTDIRS, |
|
134 |
DJAVA_EXT_DIRS, |
|
135 |
ENDORSEDDIRS, |
|
136 |
DJAVA_ENDORSED_DIRS, |
|
168 | 137 |
PROC, |
10 | 138 |
PROCESSOR, |
139 |
PROCESSORPATH, |
|
140 |
D, |
|
141 |
S, |
|
142 |
IMPLICIT, |
|
143 |
ENCODING, |
|
144 |
SOURCE, |
|
145 |
TARGET, |
|
146 |
VERSION, |
|
147 |
FULLVERSION, |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
148 |
DIAGS, |
10 | 149 |
HELP, |
150 |
A, |
|
151 |
X, |
|
152 |
J, |
|
153 |
MOREINFO, |
|
154 |
WERROR, |
|
155 |
// COMPLEXINFERENCE, |
|
156 |
PROMPT, |
|
157 |
DOE, |
|
158 |
PRINTSOURCE, |
|
159 |
WARNUNCHECKED, |
|
160 |
XMAXERRS, |
|
161 |
XMAXWARNS, |
|
162 |
XSTDOUT, |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
163 |
XPKGINFO, |
10 | 164 |
XPRINT, |
165 |
XPRINTROUNDS, |
|
166 |
XPRINTPROCESSORINFO, |
|
167 |
XPREFER, |
|
168 |
O, |
|
169 |
XJCOV, |
|
170 |
XD, |
|
8637
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
171 |
AT, |
10 | 172 |
SOURCEFILE); |
173 |
||
174 |
static Set<OptionName> javacFileManagerOptions = EnumSet.of( |
|
175 |
CLASSPATH, |
|
176 |
CP, |
|
177 |
SOURCEPATH, |
|
178 |
BOOTCLASSPATH, |
|
179 |
XBOOTCLASSPATH_PREPEND, |
|
180 |
XBOOTCLASSPATH_APPEND, |
|
181 |
XBOOTCLASSPATH, |
|
182 |
EXTDIRS, |
|
183 |
DJAVA_EXT_DIRS, |
|
184 |
ENDORSEDDIRS, |
|
185 |
DJAVA_ENDORSED_DIRS, |
|
186 |
PROCESSORPATH, |
|
187 |
D, |
|
188 |
S, |
|
189 |
ENCODING, |
|
190 |
SOURCE); |
|
191 |
||
192 |
static Set<OptionName> javacToolOptions = EnumSet.of( |
|
193 |
G, |
|
194 |
G_NONE, |
|
195 |
G_CUSTOM, |
|
196 |
XLINT, |
|
197 |
XLINT_CUSTOM, |
|
198 |
NOWARN, |
|
199 |
VERBOSE, |
|
200 |
DEPRECATION, |
|
168 | 201 |
PROC, |
10 | 202 |
PROCESSOR, |
203 |
IMPLICIT, |
|
204 |
SOURCE, |
|
205 |
TARGET, |
|
206 |
// VERSION, |
|
207 |
// FULLVERSION, |
|
208 |
// HELP, |
|
209 |
A, |
|
210 |
// X, |
|
211 |
// J, |
|
212 |
MOREINFO, |
|
213 |
WERROR, |
|
214 |
// COMPLEXINFERENCE, |
|
215 |
PROMPT, |
|
216 |
DOE, |
|
217 |
PRINTSOURCE, |
|
218 |
WARNUNCHECKED, |
|
219 |
XMAXERRS, |
|
220 |
XMAXWARNS, |
|
221 |
// XSTDOUT, |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
222 |
XPKGINFO, |
10 | 223 |
XPRINT, |
224 |
XPRINTROUNDS, |
|
225 |
XPRINTPROCESSORINFO, |
|
226 |
XPREFER, |
|
227 |
O, |
|
228 |
XJCOV, |
|
229 |
XD); |
|
230 |
||
231 |
static Option[] getJavaCompilerOptions(OptionHelper helper) { |
|
232 |
return getOptions(helper, javacOptions); |
|
233 |
} |
|
234 |
||
235 |
public static Option[] getJavacFileManagerOptions(OptionHelper helper) { |
|
236 |
return getOptions(helper, javacFileManagerOptions); |
|
237 |
} |
|
238 |
||
239 |
public static Option[] getJavacToolOptions(OptionHelper helper) { |
|
240 |
return getOptions(helper, javacToolOptions); |
|
241 |
} |
|
242 |
||
243 |
static Option[] getOptions(OptionHelper helper, Set<OptionName> desired) { |
|
244 |
ListBuffer<Option> options = new ListBuffer<Option>(); |
|
245 |
for (Option option : getAll(helper)) |
|
246 |
if (desired.contains(option.getName())) |
|
247 |
options.append(option); |
|
248 |
return options.toArray(new Option[options.length()]); |
|
249 |
} |
|
250 |
||
251 |
/** |
|
168 | 252 |
* Get all the recognized options. |
253 |
* @param helper an {@code OptionHelper} to help when processing options |
|
254 |
* @return an array of options |
|
10 | 255 |
*/ |
256 |
public static Option[] getAll(final OptionHelper helper) { |
|
168 | 257 |
return new Option[] { |
10 | 258 |
new Option(G, "opt.g"), |
259 |
new Option(G_NONE, "opt.g.none") { |
|
168 | 260 |
@Override |
10 | 261 |
public boolean process(Options options, String option) { |
262 |
options.put("-g:", "none"); |
|
263 |
return false; |
|
264 |
} |
|
265 |
}, |
|
266 |
||
168 | 267 |
new Option(G_CUSTOM, "opt.g.lines.vars.source", |
268 |
Option.ChoiceKind.ANYOF, "lines", "vars", "source"), |
|
269 |
||
270 |
new XOption(XLINT, "opt.Xlint"), |
|
271 |
new XOption(XLINT_CUSTOM, "opt.Xlint.suboptlist", |
|
272 |
Option.ChoiceKind.ANYOF, getXLintChoices()), |
|
273 |
||
274 |
// -nowarn is retained for command-line backward compatibility |
|
275 |
new Option(NOWARN, "opt.nowarn") { |
|
276 |
@Override |
|
10 | 277 |
public boolean process(Options options, String option) { |
168 | 278 |
options.put("-Xlint:none", option); |
10 | 279 |
return false; |
280 |
} |
|
281 |
}, |
|
282 |
||
283 |
new Option(VERBOSE, "opt.verbose"), |
|
284 |
||
285 |
// -deprecation is retained for command-line backward compatibility |
|
286 |
new Option(DEPRECATION, "opt.deprecation") { |
|
168 | 287 |
@Override |
288 |
public boolean process(Options options, String option) { |
|
289 |
options.put("-Xlint:deprecation", option); |
|
290 |
return false; |
|
291 |
} |
|
292 |
}, |
|
10 | 293 |
|
294 |
new Option(CLASSPATH, "opt.arg.path", "opt.classpath"), |
|
295 |
new Option(CP, "opt.arg.path", "opt.classpath") { |
|
168 | 296 |
@Override |
10 | 297 |
public boolean process(Options options, String option, String arg) { |
298 |
return super.process(options, "-classpath", arg); |
|
299 |
} |
|
300 |
}, |
|
301 |
new Option(SOURCEPATH, "opt.arg.path", "opt.sourcepath"), |
|
302 |
new Option(BOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") { |
|
168 | 303 |
@Override |
10 | 304 |
public boolean process(Options options, String option, String arg) { |
305 |
options.remove("-Xbootclasspath/p:"); |
|
306 |
options.remove("-Xbootclasspath/a:"); |
|
307 |
return super.process(options, option, arg); |
|
308 |
} |
|
309 |
}, |
|
310 |
new XOption(XBOOTCLASSPATH_PREPEND,"opt.arg.path", "opt.Xbootclasspath.p"), |
|
311 |
new XOption(XBOOTCLASSPATH_APPEND, "opt.arg.path", "opt.Xbootclasspath.a"), |
|
312 |
new XOption(XBOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") { |
|
168 | 313 |
@Override |
10 | 314 |
public boolean process(Options options, String option, String arg) { |
315 |
options.remove("-Xbootclasspath/p:"); |
|
316 |
options.remove("-Xbootclasspath/a:"); |
|
317 |
return super.process(options, "-bootclasspath", arg); |
|
318 |
} |
|
319 |
}, |
|
320 |
new Option(EXTDIRS, "opt.arg.dirs", "opt.extdirs"), |
|
321 |
new XOption(DJAVA_EXT_DIRS, "opt.arg.dirs", "opt.extdirs") { |
|
168 | 322 |
@Override |
10 | 323 |
public boolean process(Options options, String option, String arg) { |
324 |
return super.process(options, "-extdirs", arg); |
|
325 |
} |
|
326 |
}, |
|
327 |
new Option(ENDORSEDDIRS, "opt.arg.dirs", "opt.endorseddirs"), |
|
328 |
new XOption(DJAVA_ENDORSED_DIRS, "opt.arg.dirs", "opt.endorseddirs") { |
|
168 | 329 |
@Override |
10 | 330 |
public boolean process(Options options, String option, String arg) { |
331 |
return super.process(options, "-endorseddirs", arg); |
|
332 |
} |
|
333 |
}, |
|
168 | 334 |
new Option(PROC, "opt.proc.none.only", |
335 |
Option.ChoiceKind.ONEOF, "none", "only"), |
|
10 | 336 |
new Option(PROCESSOR, "opt.arg.class.list", "opt.processor"), |
337 |
new Option(PROCESSORPATH, "opt.arg.path", "opt.processorpath"), |
|
338 |
new Option(D, "opt.arg.directory", "opt.d"), |
|
339 |
new Option(S, "opt.arg.directory", "opt.sourceDest"), |
|
168 | 340 |
new Option(IMPLICIT, "opt.implicit", |
341 |
Option.ChoiceKind.ONEOF, "none", "class"), |
|
10 | 342 |
new Option(ENCODING, "opt.arg.encoding", "opt.encoding"), |
343 |
new Option(SOURCE, "opt.arg.release", "opt.source") { |
|
168 | 344 |
@Override |
10 | 345 |
public boolean process(Options options, String option, String operand) { |
346 |
Source source = Source.lookup(operand); |
|
347 |
if (source == null) { |
|
348 |
helper.error("err.invalid.source", operand); |
|
349 |
return true; |
|
350 |
} |
|
351 |
return super.process(options, option, operand); |
|
352 |
} |
|
353 |
}, |
|
354 |
new Option(TARGET, "opt.arg.release", "opt.target") { |
|
168 | 355 |
@Override |
10 | 356 |
public boolean process(Options options, String option, String operand) { |
357 |
Target target = Target.lookup(operand); |
|
358 |
if (target == null) { |
|
359 |
helper.error("err.invalid.target", operand); |
|
360 |
return true; |
|
361 |
} |
|
362 |
return super.process(options, option, operand); |
|
363 |
} |
|
364 |
}, |
|
365 |
new Option(VERSION, "opt.version") { |
|
168 | 366 |
@Override |
10 | 367 |
public boolean process(Options options, String option) { |
368 |
helper.printVersion(); |
|
369 |
return super.process(options, option); |
|
370 |
} |
|
371 |
}, |
|
372 |
new HiddenOption(FULLVERSION) { |
|
168 | 373 |
@Override |
10 | 374 |
public boolean process(Options options, String option) { |
375 |
helper.printFullVersion(); |
|
376 |
return super.process(options, option); |
|
377 |
} |
|
378 |
}, |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
379 |
new HiddenOption(DIAGS) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
380 |
@Override |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
381 |
public boolean process(Options options, String option) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
382 |
Option xd = getOptions(helper, EnumSet.of(XD))[0]; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
383 |
option = option.substring(option.indexOf('=') + 1); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
384 |
String diagsOption = option.contains("%") ? |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
385 |
"-XDdiagsFormat=" : |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
386 |
"-XDdiags="; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
387 |
diagsOption += option; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
388 |
if (xd.matches(diagsOption)) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
389 |
return xd.process(options, diagsOption); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
390 |
else |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
391 |
return false; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
392 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
393 |
}, |
10 | 394 |
new Option(HELP, "opt.help") { |
168 | 395 |
@Override |
10 | 396 |
public boolean process(Options options, String option) { |
397 |
helper.printHelp(); |
|
398 |
return super.process(options, option); |
|
399 |
} |
|
400 |
}, |
|
401 |
new Option(A, "opt.arg.key.equals.value","opt.A") { |
|
168 | 402 |
@Override |
403 |
String helpSynopsis() { |
|
404 |
hasSuffix = true; |
|
405 |
return super.helpSynopsis(); |
|
406 |
} |
|
407 |
||
408 |
@Override |
|
409 |
public boolean matches(String arg) { |
|
410 |
return arg.startsWith("-A"); |
|
411 |
} |
|
10 | 412 |
|
168 | 413 |
@Override |
414 |
public boolean hasArg() { |
|
415 |
return false; |
|
416 |
} |
|
417 |
// Mapping for processor options created in |
|
418 |
// JavacProcessingEnvironment |
|
419 |
@Override |
|
420 |
public boolean process(Options options, String option) { |
|
421 |
int argLength = option.length(); |
|
422 |
if (argLength == 2) { |
|
423 |
helper.error("err.empty.A.argument"); |
|
424 |
return true; |
|
10 | 425 |
} |
168 | 426 |
int sepIndex = option.indexOf('='); |
427 |
String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) ); |
|
428 |
if (!JavacProcessingEnvironment.isValidOptionName(key)) { |
|
429 |
helper.error("err.invalid.A.key", option); |
|
430 |
return true; |
|
10 | 431 |
} |
168 | 432 |
return process(options, option, option); |
433 |
} |
|
10 | 434 |
}, |
435 |
new Option(X, "opt.X") { |
|
168 | 436 |
@Override |
10 | 437 |
public boolean process(Options options, String option) { |
438 |
helper.printXhelp(); |
|
439 |
return super.process(options, option); |
|
440 |
} |
|
441 |
}, |
|
442 |
||
443 |
// This option exists only for the purpose of documenting itself. |
|
444 |
// It's actually implemented by the launcher. |
|
445 |
new Option(J, "opt.arg.flag", "opt.J") { |
|
168 | 446 |
@Override |
10 | 447 |
String helpSynopsis() { |
448 |
hasSuffix = true; |
|
449 |
return super.helpSynopsis(); |
|
450 |
} |
|
168 | 451 |
@Override |
10 | 452 |
public boolean process(Options options, String option) { |
453 |
throw new AssertionError |
|
454 |
("the -J flag should be caught by the launcher."); |
|
455 |
} |
|
456 |
}, |
|
457 |
||
458 |
// stop after parsing and attributing. |
|
459 |
// new HiddenOption("-attrparseonly"), |
|
460 |
||
461 |
// new Option("-moreinfo", "opt.moreinfo") { |
|
462 |
new HiddenOption(MOREINFO) { |
|
168 | 463 |
@Override |
10 | 464 |
public boolean process(Options options, String option) { |
465 |
Type.moreInfo = true; |
|
466 |
return super.process(options, option); |
|
467 |
} |
|
468 |
}, |
|
469 |
||
470 |
// treat warnings as errors |
|
1996 | 471 |
new Option(WERROR, "opt.Werror"), |
10 | 472 |
|
473 |
// use complex inference from context in the position of a method call argument |
|
474 |
new HiddenOption(COMPLEXINFERENCE), |
|
475 |
||
476 |
// generare source stubs |
|
477 |
// new HiddenOption("-stubs"), |
|
478 |
||
479 |
// relax some constraints to allow compiling from stubs |
|
480 |
// new HiddenOption("-relax"), |
|
481 |
||
482 |
// output source after translating away inner classes |
|
483 |
// new Option("-printflat", "opt.printflat"), |
|
484 |
// new HiddenOption("-printflat"), |
|
485 |
||
486 |
// display scope search details |
|
487 |
// new Option("-printsearch", "opt.printsearch"), |
|
488 |
// new HiddenOption("-printsearch"), |
|
489 |
||
490 |
// prompt after each error |
|
491 |
// new Option("-prompt", "opt.prompt"), |
|
492 |
new HiddenOption(PROMPT), |
|
493 |
||
494 |
// dump stack on error |
|
495 |
new HiddenOption(DOE), |
|
496 |
||
497 |
// output source after type erasure |
|
498 |
// new Option("-s", "opt.s"), |
|
499 |
new HiddenOption(PRINTSOURCE), |
|
500 |
||
501 |
// output shrouded class files |
|
502 |
// new Option("-scramble", "opt.scramble"), |
|
503 |
// new Option("-scrambleall", "opt.scrambleall"), |
|
504 |
||
505 |
// display warnings for generic unchecked operations |
|
506 |
new HiddenOption(WARNUNCHECKED) { |
|
168 | 507 |
@Override |
10 | 508 |
public boolean process(Options options, String option) { |
509 |
options.put("-Xlint:unchecked", option); |
|
510 |
return false; |
|
511 |
} |
|
512 |
}, |
|
513 |
||
514 |
new XOption(XMAXERRS, "opt.arg.number", "opt.maxerrs"), |
|
515 |
new XOption(XMAXWARNS, "opt.arg.number", "opt.maxwarns"), |
|
516 |
new XOption(XSTDOUT, "opt.arg.file", "opt.Xstdout") { |
|
168 | 517 |
@Override |
10 | 518 |
public boolean process(Options options, String option, String arg) { |
519 |
try { |
|
520 |
helper.setOut(new PrintWriter(new FileWriter(arg), true)); |
|
521 |
} catch (java.io.IOException e) { |
|
522 |
helper.error("err.error.writing.file", arg, e); |
|
523 |
return true; |
|
524 |
} |
|
525 |
return super.process(options, option, arg); |
|
526 |
} |
|
527 |
}, |
|
528 |
||
529 |
new XOption(XPRINT, "opt.print"), |
|
530 |
||
531 |
new XOption(XPRINTROUNDS, "opt.printRounds"), |
|
532 |
||
533 |
new XOption(XPRINTPROCESSORINFO, "opt.printProcessorInfo"), |
|
534 |
||
168 | 535 |
new XOption(XPREFER, "opt.prefer", |
536 |
Option.ChoiceKind.ONEOF, "source", "newer"), |
|
10 | 537 |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
538 |
new XOption(XPKGINFO, "opt.pkginfo", |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
539 |
Option.ChoiceKind.ONEOF, "always", "legacy", "nonempty"), |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
540 |
|
10 | 541 |
/* -O is a no-op, accepted for backward compatibility. */ |
542 |
new HiddenOption(O), |
|
543 |
||
544 |
/* -Xjcov produces tables to support the code coverage tool jcov. */ |
|
545 |
new HiddenOption(XJCOV), |
|
546 |
||
547 |
/* This is a back door to the compiler's option table. |
|
548 |
* -XDx=y sets the option x to the value y. |
|
549 |
* -XDx sets the option x to the value x. |
|
550 |
*/ |
|
551 |
new HiddenOption(XD) { |
|
552 |
String s; |
|
168 | 553 |
@Override |
10 | 554 |
public boolean matches(String s) { |
555 |
this.s = s; |
|
556 |
return s.startsWith(name.optionName); |
|
557 |
} |
|
168 | 558 |
@Override |
10 | 559 |
public boolean process(Options options, String option) { |
560 |
s = s.substring(name.optionName.length()); |
|
561 |
int eq = s.indexOf('='); |
|
562 |
String key = (eq < 0) ? s : s.substring(0, eq); |
|
563 |
String value = (eq < 0) ? s : s.substring(eq+1); |
|
564 |
options.put(key, value); |
|
565 |
return false; |
|
566 |
} |
|
567 |
}, |
|
568 |
||
8637
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
569 |
// This option exists only for the purpose of documenting itself. |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
570 |
// It's actually implemented by the CommandLine class. |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
571 |
new Option(AT, "opt.arg.file", "opt.AT") { |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
572 |
@Override |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
573 |
String helpSynopsis() { |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
574 |
hasSuffix = true; |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
575 |
return super.helpSynopsis(); |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
576 |
} |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
577 |
@Override |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
578 |
public boolean process(Options options, String option) { |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
579 |
throw new AssertionError |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
580 |
("the @ flag should be caught by CommandLine."); |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
581 |
} |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
582 |
}, |
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
583 |
|
10 | 584 |
/* |
585 |
* TODO: With apt, the matches method accepts anything if |
|
586 |
* -XclassAsDecls is used; code elsewhere does the lookup to |
|
587 |
* see if the class name is both legal and found. |
|
588 |
* |
|
8637
be1b564b50aa
6980021: javac should document @file command line option
jjg
parents:
7681
diff
changeset
|
589 |
* In apt, the process method adds the candidate class file |
10 | 590 |
* name to a separate list. |
591 |
*/ |
|
592 |
new HiddenOption(SOURCEFILE) { |
|
593 |
String s; |
|
168 | 594 |
@Override |
10 | 595 |
public boolean matches(String s) { |
596 |
this.s = s; |
|
597 |
return s.endsWith(".java") // Java source file |
|
598 |
|| SourceVersion.isName(s); // Legal type name |
|
599 |
} |
|
168 | 600 |
@Override |
10 | 601 |
public boolean process(Options options, String option) { |
602 |
if (s.endsWith(".java") ) { |
|
603 |
File f = new File(s); |
|
604 |
if (!f.exists()) { |
|
605 |
helper.error("err.file.not.found", f); |
|
606 |
return true; |
|
607 |
} |
|
608 |
if (!f.isFile()) { |
|
609 |
helper.error("err.file.not.file", f); |
|
610 |
return true; |
|
611 |
} |
|
612 |
helper.addFile(f); |
|
613 |
} |
|
614 |
else |
|
615 |
helper.addClassName(s); |
|
616 |
return false; |
|
617 |
} |
|
618 |
}, |
|
619 |
}; |
|
620 |
} |
|
621 |
||
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
622 |
public enum PkgInfo { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
623 |
ALWAYS, LEGACY, NONEMPTY; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
624 |
public static PkgInfo get(Options options) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
625 |
String v = options.get(XPKGINFO); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
626 |
return (v == null |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
627 |
? PkgInfo.LEGACY |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
628 |
: PkgInfo.valueOf(v.toUpperCase())); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
629 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
630 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
5847
diff
changeset
|
631 |
|
3661 | 632 |
private static Map<String,Boolean> getXLintChoices() { |
633 |
Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>(); |
|
634 |
choices.put("all", false); |
|
168 | 635 |
for (Lint.LintCategory c : Lint.LintCategory.values()) |
3661 | 636 |
choices.put(c.option, c.hidden); |
168 | 637 |
for (Lint.LintCategory c : Lint.LintCategory.values()) |
3661 | 638 |
choices.put("-" + c.option, c.hidden); |
639 |
choices.put("none", false); |
|
168 | 640 |
return choices; |
641 |
} |
|
642 |
||
10 | 643 |
} |