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

Tue, 08 Nov 2011 17:06:58 -0800

author
jjg
date
Tue, 08 Nov 2011 17:06:58 -0800
changeset 1136
ae361e7f435a
parent 962
0ff2bbd38f10
permissions
-rw-r--r--

7108669: cleanup Log methods for direct printing to streams
Reviewed-by: mcimadamore

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

mercurial