src/share/classes/com/sun/tools/javac/main/Option.java

changeset 1442
fcf89720ae71
parent 1416
c0f0c41cafa0
child 1463
67b01d295cd2
equal deleted inserted replaced
1441:c78acf6c2f3e 1442:fcf89720ae71
165 IMPLICIT("-implicit:", "opt.implicit", STANDARD, BASIC, ONEOF, "none", "class"), 165 IMPLICIT("-implicit:", "opt.implicit", STANDARD, BASIC, ONEOF, "none", "class"),
166 166
167 ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER) { 167 ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER) {
168 @Override 168 @Override
169 public boolean process(OptionHelper helper, String option, String operand) { 169 public boolean process(OptionHelper helper, String option, String operand) {
170 // System.err.println("process encoding " + operand);
171 return super.process(helper, option, operand); 170 return super.process(helper, option, operand);
172 } 171 }
173 172
174 }, 173 },
175 174
244 log.printNewline(); 243 log.printNewline();
245 return super.process(helper, option); 244 return super.process(helper, option);
246 } 245 }
247 }, 246 },
248 247
249 A("-A", "opt.arg.key.equals.value", "opt.A", STANDARD, BASIC) { 248 A("-A", "opt.arg.key.equals.value", "opt.A", STANDARD, BASIC, true) {
250 { hasSuffix = true; }
251
252 @Override 249 @Override
253 public boolean matches(String arg) { 250 public boolean matches(String arg) {
254 return arg.startsWith("-A"); 251 return arg.startsWith("-A");
255 } 252 }
256 253
291 }, 288 },
292 289
293 // This option exists only for the purpose of documenting itself. 290 // This option exists only for the purpose of documenting itself.
294 // It's actually implemented by the launcher. 291 // It's actually implemented by the launcher.
295 J("-J", "opt.arg.flag", "opt.J", STANDARD, INFO) { 292 J("-J", "opt.arg.flag", "opt.J", STANDARD, INFO) {
296 { hasSuffix = true; }
297
298 @Override 293 @Override
299 public boolean process(OptionHelper helper, String option) { 294 public boolean process(OptionHelper helper, String option) {
300 throw new AssertionError 295 throw new AssertionError
301 ("the -J flag should be caught by the launcher."); 296 ("the -J flag should be caught by the launcher.");
302 } 297 }
303 }, 298 },
304 299
305 // stop after parsing and attributing.
306 // new HiddenOption("-attrparseonly"),
307
308 // new Option("-moreinfo", "opt.moreinfo") {
309 MOREINFO("-moreinfo", null, HIDDEN, BASIC) { 300 MOREINFO("-moreinfo", null, HIDDEN, BASIC) {
310 @Override 301 @Override
311 public boolean process(OptionHelper helper, String option) { 302 public boolean process(OptionHelper helper, String option) {
312 Type.moreInfo = true; 303 Type.moreInfo = true;
313 return super.process(helper, option); 304 return super.process(helper, option);
314 } 305 }
315 }, 306 },
316 307
317 // treat warnings as errors 308 // treat warnings as errors
318 WERROR("-Werror", "opt.Werror", STANDARD, BASIC), 309 WERROR("-Werror", "opt.Werror", STANDARD, BASIC),
319
320 // // use complex inference from context in the position of a method call argument
321 // COMPLEXINFERENCE("-complexinference", null, HIDDEN, BASIC),
322
323 // generare source stubs
324 // new HiddenOption("-stubs"),
325
326 // relax some constraints to allow compiling from stubs
327 // new HiddenOption("-relax"),
328
329 // output source after translating away inner classes
330 // new Option("-printflat", "opt.printflat"),
331 // new HiddenOption("-printflat"),
332
333 // display scope search details
334 // new Option("-printsearch", "opt.printsearch"),
335 // new HiddenOption("-printsearch"),
336 310
337 // prompt after each error 311 // prompt after each error
338 // new Option("-prompt", "opt.prompt"), 312 // new Option("-prompt", "opt.prompt"),
339 PROMPT("-prompt", null, HIDDEN, BASIC), 313 PROMPT("-prompt", null, HIDDEN, BASIC),
340 314
341 // dump stack on error 315 // dump stack on error
342 DOE("-doe", null, HIDDEN, BASIC), 316 DOE("-doe", null, HIDDEN, BASIC),
343 317
344 // output source after type erasure 318 // output source after type erasure
345 // new Option("-s", "opt.s"),
346 PRINTSOURCE("-printsource", null, HIDDEN, BASIC), 319 PRINTSOURCE("-printsource", null, HIDDEN, BASIC),
347
348 // output shrouded class files
349 // new Option("-scramble", "opt.scramble"),
350 // new Option("-scrambleall", "opt.scrambleall"),
351 320
352 // display warnings for generic unchecked operations 321 // display warnings for generic unchecked operations
353 WARNUNCHECKED("-warnunchecked", null, HIDDEN, BASIC) { 322 WARNUNCHECKED("-warnunchecked", null, HIDDEN, BASIC) {
354 @Override 323 @Override
355 public boolean process(OptionHelper helper, String option) { 324 public boolean process(OptionHelper helper, String option) {
406 /* This is a back door to the compiler's option table. 375 /* This is a back door to the compiler's option table.
407 * -XDx=y sets the option x to the value y. 376 * -XDx=y sets the option x to the value y.
408 * -XDx sets the option x to the value x. 377 * -XDx sets the option x to the value x.
409 */ 378 */
410 XD("-XD", null, HIDDEN, BASIC) { 379 XD("-XD", null, HIDDEN, BASIC) {
411 String s;
412 @Override 380 @Override
413 public boolean matches(String s) { 381 public boolean matches(String s) {
414 this.s = s;
415 return s.startsWith(text); 382 return s.startsWith(text);
416 } 383 }
417 @Override 384 @Override
418 public boolean process(OptionHelper helper, String option) { 385 public boolean process(OptionHelper helper, String option) {
419 s = s.substring(text.length()); 386 option = option.substring(text.length());
420 int eq = s.indexOf('='); 387 int eq = option.indexOf('=');
421 String key = (eq < 0) ? s : s.substring(0, eq); 388 String key = (eq < 0) ? option : option.substring(0, eq);
422 String value = (eq < 0) ? s : s.substring(eq+1); 389 String value = (eq < 0) ? option : option.substring(eq+1);
423 helper.put(key, value); 390 helper.put(key, value);
424 return false; 391 return false;
425 } 392 }
426 }, 393 },
427 394
428 // This option exists only for the purpose of documenting itself. 395 // This option exists only for the purpose of documenting itself.
429 // It's actually implemented by the CommandLine class. 396 // It's actually implemented by the CommandLine class.
430 AT("@", "opt.arg.file", "opt.AT", STANDARD, INFO) { 397 AT("@", "opt.arg.file", "opt.AT", STANDARD, INFO) {
431 { hasSuffix = true; }
432
433 @Override 398 @Override
434 public boolean process(OptionHelper helper, String option) { 399 public boolean process(OptionHelper helper, String option) {
435 throw new AssertionError("the @ flag should be caught by CommandLine."); 400 throw new AssertionError("the @ flag should be caught by CommandLine.");
436 } 401 }
437 }, 402 },
443 * 408 *
444 * In apt, the process method adds the candidate class file 409 * In apt, the process method adds the candidate class file
445 * name to a separate list. 410 * name to a separate list.
446 */ 411 */
447 SOURCEFILE("sourcefile", null, HIDDEN, INFO) { 412 SOURCEFILE("sourcefile", null, HIDDEN, INFO) {
448 String s;
449 @Override 413 @Override
450 public boolean matches(String s) { 414 public boolean matches(String s) {
451 this.s = s;
452 return s.endsWith(".java") // Java source file 415 return s.endsWith(".java") // Java source file
453 || SourceVersion.isName(s); // Legal type name 416 || SourceVersion.isName(s); // Legal type name
454 } 417 }
455 @Override 418 @Override
456 public boolean process(OptionHelper helper, String option) { 419 public boolean process(OptionHelper helper, String option) {
457 if (s.endsWith(".java") ) { 420 if (option.endsWith(".java") ) {
458 File f = new File(s); 421 File f = new File(option);
459 if (!f.exists()) { 422 if (!f.exists()) {
460 helper.error("err.file.not.found", f); 423 helper.error("err.file.not.found", f);
461 return true; 424 return true;
462 } 425 }
463 if (!f.isFile()) { 426 if (!f.isFile()) {
464 helper.error("err.file.not.file", f); 427 helper.error("err.file.not.file", f);
465 return true; 428 return true;
466 } 429 }
467 helper.addFile(f); 430 helper.addFile(f);
468 } 431 } else {
469 else 432 helper.addClassName(option);
470 helper.addClassName(s); 433 }
471 return false; 434 return false;
472 } 435 }
473 }; 436 };
474 437
475 /** The kind of an Option. This is used by the -help and -X options. */ 438 /** The kind of an Option. This is used by the -help and -X options. */
519 */ 482 */
520 final String descrKey; 483 final String descrKey;
521 484
522 /** Suffix option (-foo=bar or -foo:bar) 485 /** Suffix option (-foo=bar or -foo:bar)
523 */ 486 */
524 boolean hasSuffix; 487 final boolean hasSuffix;
525 488
526 /** The kind of choices for this option, if any. 489 /** The kind of choices for this option, if any.
527 */ 490 */
528 final ChoiceKind choiceKind; 491 final ChoiceKind choiceKind;
529 492
533 final Map<String,Boolean> choices; 496 final Map<String,Boolean> choices;
534 497
535 498
536 Option(String text, String descrKey, 499 Option(String text, String descrKey,
537 OptionKind kind, OptionGroup group) { 500 OptionKind kind, OptionGroup group) {
538 this(text, null, descrKey, kind, group, null, null); 501 this(text, null, descrKey, kind, group, null, null, false);
539 } 502 }
540 503
541 Option(String text, String argsNameKey, String descrKey, 504 Option(String text, String argsNameKey, String descrKey,
542 OptionKind kind, OptionGroup group) { 505 OptionKind kind, OptionGroup group) {
543 this(text, argsNameKey, descrKey, kind, group, null, null); 506 this(text, argsNameKey, descrKey, kind, group, null, null, false);
507 }
508
509 Option(String text, String argsNameKey, String descrKey,
510 OptionKind kind, OptionGroup group, boolean doHasSuffix) {
511 this(text, argsNameKey, descrKey, kind, group, null, null, doHasSuffix);
544 } 512 }
545 513
546 Option(String text, String descrKey, 514 Option(String text, String descrKey,
547 OptionKind kind, OptionGroup group, 515 OptionKind kind, OptionGroup group,
548 ChoiceKind choiceKind, Map<String,Boolean> choices) { 516 ChoiceKind choiceKind, Map<String,Boolean> choices) {
549 this(text, null, descrKey, kind, group, choiceKind, choices); 517 this(text, null, descrKey, kind, group, choiceKind, choices, false);
550 } 518 }
551 519
552 Option(String text, String descrKey, 520 Option(String text, String descrKey,
553 OptionKind kind, OptionGroup group, 521 OptionKind kind, OptionGroup group,
554 ChoiceKind choiceKind, String... choices) { 522 ChoiceKind choiceKind, String... choices) {
555 this(text, null, descrKey, kind, group, choiceKind, createChoices(choices)); 523 this(text, null, descrKey, kind, group, choiceKind,
524 createChoices(choices), false);
556 } 525 }
557 // where 526 // where
558 private static Map<String,Boolean> createChoices(String... choices) { 527 private static Map<String,Boolean> createChoices(String... choices) {
559 Map<String,Boolean> map = new LinkedHashMap<String,Boolean>(); 528 Map<String,Boolean> map = new LinkedHashMap<String,Boolean>();
560 for (String c: choices) 529 for (String c: choices)
562 return map; 531 return map;
563 } 532 }
564 533
565 private Option(String text, String argsNameKey, String descrKey, 534 private Option(String text, String argsNameKey, String descrKey,
566 OptionKind kind, OptionGroup group, 535 OptionKind kind, OptionGroup group,
567 ChoiceKind choiceKind, Map<String,Boolean> choices) { 536 ChoiceKind choiceKind, Map<String,Boolean> choices,
537 boolean doHasSuffix) {
568 this.text = text; 538 this.text = text;
569 this.argsNameKey = argsNameKey; 539 this.argsNameKey = argsNameKey;
570 this.descrKey = descrKey; 540 this.descrKey = descrKey;
571 this.kind = kind; 541 this.kind = kind;
572 this.group = group; 542 this.group = group;
573 this.choiceKind = choiceKind; 543 this.choiceKind = choiceKind;
574 this.choices = choices; 544 this.choices = choices;
575 char lastChar = text.charAt(text.length()-1); 545 char lastChar = text.charAt(text.length()-1);
576 hasSuffix = lastChar == ':' || lastChar == '='; 546 this.hasSuffix = doHasSuffix || lastChar == ':' || lastChar == '=';
577 } 547 }
578 548
579 public String getText() { 549 public String getText() {
580 return text; 550 return text;
581 } 551 }

mercurial