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

Wed, 02 Jul 2008 12:56:02 -0700

author
xdono
date
Wed, 02 Jul 2008 12:56:02 -0700
changeset 54
eaf608c64fec
parent 11
b66d15dfd001
child 104
5e89c4ca637c
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

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

mercurial