author | jjg |
Thu, 10 Jun 2010 16:08:01 -0700 | |
changeset 5847 | 1908176fd6e3 |
parent 5520 | 86e4b9a9da40 |
child 6575 | ae1798028008 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2006, 2009, 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, |
|
163 |
XPRINT, |
|
164 |
XPRINTROUNDS, |
|
165 |
XPRINTPROCESSORINFO, |
|
166 |
XPREFER, |
|
167 |
O, |
|
168 |
XJCOV, |
|
169 |
XD, |
|
170 |
SOURCEFILE); |
|
171 |
||
172 |
static Set<OptionName> javacFileManagerOptions = EnumSet.of( |
|
173 |
CLASSPATH, |
|
174 |
CP, |
|
175 |
SOURCEPATH, |
|
176 |
BOOTCLASSPATH, |
|
177 |
XBOOTCLASSPATH_PREPEND, |
|
178 |
XBOOTCLASSPATH_APPEND, |
|
179 |
XBOOTCLASSPATH, |
|
180 |
EXTDIRS, |
|
181 |
DJAVA_EXT_DIRS, |
|
182 |
ENDORSEDDIRS, |
|
183 |
DJAVA_ENDORSED_DIRS, |
|
184 |
PROCESSORPATH, |
|
185 |
D, |
|
186 |
S, |
|
187 |
ENCODING, |
|
188 |
SOURCE); |
|
189 |
||
190 |
static Set<OptionName> javacToolOptions = EnumSet.of( |
|
191 |
G, |
|
192 |
G_NONE, |
|
193 |
G_CUSTOM, |
|
194 |
XLINT, |
|
195 |
XLINT_CUSTOM, |
|
196 |
NOWARN, |
|
197 |
VERBOSE, |
|
198 |
DEPRECATION, |
|
168 | 199 |
PROC, |
10 | 200 |
PROCESSOR, |
201 |
IMPLICIT, |
|
202 |
SOURCE, |
|
203 |
TARGET, |
|
204 |
// VERSION, |
|
205 |
// FULLVERSION, |
|
206 |
// HELP, |
|
207 |
A, |
|
208 |
// X, |
|
209 |
// J, |
|
210 |
MOREINFO, |
|
211 |
WERROR, |
|
212 |
// COMPLEXINFERENCE, |
|
213 |
PROMPT, |
|
214 |
DOE, |
|
215 |
PRINTSOURCE, |
|
216 |
WARNUNCHECKED, |
|
217 |
XMAXERRS, |
|
218 |
XMAXWARNS, |
|
219 |
// XSTDOUT, |
|
220 |
XPRINT, |
|
221 |
XPRINTROUNDS, |
|
222 |
XPRINTPROCESSORINFO, |
|
223 |
XPREFER, |
|
224 |
O, |
|
225 |
XJCOV, |
|
226 |
XD); |
|
227 |
||
228 |
static Option[] getJavaCompilerOptions(OptionHelper helper) { |
|
229 |
return getOptions(helper, javacOptions); |
|
230 |
} |
|
231 |
||
232 |
public static Option[] getJavacFileManagerOptions(OptionHelper helper) { |
|
233 |
return getOptions(helper, javacFileManagerOptions); |
|
234 |
} |
|
235 |
||
236 |
public static Option[] getJavacToolOptions(OptionHelper helper) { |
|
237 |
return getOptions(helper, javacToolOptions); |
|
238 |
} |
|
239 |
||
240 |
static Option[] getOptions(OptionHelper helper, Set<OptionName> desired) { |
|
241 |
ListBuffer<Option> options = new ListBuffer<Option>(); |
|
242 |
for (Option option : getAll(helper)) |
|
243 |
if (desired.contains(option.getName())) |
|
244 |
options.append(option); |
|
245 |
return options.toArray(new Option[options.length()]); |
|
246 |
} |
|
247 |
||
248 |
/** |
|
168 | 249 |
* Get all the recognized options. |
250 |
* @param helper an {@code OptionHelper} to help when processing options |
|
251 |
* @return an array of options |
|
10 | 252 |
*/ |
253 |
public static Option[] getAll(final OptionHelper helper) { |
|
168 | 254 |
return new Option[] { |
10 | 255 |
new Option(G, "opt.g"), |
256 |
new Option(G_NONE, "opt.g.none") { |
|
168 | 257 |
@Override |
10 | 258 |
public boolean process(Options options, String option) { |
259 |
options.put("-g:", "none"); |
|
260 |
return false; |
|
261 |
} |
|
262 |
}, |
|
263 |
||
168 | 264 |
new Option(G_CUSTOM, "opt.g.lines.vars.source", |
265 |
Option.ChoiceKind.ANYOF, "lines", "vars", "source"), |
|
266 |
||
267 |
new XOption(XLINT, "opt.Xlint"), |
|
268 |
new XOption(XLINT_CUSTOM, "opt.Xlint.suboptlist", |
|
269 |
Option.ChoiceKind.ANYOF, getXLintChoices()), |
|
270 |
||
271 |
// -nowarn is retained for command-line backward compatibility |
|
272 |
new Option(NOWARN, "opt.nowarn") { |
|
273 |
@Override |
|
10 | 274 |
public boolean process(Options options, String option) { |
168 | 275 |
options.put("-Xlint:none", option); |
10 | 276 |
return false; |
277 |
} |
|
278 |
}, |
|
279 |
||
280 |
new Option(VERBOSE, "opt.verbose"), |
|
281 |
||
282 |
// -deprecation is retained for command-line backward compatibility |
|
283 |
new Option(DEPRECATION, "opt.deprecation") { |
|
168 | 284 |
@Override |
285 |
public boolean process(Options options, String option) { |
|
286 |
options.put("-Xlint:deprecation", option); |
|
287 |
return false; |
|
288 |
} |
|
289 |
}, |
|
10 | 290 |
|
291 |
new Option(CLASSPATH, "opt.arg.path", "opt.classpath"), |
|
292 |
new Option(CP, "opt.arg.path", "opt.classpath") { |
|
168 | 293 |
@Override |
10 | 294 |
public boolean process(Options options, String option, String arg) { |
295 |
return super.process(options, "-classpath", arg); |
|
296 |
} |
|
297 |
}, |
|
298 |
new Option(SOURCEPATH, "opt.arg.path", "opt.sourcepath"), |
|
299 |
new Option(BOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") { |
|
168 | 300 |
@Override |
10 | 301 |
public boolean process(Options options, String option, String arg) { |
302 |
options.remove("-Xbootclasspath/p:"); |
|
303 |
options.remove("-Xbootclasspath/a:"); |
|
304 |
return super.process(options, option, arg); |
|
305 |
} |
|
306 |
}, |
|
307 |
new XOption(XBOOTCLASSPATH_PREPEND,"opt.arg.path", "opt.Xbootclasspath.p"), |
|
308 |
new XOption(XBOOTCLASSPATH_APPEND, "opt.arg.path", "opt.Xbootclasspath.a"), |
|
309 |
new XOption(XBOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") { |
|
168 | 310 |
@Override |
10 | 311 |
public boolean process(Options options, String option, String arg) { |
312 |
options.remove("-Xbootclasspath/p:"); |
|
313 |
options.remove("-Xbootclasspath/a:"); |
|
314 |
return super.process(options, "-bootclasspath", arg); |
|
315 |
} |
|
316 |
}, |
|
317 |
new Option(EXTDIRS, "opt.arg.dirs", "opt.extdirs"), |
|
318 |
new XOption(DJAVA_EXT_DIRS, "opt.arg.dirs", "opt.extdirs") { |
|
168 | 319 |
@Override |
10 | 320 |
public boolean process(Options options, String option, String arg) { |
321 |
return super.process(options, "-extdirs", arg); |
|
322 |
} |
|
323 |
}, |
|
324 |
new Option(ENDORSEDDIRS, "opt.arg.dirs", "opt.endorseddirs"), |
|
325 |
new XOption(DJAVA_ENDORSED_DIRS, "opt.arg.dirs", "opt.endorseddirs") { |
|
168 | 326 |
@Override |
10 | 327 |
public boolean process(Options options, String option, String arg) { |
328 |
return super.process(options, "-endorseddirs", arg); |
|
329 |
} |
|
330 |
}, |
|
168 | 331 |
new Option(PROC, "opt.proc.none.only", |
332 |
Option.ChoiceKind.ONEOF, "none", "only"), |
|
10 | 333 |
new Option(PROCESSOR, "opt.arg.class.list", "opt.processor"), |
334 |
new Option(PROCESSORPATH, "opt.arg.path", "opt.processorpath"), |
|
335 |
new Option(D, "opt.arg.directory", "opt.d"), |
|
336 |
new Option(S, "opt.arg.directory", "opt.sourceDest"), |
|
168 | 337 |
new Option(IMPLICIT, "opt.implicit", |
338 |
Option.ChoiceKind.ONEOF, "none", "class"), |
|
10 | 339 |
new Option(ENCODING, "opt.arg.encoding", "opt.encoding"), |
340 |
new Option(SOURCE, "opt.arg.release", "opt.source") { |
|
168 | 341 |
@Override |
10 | 342 |
public boolean process(Options options, String option, String operand) { |
343 |
Source source = Source.lookup(operand); |
|
344 |
if (source == null) { |
|
345 |
helper.error("err.invalid.source", operand); |
|
346 |
return true; |
|
347 |
} |
|
348 |
return super.process(options, option, operand); |
|
349 |
} |
|
350 |
}, |
|
351 |
new Option(TARGET, "opt.arg.release", "opt.target") { |
|
168 | 352 |
@Override |
10 | 353 |
public boolean process(Options options, String option, String operand) { |
354 |
Target target = Target.lookup(operand); |
|
355 |
if (target == null) { |
|
356 |
helper.error("err.invalid.target", operand); |
|
357 |
return true; |
|
358 |
} |
|
359 |
return super.process(options, option, operand); |
|
360 |
} |
|
361 |
}, |
|
362 |
new Option(VERSION, "opt.version") { |
|
168 | 363 |
@Override |
10 | 364 |
public boolean process(Options options, String option) { |
365 |
helper.printVersion(); |
|
366 |
return super.process(options, option); |
|
367 |
} |
|
368 |
}, |
|
369 |
new HiddenOption(FULLVERSION) { |
|
168 | 370 |
@Override |
10 | 371 |
public boolean process(Options options, String option) { |
372 |
helper.printFullVersion(); |
|
373 |
return super.process(options, option); |
|
374 |
} |
|
375 |
}, |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
376 |
new HiddenOption(DIAGS) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
377 |
@Override |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
378 |
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
|
379 |
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
|
380 |
option = option.substring(option.indexOf('=') + 1); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
381 |
String diagsOption = option.contains("%") ? |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
382 |
"-XDdiagsFormat=" : |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
383 |
"-XDdiags="; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
384 |
diagsOption += option; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
385 |
if (xd.matches(diagsOption)) |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
386 |
return xd.process(options, diagsOption); |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
387 |
else |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
388 |
return false; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
389 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1996
diff
changeset
|
390 |
}, |
10 | 391 |
new Option(HELP, "opt.help") { |
168 | 392 |
@Override |
10 | 393 |
public boolean process(Options options, String option) { |
394 |
helper.printHelp(); |
|
395 |
return super.process(options, option); |
|
396 |
} |
|
397 |
}, |
|
398 |
new Option(A, "opt.arg.key.equals.value","opt.A") { |
|
168 | 399 |
@Override |
400 |
String helpSynopsis() { |
|
401 |
hasSuffix = true; |
|
402 |
return super.helpSynopsis(); |
|
403 |
} |
|
404 |
||
405 |
@Override |
|
406 |
public boolean matches(String arg) { |
|
407 |
return arg.startsWith("-A"); |
|
408 |
} |
|
10 | 409 |
|
168 | 410 |
@Override |
411 |
public boolean hasArg() { |
|
412 |
return false; |
|
413 |
} |
|
414 |
// Mapping for processor options created in |
|
415 |
// JavacProcessingEnvironment |
|
416 |
@Override |
|
417 |
public boolean process(Options options, String option) { |
|
418 |
int argLength = option.length(); |
|
419 |
if (argLength == 2) { |
|
420 |
helper.error("err.empty.A.argument"); |
|
421 |
return true; |
|
10 | 422 |
} |
168 | 423 |
int sepIndex = option.indexOf('='); |
424 |
String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) ); |
|
425 |
if (!JavacProcessingEnvironment.isValidOptionName(key)) { |
|
426 |
helper.error("err.invalid.A.key", option); |
|
427 |
return true; |
|
10 | 428 |
} |
168 | 429 |
return process(options, option, option); |
430 |
} |
|
10 | 431 |
}, |
432 |
new Option(X, "opt.X") { |
|
168 | 433 |
@Override |
10 | 434 |
public boolean process(Options options, String option) { |
435 |
helper.printXhelp(); |
|
436 |
return super.process(options, option); |
|
437 |
} |
|
438 |
}, |
|
439 |
||
440 |
// This option exists only for the purpose of documenting itself. |
|
441 |
// It's actually implemented by the launcher. |
|
442 |
new Option(J, "opt.arg.flag", "opt.J") { |
|
168 | 443 |
@Override |
10 | 444 |
String helpSynopsis() { |
445 |
hasSuffix = true; |
|
446 |
return super.helpSynopsis(); |
|
447 |
} |
|
168 | 448 |
@Override |
10 | 449 |
public boolean process(Options options, String option) { |
450 |
throw new AssertionError |
|
451 |
("the -J flag should be caught by the launcher."); |
|
452 |
} |
|
453 |
}, |
|
454 |
||
455 |
// stop after parsing and attributing. |
|
456 |
// new HiddenOption("-attrparseonly"), |
|
457 |
||
458 |
// new Option("-moreinfo", "opt.moreinfo") { |
|
459 |
new HiddenOption(MOREINFO) { |
|
168 | 460 |
@Override |
10 | 461 |
public boolean process(Options options, String option) { |
462 |
Type.moreInfo = true; |
|
463 |
return super.process(options, option); |
|
464 |
} |
|
465 |
}, |
|
466 |
||
467 |
// treat warnings as errors |
|
1996 | 468 |
new Option(WERROR, "opt.Werror"), |
10 | 469 |
|
470 |
// use complex inference from context in the position of a method call argument |
|
471 |
new HiddenOption(COMPLEXINFERENCE), |
|
472 |
||
473 |
// generare source stubs |
|
474 |
// new HiddenOption("-stubs"), |
|
475 |
||
476 |
// relax some constraints to allow compiling from stubs |
|
477 |
// new HiddenOption("-relax"), |
|
478 |
||
479 |
// output source after translating away inner classes |
|
480 |
// new Option("-printflat", "opt.printflat"), |
|
481 |
// new HiddenOption("-printflat"), |
|
482 |
||
483 |
// display scope search details |
|
484 |
// new Option("-printsearch", "opt.printsearch"), |
|
485 |
// new HiddenOption("-printsearch"), |
|
486 |
||
487 |
// prompt after each error |
|
488 |
// new Option("-prompt", "opt.prompt"), |
|
489 |
new HiddenOption(PROMPT), |
|
490 |
||
491 |
// dump stack on error |
|
492 |
new HiddenOption(DOE), |
|
493 |
||
494 |
// output source after type erasure |
|
495 |
// new Option("-s", "opt.s"), |
|
496 |
new HiddenOption(PRINTSOURCE), |
|
497 |
||
498 |
// output shrouded class files |
|
499 |
// new Option("-scramble", "opt.scramble"), |
|
500 |
// new Option("-scrambleall", "opt.scrambleall"), |
|
501 |
||
502 |
// display warnings for generic unchecked operations |
|
503 |
new HiddenOption(WARNUNCHECKED) { |
|
168 | 504 |
@Override |
10 | 505 |
public boolean process(Options options, String option) { |
506 |
options.put("-Xlint:unchecked", option); |
|
507 |
return false; |
|
508 |
} |
|
509 |
}, |
|
510 |
||
511 |
new XOption(XMAXERRS, "opt.arg.number", "opt.maxerrs"), |
|
512 |
new XOption(XMAXWARNS, "opt.arg.number", "opt.maxwarns"), |
|
513 |
new XOption(XSTDOUT, "opt.arg.file", "opt.Xstdout") { |
|
168 | 514 |
@Override |
10 | 515 |
public boolean process(Options options, String option, String arg) { |
516 |
try { |
|
517 |
helper.setOut(new PrintWriter(new FileWriter(arg), true)); |
|
518 |
} catch (java.io.IOException e) { |
|
519 |
helper.error("err.error.writing.file", arg, e); |
|
520 |
return true; |
|
521 |
} |
|
522 |
return super.process(options, option, arg); |
|
523 |
} |
|
524 |
}, |
|
525 |
||
526 |
new XOption(XPRINT, "opt.print"), |
|
527 |
||
528 |
new XOption(XPRINTROUNDS, "opt.printRounds"), |
|
529 |
||
530 |
new XOption(XPRINTPROCESSORINFO, "opt.printProcessorInfo"), |
|
531 |
||
168 | 532 |
new XOption(XPREFER, "opt.prefer", |
533 |
Option.ChoiceKind.ONEOF, "source", "newer"), |
|
10 | 534 |
|
535 |
/* -O is a no-op, accepted for backward compatibility. */ |
|
536 |
new HiddenOption(O), |
|
537 |
||
538 |
/* -Xjcov produces tables to support the code coverage tool jcov. */ |
|
539 |
new HiddenOption(XJCOV), |
|
540 |
||
541 |
/* This is a back door to the compiler's option table. |
|
542 |
* -XDx=y sets the option x to the value y. |
|
543 |
* -XDx sets the option x to the value x. |
|
544 |
*/ |
|
545 |
new HiddenOption(XD) { |
|
546 |
String s; |
|
168 | 547 |
@Override |
10 | 548 |
public boolean matches(String s) { |
549 |
this.s = s; |
|
550 |
return s.startsWith(name.optionName); |
|
551 |
} |
|
168 | 552 |
@Override |
10 | 553 |
public boolean process(Options options, String option) { |
554 |
s = s.substring(name.optionName.length()); |
|
555 |
int eq = s.indexOf('='); |
|
556 |
String key = (eq < 0) ? s : s.substring(0, eq); |
|
557 |
String value = (eq < 0) ? s : s.substring(eq+1); |
|
558 |
options.put(key, value); |
|
559 |
return false; |
|
560 |
} |
|
561 |
}, |
|
562 |
||
563 |
/* |
|
564 |
* TODO: With apt, the matches method accepts anything if |
|
565 |
* -XclassAsDecls is used; code elsewhere does the lookup to |
|
566 |
* see if the class name is both legal and found. |
|
567 |
* |
|
568 |
* In apt, the process method adds the candiate class file |
|
569 |
* name to a separate list. |
|
570 |
*/ |
|
571 |
new HiddenOption(SOURCEFILE) { |
|
572 |
String s; |
|
168 | 573 |
@Override |
10 | 574 |
public boolean matches(String s) { |
575 |
this.s = s; |
|
576 |
return s.endsWith(".java") // Java source file |
|
577 |
|| SourceVersion.isName(s); // Legal type name |
|
578 |
} |
|
168 | 579 |
@Override |
10 | 580 |
public boolean process(Options options, String option) { |
581 |
if (s.endsWith(".java") ) { |
|
582 |
File f = new File(s); |
|
583 |
if (!f.exists()) { |
|
584 |
helper.error("err.file.not.found", f); |
|
585 |
return true; |
|
586 |
} |
|
587 |
if (!f.isFile()) { |
|
588 |
helper.error("err.file.not.file", f); |
|
589 |
return true; |
|
590 |
} |
|
591 |
helper.addFile(f); |
|
592 |
} |
|
593 |
else |
|
594 |
helper.addClassName(s); |
|
595 |
return false; |
|
596 |
} |
|
597 |
}, |
|
598 |
}; |
|
599 |
} |
|
600 |
||
3661 | 601 |
private static Map<String,Boolean> getXLintChoices() { |
602 |
Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>(); |
|
603 |
choices.put("all", false); |
|
168 | 604 |
for (Lint.LintCategory c : Lint.LintCategory.values()) |
3661 | 605 |
choices.put(c.option, c.hidden); |
168 | 606 |
for (Lint.LintCategory c : Lint.LintCategory.values()) |
3661 | 607 |
choices.put("-" + c.option, c.hidden); |
608 |
choices.put("none", false); |
|
168 | 609 |
return choices; |
610 |
} |
|
611 |
||
10 | 612 |
} |