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