243 options.append(option); |
245 options.append(option); |
244 return options.toArray(new Option[options.length()]); |
246 return options.toArray(new Option[options.length()]); |
245 } |
247 } |
246 |
248 |
247 /** |
249 /** |
248 * @param out the writer to use for diagnostic output |
250 * Get all the recognized options. |
|
251 * @param helper an {@code OptionHelper} to help when processing options |
|
252 * @return an array of options |
249 */ |
253 */ |
250 public static Option[] getAll(final OptionHelper helper) { |
254 public static Option[] getAll(final OptionHelper helper) { |
251 return new Option[]{ |
255 return new Option[] { |
252 new Option(G, "opt.g"), |
256 new Option(G, "opt.g"), |
253 new Option(G_NONE, "opt.g.none") { |
257 new Option(G_NONE, "opt.g.none") { |
|
258 @Override |
254 public boolean process(Options options, String option) { |
259 public boolean process(Options options, String option) { |
255 options.put("-g:", "none"); |
260 options.put("-g:", "none"); |
256 return false; |
261 return false; |
257 } |
262 } |
258 }, |
263 }, |
259 |
264 |
260 new Option(G_CUSTOM, "opt.g.lines.vars.source") { |
265 new Option(G_CUSTOM, "opt.g.lines.vars.source", |
261 public boolean matches(String s) { |
266 Option.ChoiceKind.ANYOF, "lines", "vars", "source"), |
262 return s.startsWith("-g:"); |
|
263 } |
|
264 public boolean process(Options options, String option) { |
|
265 String suboptions = option.substring(3); |
|
266 options.put("-g:", suboptions); |
|
267 // enter all the -g suboptions as "-g:suboption" |
|
268 for (StringTokenizer t = new StringTokenizer(suboptions, ","); t.hasMoreTokens(); ) { |
|
269 String tok = t.nextToken(); |
|
270 String opt = "-g:" + tok; |
|
271 options.put(opt, opt); |
|
272 } |
|
273 return false; |
|
274 } |
|
275 }, |
|
276 |
267 |
277 new XOption(XLINT, "opt.Xlint"), |
268 new XOption(XLINT, "opt.Xlint"), |
278 new XOption(XLINT_CUSTOM, "opt.Xlint.suboptlist") { |
269 new XOption(XLINT_CUSTOM, "opt.Xlint.suboptlist", |
279 public boolean matches(String s) { |
270 Option.ChoiceKind.ANYOF, getXLintChoices()), |
280 return s.startsWith("-Xlint:"); |
|
281 } |
|
282 public boolean process(Options options, String option) { |
|
283 String suboptions = option.substring(7); |
|
284 options.put("-Xlint:", suboptions); |
|
285 // enter all the -Xlint suboptions as "-Xlint:suboption" |
|
286 for (StringTokenizer t = new StringTokenizer(suboptions, ","); t.hasMoreTokens(); ) { |
|
287 String tok = t.nextToken(); |
|
288 String opt = "-Xlint:" + tok; |
|
289 options.put(opt, opt); |
|
290 } |
|
291 return false; |
|
292 } |
|
293 }, |
|
294 |
271 |
295 // -nowarn is retained for command-line backward compatibility |
272 // -nowarn is retained for command-line backward compatibility |
296 new Option(NOWARN, "opt.nowarn") { |
273 new Option(NOWARN, "opt.nowarn") { |
297 public boolean process(Options options, String option) { |
274 @Override |
298 options.put("-Xlint:none", option); |
275 public boolean process(Options options, String option) { |
299 return false; |
276 options.put("-Xlint:none", option); |
300 } |
277 return false; |
301 }, |
278 } |
|
279 }, |
302 |
280 |
303 new Option(VERBOSE, "opt.verbose"), |
281 new Option(VERBOSE, "opt.verbose"), |
304 |
282 |
305 // -deprecation is retained for command-line backward compatibility |
283 // -deprecation is retained for command-line backward compatibility |
306 new Option(DEPRECATION, "opt.deprecation") { |
284 new Option(DEPRECATION, "opt.deprecation") { |
307 public boolean process(Options options, String option) { |
285 @Override |
308 options.put("-Xlint:deprecation", option); |
286 public boolean process(Options options, String option) { |
309 return false; |
287 options.put("-Xlint:deprecation", option); |
310 } |
288 return false; |
311 }, |
289 } |
|
290 }, |
312 |
291 |
313 new Option(CLASSPATH, "opt.arg.path", "opt.classpath"), |
292 new Option(CLASSPATH, "opt.arg.path", "opt.classpath"), |
314 new Option(CP, "opt.arg.path", "opt.classpath") { |
293 new Option(CP, "opt.arg.path", "opt.classpath") { |
|
294 @Override |
315 public boolean process(Options options, String option, String arg) { |
295 public boolean process(Options options, String option, String arg) { |
316 return super.process(options, "-classpath", arg); |
296 return super.process(options, "-classpath", arg); |
317 } |
297 } |
318 }, |
298 }, |
319 new Option(SOURCEPATH, "opt.arg.path", "opt.sourcepath"), |
299 new Option(SOURCEPATH, "opt.arg.path", "opt.sourcepath"), |
320 new Option(BOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") { |
300 new Option(BOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") { |
|
301 @Override |
321 public boolean process(Options options, String option, String arg) { |
302 public boolean process(Options options, String option, String arg) { |
322 options.remove("-Xbootclasspath/p:"); |
303 options.remove("-Xbootclasspath/p:"); |
323 options.remove("-Xbootclasspath/a:"); |
304 options.remove("-Xbootclasspath/a:"); |
324 return super.process(options, option, arg); |
305 return super.process(options, option, arg); |
325 } |
306 } |
326 }, |
307 }, |
327 new XOption(XBOOTCLASSPATH_PREPEND,"opt.arg.path", "opt.Xbootclasspath.p"), |
308 new XOption(XBOOTCLASSPATH_PREPEND,"opt.arg.path", "opt.Xbootclasspath.p"), |
328 new XOption(XBOOTCLASSPATH_APPEND, "opt.arg.path", "opt.Xbootclasspath.a"), |
309 new XOption(XBOOTCLASSPATH_APPEND, "opt.arg.path", "opt.Xbootclasspath.a"), |
329 new XOption(XBOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") { |
310 new XOption(XBOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") { |
|
311 @Override |
330 public boolean process(Options options, String option, String arg) { |
312 public boolean process(Options options, String option, String arg) { |
331 options.remove("-Xbootclasspath/p:"); |
313 options.remove("-Xbootclasspath/p:"); |
332 options.remove("-Xbootclasspath/a:"); |
314 options.remove("-Xbootclasspath/a:"); |
333 return super.process(options, "-bootclasspath", arg); |
315 return super.process(options, "-bootclasspath", arg); |
334 } |
316 } |
335 }, |
317 }, |
336 new Option(EXTDIRS, "opt.arg.dirs", "opt.extdirs"), |
318 new Option(EXTDIRS, "opt.arg.dirs", "opt.extdirs"), |
337 new XOption(DJAVA_EXT_DIRS, "opt.arg.dirs", "opt.extdirs") { |
319 new XOption(DJAVA_EXT_DIRS, "opt.arg.dirs", "opt.extdirs") { |
|
320 @Override |
338 public boolean process(Options options, String option, String arg) { |
321 public boolean process(Options options, String option, String arg) { |
339 return super.process(options, "-extdirs", arg); |
322 return super.process(options, "-extdirs", arg); |
340 } |
323 } |
341 }, |
324 }, |
342 new Option(ENDORSEDDIRS, "opt.arg.dirs", "opt.endorseddirs"), |
325 new Option(ENDORSEDDIRS, "opt.arg.dirs", "opt.endorseddirs"), |
343 new XOption(DJAVA_ENDORSED_DIRS, "opt.arg.dirs", "opt.endorseddirs") { |
326 new XOption(DJAVA_ENDORSED_DIRS, "opt.arg.dirs", "opt.endorseddirs") { |
|
327 @Override |
344 public boolean process(Options options, String option, String arg) { |
328 public boolean process(Options options, String option, String arg) { |
345 return super.process(options, "-endorseddirs", arg); |
329 return super.process(options, "-endorseddirs", arg); |
346 } |
330 } |
347 }, |
331 }, |
348 new Option(PROC_CUSTOM, "opt.proc.none.only") { |
332 new Option(PROC, "opt.proc.none.only", |
349 public boolean matches(String s) { |
333 Option.ChoiceKind.ONEOF, "none", "only"), |
350 return s.equals("-proc:none") || s.equals("-proc:only"); |
|
351 } |
|
352 |
|
353 public boolean process(Options options, String option) { |
|
354 if (option.equals("-proc:none")) { |
|
355 options.remove("-proc:only"); |
|
356 } else { |
|
357 options.remove("-proc:none"); |
|
358 } |
|
359 options.put(option, option); |
|
360 return false; |
|
361 } |
|
362 }, |
|
363 new Option(PROCESSOR, "opt.arg.class.list", "opt.processor"), |
334 new Option(PROCESSOR, "opt.arg.class.list", "opt.processor"), |
364 new Option(PROCESSORPATH, "opt.arg.path", "opt.processorpath"), |
335 new Option(PROCESSORPATH, "opt.arg.path", "opt.processorpath"), |
365 new Option(D, "opt.arg.directory", "opt.d"), |
336 new Option(D, "opt.arg.directory", "opt.d"), |
366 new Option(S, "opt.arg.directory", "opt.sourceDest"), |
337 new Option(S, "opt.arg.directory", "opt.sourceDest"), |
367 new Option(IMPLICIT, "opt.implicit") { |
338 new Option(IMPLICIT, "opt.implicit", |
368 public boolean matches(String s) { |
339 Option.ChoiceKind.ONEOF, "none", "class"), |
369 return s.equals("-implicit:none") || s.equals("-implicit:class"); |
|
370 } |
|
371 public boolean process(Options options, String option, String operand) { |
|
372 int sep = option.indexOf(":"); |
|
373 options.put(option.substring(0, sep), option.substring(sep+1)); |
|
374 options.put(option,option); |
|
375 return false; |
|
376 } |
|
377 }, |
|
378 new Option(ENCODING, "opt.arg.encoding", "opt.encoding"), |
340 new Option(ENCODING, "opt.arg.encoding", "opt.encoding"), |
379 new Option(SOURCE, "opt.arg.release", "opt.source") { |
341 new Option(SOURCE, "opt.arg.release", "opt.source") { |
|
342 @Override |
380 public boolean process(Options options, String option, String operand) { |
343 public boolean process(Options options, String option, String operand) { |
381 Source source = Source.lookup(operand); |
344 Source source = Source.lookup(operand); |
382 if (source == null) { |
345 if (source == null) { |
383 helper.error("err.invalid.source", operand); |
346 helper.error("err.invalid.source", operand); |
384 return true; |
347 return true; |
385 } |
348 } |
386 return super.process(options, option, operand); |
349 return super.process(options, option, operand); |
387 } |
350 } |
388 }, |
351 }, |
389 new Option(TARGET, "opt.arg.release", "opt.target") { |
352 new Option(TARGET, "opt.arg.release", "opt.target") { |
|
353 @Override |
390 public boolean process(Options options, String option, String operand) { |
354 public boolean process(Options options, String option, String operand) { |
391 Target target = Target.lookup(operand); |
355 Target target = Target.lookup(operand); |
392 if (target == null) { |
356 if (target == null) { |
393 helper.error("err.invalid.target", operand); |
357 helper.error("err.invalid.target", operand); |
394 return true; |
358 return true; |
395 } |
359 } |
396 return super.process(options, option, operand); |
360 return super.process(options, option, operand); |
397 } |
361 } |
398 }, |
362 }, |
399 new Option(VERSION, "opt.version") { |
363 new Option(VERSION, "opt.version") { |
|
364 @Override |
400 public boolean process(Options options, String option) { |
365 public boolean process(Options options, String option) { |
401 helper.printVersion(); |
366 helper.printVersion(); |
402 return super.process(options, option); |
367 return super.process(options, option); |
403 } |
368 } |
404 }, |
369 }, |
405 new HiddenOption(FULLVERSION) { |
370 new HiddenOption(FULLVERSION) { |
|
371 @Override |
406 public boolean process(Options options, String option) { |
372 public boolean process(Options options, String option) { |
407 helper.printFullVersion(); |
373 helper.printFullVersion(); |
408 return super.process(options, option); |
374 return super.process(options, option); |
409 } |
375 } |
410 }, |
376 }, |
411 new Option(HELP, "opt.help") { |
377 new Option(HELP, "opt.help") { |
|
378 @Override |
412 public boolean process(Options options, String option) { |
379 public boolean process(Options options, String option) { |
413 helper.printHelp(); |
380 helper.printHelp(); |
414 return super.process(options, option); |
381 return super.process(options, option); |
415 } |
382 } |
416 }, |
383 }, |
417 new Option(A, "opt.arg.key.equals.value","opt.A") { |
384 new Option(A, "opt.arg.key.equals.value","opt.A") { |
418 String helpSynopsis() { |
385 @Override |
419 hasSuffix = true; |
386 String helpSynopsis() { |
420 return super.helpSynopsis(); |
387 hasSuffix = true; |
|
388 return super.helpSynopsis(); |
|
389 } |
|
390 |
|
391 @Override |
|
392 public boolean matches(String arg) { |
|
393 return arg.startsWith("-A"); |
|
394 } |
|
395 |
|
396 @Override |
|
397 public boolean hasArg() { |
|
398 return false; |
|
399 } |
|
400 // Mapping for processor options created in |
|
401 // JavacProcessingEnvironment |
|
402 @Override |
|
403 public boolean process(Options options, String option) { |
|
404 int argLength = option.length(); |
|
405 if (argLength == 2) { |
|
406 helper.error("err.empty.A.argument"); |
|
407 return true; |
421 } |
408 } |
422 |
409 int sepIndex = option.indexOf('='); |
423 public boolean matches(String arg) { |
410 String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) ); |
424 return arg.startsWith("-A"); |
411 if (!JavacProcessingEnvironment.isValidOptionName(key)) { |
|
412 helper.error("err.invalid.A.key", option); |
|
413 return true; |
425 } |
414 } |
426 |
415 return process(options, option, option); |
427 public boolean hasArg() { |
416 } |
428 return false; |
|
429 } |
|
430 // Mapping for processor options created in |
|
431 // JavacProcessingEnvironment |
|
432 public boolean process(Options options, String option) { |
|
433 int argLength = option.length(); |
|
434 if (argLength == 2) { |
|
435 helper.error("err.empty.A.argument"); |
|
436 return true; |
|
437 } |
|
438 int sepIndex = option.indexOf('='); |
|
439 String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) ); |
|
440 if (!JavacProcessingEnvironment.isValidOptionName(key)) { |
|
441 helper.error("err.invalid.A.key", option); |
|
442 return true; |
|
443 } |
|
444 return process(options, option, option); |
|
445 } |
|
446 }, |
417 }, |
447 new Option(X, "opt.X") { |
418 new Option(X, "opt.X") { |
|
419 @Override |
448 public boolean process(Options options, String option) { |
420 public boolean process(Options options, String option) { |
449 helper.printXhelp(); |
421 helper.printXhelp(); |
450 return super.process(options, option); |
422 return super.process(options, option); |
451 } |
423 } |
452 }, |
424 }, |
453 |
425 |
454 // This option exists only for the purpose of documenting itself. |
426 // This option exists only for the purpose of documenting itself. |
455 // It's actually implemented by the launcher. |
427 // It's actually implemented by the launcher. |
456 new Option(J, "opt.arg.flag", "opt.J") { |
428 new Option(J, "opt.arg.flag", "opt.J") { |
|
429 @Override |
457 String helpSynopsis() { |
430 String helpSynopsis() { |
458 hasSuffix = true; |
431 hasSuffix = true; |
459 return super.helpSynopsis(); |
432 return super.helpSynopsis(); |
460 } |
433 } |
|
434 @Override |
461 public boolean process(Options options, String option) { |
435 public boolean process(Options options, String option) { |
462 throw new AssertionError |
436 throw new AssertionError |
463 ("the -J flag should be caught by the launcher."); |
437 ("the -J flag should be caught by the launcher."); |
464 } |
438 } |
465 }, |
439 }, |