--- a/langtools/src/share/classes/com/sun/tools/javac/main/JavacOption.java Tue Dec 13 11:21:28 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,299 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.tools.javac.main;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import com.sun.tools.javac.util.Log;
-import com.sun.tools.javac.util.Log.PrefixKind;
-import com.sun.tools.javac.util.Log.WriterKind;
-import com.sun.tools.javac.util.Options;
-
-/**
- * TODO: describe com.sun.tools.javac.main.JavacOption
- *
- * <p><b>This is NOT part of any supported API.
- * If you write code that depends on this, you do so at your own
- * risk. This code and its internal interfaces are subject to change
- * or deletion without notice.</b></p>
- */
-public interface JavacOption {
-
- OptionKind getKind();
-
- /** Does this option take a (separate) operand?
- * @return true if this option takes a separate operand
- */
- boolean hasArg();
-
- /** Does argument string match option pattern?
- * @param arg the command line argument string
- * @return true if {@code arg} matches this option
- */
- boolean matches(String arg);
-
- /** Process an option with an argument.
- * @param options the accumulated set of analyzed options
- * @param option the option to be processed
- * @param arg the arg for the option to be processed
- * @return true if an error was detected
- */
- boolean process(Options options, String option, String arg);
-
- /** Process the option with no argument.
- * @param options the accumulated set of analyzed options
- * @param option the option to be processed
- * @return true if an error was detected
- */
- boolean process(Options options, String option);
-
- OptionName getName();
-
- enum OptionKind {
- NORMAL,
- EXTENDED,
- HIDDEN,
- }
-
- enum ChoiceKind {
- ONEOF,
- ANYOF
- }
-
- /** This class represents an option recognized by the main program
- */
- static class Option implements JavacOption {
-
- /** Option string.
- */
- OptionName name;
-
- /** Documentation key for arguments.
- */
- String argsNameKey;
-
- /** Documentation key for description.
- */
- String descrKey;
-
- /** Suffix option (-foo=bar or -foo:bar)
- */
- boolean hasSuffix;
-
- /** The kind of choices for this option, if any.
- */
- ChoiceKind choiceKind;
-
- /** The choices for this option, if any, and whether or not the choices
- * are hidden
- */
- Map<String,Boolean> choices;
-
- Option(OptionName name, String argsNameKey, String descrKey) {
- this.name = name;
- this.argsNameKey = argsNameKey;
- this.descrKey = descrKey;
- char lastChar = name.optionName.charAt(name.optionName.length()-1);
- hasSuffix = lastChar == ':' || lastChar == '=';
- }
-
- Option(OptionName name, String descrKey) {
- this(name, null, descrKey);
- }
-
- Option(OptionName name, String descrKey, ChoiceKind choiceKind, String... choices) {
- this(name, descrKey, choiceKind, createChoices(choices));
- }
-
- private static Map<String,Boolean> createChoices(String... choices) {
- Map<String,Boolean> map = new LinkedHashMap<String,Boolean>();
- for (String c: choices)
- map.put(c, false);
- return map;
- }
-
- Option(OptionName name, String descrKey, ChoiceKind choiceKind,
- Map<String,Boolean> choices) {
- this(name, null, descrKey);
- if (choiceKind == null || choices == null)
- throw new NullPointerException();
- this.choiceKind = choiceKind;
- this.choices = choices;
- }
-
- @Override
- public String toString() {
- return name.optionName;
- }
-
- public boolean hasArg() {
- return argsNameKey != null && !hasSuffix;
- }
-
- public boolean matches(String option) {
- if (!hasSuffix)
- return option.equals(name.optionName);
-
- if (!option.startsWith(name.optionName))
- return false;
-
- if (choices != null) {
- String arg = option.substring(name.optionName.length());
- if (choiceKind == ChoiceKind.ONEOF)
- return choices.keySet().contains(arg);
- else {
- for (String a: arg.split(",+")) {
- if (!choices.keySet().contains(a))
- return false;
- }
- }
- }
-
- return true;
- }
-
- /** Print a line of documentation describing this option, if standard.
- * @param out the stream to which to write the documentation
- */
- void help(Log log) {
- log.printRawLines(WriterKind.NOTICE,
- String.format(" %-26s %s",
- helpSynopsis(log),
- log.localize(PrefixKind.JAVAC, descrKey)));
- }
-
- String helpSynopsis(Log log) {
- StringBuilder sb = new StringBuilder();
- sb.append(name);
- if (argsNameKey == null) {
- if (choices != null) {
- String sep = "{";
- for (Map.Entry<String,Boolean> e: choices.entrySet()) {
- if (!e.getValue()) {
- sb.append(sep);
- sb.append(e.getKey());
- sep = ",";
- }
- }
- sb.append("}");
- }
- } else {
- if (!hasSuffix)
- sb.append(" ");
- sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
- }
-
- return sb.toString();
- }
-
- /** Print a line of documentation describing this option, if non-standard.
- * @param out the stream to which to write the documentation
- */
- void xhelp(Log log) {}
-
- /** Process the option (with arg). Return true if error detected.
- */
- public boolean process(Options options, String option, String arg) {
- if (options != null) {
- if (choices != null) {
- if (choiceKind == ChoiceKind.ONEOF) {
- // some clients like to see just one of option+choice set
- for (String s: choices.keySet())
- options.remove(option + s);
- String opt = option + arg;
- options.put(opt, opt);
- // some clients like to see option (without trailing ":")
- // set to arg
- String nm = option.substring(0, option.length() - 1);
- options.put(nm, arg);
- } else {
- // set option+word for each word in arg
- for (String a: arg.split(",+")) {
- String opt = option + a;
- options.put(opt, opt);
- }
- }
- }
- options.put(option, arg);
- }
- return false;
- }
-
- /** Process the option (without arg). Return true if error detected.
- */
- public boolean process(Options options, String option) {
- if (hasSuffix)
- return process(options, name.optionName, option.substring(name.optionName.length()));
- else
- return process(options, option, option);
- }
-
- public OptionKind getKind() { return OptionKind.NORMAL; }
-
- public OptionName getName() { return name; }
- };
-
- /** A nonstandard or extended (-X) option
- */
- static class XOption extends Option {
- XOption(OptionName name, String argsNameKey, String descrKey) {
- super(name, argsNameKey, descrKey);
- }
- XOption(OptionName name, String descrKey) {
- this(name, null, descrKey);
- }
- XOption(OptionName name, String descrKey, ChoiceKind kind, String... choices) {
- super(name, descrKey, kind, choices);
- }
- XOption(OptionName name, String descrKey, ChoiceKind kind, Map<String,Boolean> choices) {
- super(name, descrKey, kind, choices);
- }
- @Override
- void help(Log log) {}
- @Override
- void xhelp(Log log) { super.help(log); }
- @Override
- public OptionKind getKind() { return OptionKind.EXTENDED; }
- };
-
- /** A hidden (implementor) option
- */
- static class HiddenOption extends Option {
- HiddenOption(OptionName name) {
- super(name, null, null);
- }
- HiddenOption(OptionName name, String argsNameKey) {
- super(name, argsNameKey, null);
- }
- @Override
- void help(Log log) {}
- @Override
- void xhelp(Log log) {}
- @Override
- public OptionKind getKind() { return OptionKind.HIDDEN; }
- };
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/Option.java Tue Dec 13 14:33:39 2011 -0800
@@ -0,0 +1,710 @@
+/*
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.tools.javac.main;
+
+import java.util.Collections;
+import com.sun.tools.javac.util.Log.PrefixKind;
+import com.sun.tools.javac.util.Log.WriterKind;
+import com.sun.tools.javac.util.Log;
+import com.sun.tools.javac.code.Lint;
+import com.sun.tools.javac.code.Source;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.jvm.Target;
+import com.sun.tools.javac.util.Options;
+import com.sun.tools.javac.processing.JavacProcessingEnvironment;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.EnumSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import javax.lang.model.SourceVersion;
+
+import static com.sun.tools.javac.main.Option.ChoiceKind.*;
+import static com.sun.tools.javac.main.Option.OptionKind.*;
+import static com.sun.tools.javac.main.Option.OptionGroup.*;
+
+/**
+ * Options for javac. The specific Option to handle a command-line option
+ * is identified by searching the members of this enum in order, looking
+ * the first {@link #matches match}. The action for an Option is performed
+ * by calling {@link #process process}, and by providing a suitable
+ * {@link OptionHelper} to provide access the compiler state.
+ *
+ * <p><b>This is NOT part of any supported API.
+ * If you write code that depends on this, you do so at your own
+ * risk. This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ */
+public enum Option {
+ G("-g", "opt.g", STANDARD, BASIC),
+
+ G_NONE("-g:none", "opt.g.none", STANDARD, BASIC) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ helper.put("-g:", "none");
+ return false;
+ }
+ },
+
+ G_CUSTOM("-g:", "opt.g.lines.vars.source",
+ STANDARD, BASIC, ANYOF, "lines", "vars", "source"),
+
+ XLINT("-Xlint", "opt.Xlint", EXTENDED, BASIC),
+
+ XLINT_CUSTOM("-Xlint:", "opt.Xlint.suboptlist",
+ EXTENDED, BASIC, ANYOF, getXLintChoices()),
+
+ // -nowarn is retained for command-line backward compatibility
+ NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ helper.put("-Xlint:none", option);
+ return false;
+ }
+ },
+
+ VERBOSE("-verbose", "opt.verbose", STANDARD, BASIC),
+
+ // -deprecation is retained for command-line backward compatibility
+ DEPRECATION("-deprecation", "opt.deprecation", STANDARD, BASIC) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ helper.put("-Xlint:deprecation", option);
+ return false;
+ }
+ },
+
+ CLASSPATH("-classpath", "opt.arg.path", "opt.classpath", STANDARD, FILEMANAGER),
+
+ CP("-cp", "opt.arg.path", "opt.classpath", STANDARD, FILEMANAGER) {
+ @Override
+ public boolean process(OptionHelper helper, String option, String arg) {
+ return super.process(helper, "-classpath", arg);
+ }
+ },
+
+ SOURCEPATH("-sourcepath", "opt.arg.path", "opt.sourcepath", STANDARD, FILEMANAGER),
+
+ BOOTCLASSPATH("-bootclasspath", "opt.arg.path", "opt.bootclasspath", STANDARD, FILEMANAGER) {
+ @Override
+ public boolean process(OptionHelper helper, String option, String arg) {
+ helper.remove("-Xbootclasspath/p:");
+ helper.remove("-Xbootclasspath/a:");
+ return super.process(helper, option, arg);
+ }
+ },
+
+ XBOOTCLASSPATH_PREPEND("-Xbootclasspath/p:", "opt.arg.path", "opt.Xbootclasspath.p", EXTENDED, FILEMANAGER),
+
+ XBOOTCLASSPATH_APPEND("-Xbootclasspath/a:", "opt.arg.path", "opt.Xbootclasspath.a", EXTENDED, FILEMANAGER),
+
+ XBOOTCLASSPATH("-Xbootclasspath:", "opt.arg.path", "opt.bootclasspath", EXTENDED, FILEMANAGER) {
+ @Override
+ public boolean process(OptionHelper helper, String option, String arg) {
+ helper.remove("-Xbootclasspath/p:");
+ helper.remove("-Xbootclasspath/a:");
+ return super.process(helper, "-bootclasspath", arg);
+ }
+ },
+
+ EXTDIRS("-extdirs", "opt.arg.dirs", "opt.extdirs", STANDARD, FILEMANAGER),
+
+ DJAVA_EXT_DIRS("-Djava.ext.dirs=", "opt.arg.dirs", "opt.extdirs", EXTENDED, FILEMANAGER) {
+ @Override
+ public boolean process(OptionHelper helper, String option, String arg) {
+ return super.process(helper, "-extdirs", arg);
+ }
+ },
+
+ ENDORSEDDIRS("-endorseddirs", "opt.arg.dirs", "opt.endorseddirs", STANDARD, FILEMANAGER),
+
+ DJAVA_ENDORSED_DIRS("-Djava.endorsed.dirs=", "opt.arg.dirs", "opt.endorseddirs", EXTENDED, FILEMANAGER) {
+ @Override
+ public boolean process(OptionHelper helper, String option, String arg) {
+ return super.process(helper, "-endorseddirs", arg);
+ }
+ },
+
+ PROC("-proc:", "opt.proc.none.only", STANDARD, BASIC, ONEOF, "none", "only"),
+
+ PROCESSOR("-processor", "opt.arg.class.list", "opt.processor", STANDARD, BASIC),
+
+ PROCESSORPATH("-processorpath", "opt.arg.path", "opt.processorpath", STANDARD, FILEMANAGER),
+
+ D("-d", "opt.arg.directory", "opt.d", STANDARD, FILEMANAGER),
+
+ S("-s", "opt.arg.directory", "opt.sourceDest", STANDARD, FILEMANAGER),
+
+ IMPLICIT("-implicit:", "opt.implicit", STANDARD, BASIC, ONEOF, "none", "class"),
+
+ ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER) {
+ @Override
+ public boolean process(OptionHelper helper, String option, String operand) {
+// System.err.println("process encoding " + operand);
+ return super.process(helper, option, operand);
+ }
+
+ },
+
+ SOURCE("-source", "opt.arg.release", "opt.source", STANDARD, BASIC) {
+ @Override
+ public boolean process(OptionHelper helper, String option, String operand) {
+ Source source = Source.lookup(operand);
+ if (source == null) {
+ helper.error("err.invalid.source", operand);
+ return true;
+ }
+ return super.process(helper, option, operand);
+ }
+ },
+
+ TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) {
+ @Override
+ public boolean process(OptionHelper helper, String option, String operand) {
+ Target target = Target.lookup(operand);
+ if (target == null) {
+ helper.error("err.invalid.target", operand);
+ return true;
+ }
+ return super.process(helper, option, operand);
+ }
+ },
+
+ VERSION("-version", "opt.version", STANDARD, INFO) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ Log log = helper.getLog();
+ String ownName = helper.getOwnName();
+ log.printLines(PrefixKind.JAVAC, "version", ownName, JavaCompiler.version());
+ return super.process(helper, option);
+ }
+ },
+
+ FULLVERSION("-fullversion", null, HIDDEN, INFO) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ Log log = helper.getLog();
+ String ownName = helper.getOwnName();
+ log.printLines(PrefixKind.JAVAC, "fullversion", ownName, JavaCompiler.fullVersion());
+ return super.process(helper, option);
+ }
+ },
+
+ DIAGS("-XDdiags=", null, HIDDEN, INFO) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ option = option.substring(option.indexOf('=') + 1);
+ String diagsOption = option.contains("%") ?
+ "-XDdiagsFormat=" :
+ "-XDdiags=";
+ diagsOption += option;
+ if (XD.matches(diagsOption))
+ return XD.process(helper, diagsOption);
+ else
+ return false;
+ }
+ },
+
+ HELP("-help", "opt.help", STANDARD, INFO) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ Log log = helper.getLog();
+ String ownName = helper.getOwnName();
+ log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName);
+ for (Option o: getJavaCompilerOptions()) {
+ o.help(log, OptionKind.STANDARD);
+ }
+ log.printNewline();
+ return super.process(helper, option);
+ }
+ },
+
+ A("-A", "opt.arg.key.equals.value", "opt.A", STANDARD, BASIC) {
+ { hasSuffix = true; }
+
+ @Override
+ public boolean matches(String arg) {
+ return arg.startsWith("-A");
+ }
+
+ @Override
+ public boolean hasArg() {
+ return false;
+ }
+ // Mapping for processor options created in
+ // JavacProcessingEnvironment
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ int argLength = option.length();
+ if (argLength == 2) {
+ helper.error("err.empty.A.argument");
+ return true;
+ }
+ int sepIndex = option.indexOf('=');
+ String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
+ if (!JavacProcessingEnvironment.isValidOptionName(key)) {
+ helper.error("err.invalid.A.key", option);
+ return true;
+ }
+ return process(helper, option, option);
+ }
+ },
+
+ X("-X", "opt.X", STANDARD, INFO) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ Log log = helper.getLog();
+ for (Option o: getJavaCompilerOptions()) {
+ o.help(log, OptionKind.EXTENDED);
+ }
+ log.printNewline();
+ log.printLines(PrefixKind.JAVAC, "msg.usage.nonstandard.footer");
+ return super.process(helper, option);
+ }
+ },
+
+ // This option exists only for the purpose of documenting itself.
+ // It's actually implemented by the launcher.
+ J("-J", "opt.arg.flag", "opt.J", STANDARD, INFO) {
+ { hasSuffix = true; }
+
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ throw new AssertionError
+ ("the -J flag should be caught by the launcher.");
+ }
+ },
+
+ // stop after parsing and attributing.
+ // new HiddenOption("-attrparseonly"),
+
+ // new Option("-moreinfo", "opt.moreinfo") {
+ MOREINFO("-moreinfo", null, HIDDEN, BASIC) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ Type.moreInfo = true;
+ return super.process(helper, option);
+ }
+ },
+
+ // treat warnings as errors
+ WERROR("-Werror", "opt.Werror", STANDARD, BASIC),
+
+// // use complex inference from context in the position of a method call argument
+// COMPLEXINFERENCE("-complexinference", null, HIDDEN, BASIC),
+
+ // generare source stubs
+ // new HiddenOption("-stubs"),
+
+ // relax some constraints to allow compiling from stubs
+ // new HiddenOption("-relax"),
+
+ // output source after translating away inner classes
+ // new Option("-printflat", "opt.printflat"),
+ // new HiddenOption("-printflat"),
+
+ // display scope search details
+ // new Option("-printsearch", "opt.printsearch"),
+ // new HiddenOption("-printsearch"),
+
+ // prompt after each error
+ // new Option("-prompt", "opt.prompt"),
+ PROMPT("-prompt", null, HIDDEN, BASIC),
+
+ // dump stack on error
+ DOE("-doe", null, HIDDEN, BASIC),
+
+ // output source after type erasure
+ // new Option("-s", "opt.s"),
+ PRINTSOURCE("-printsource", null, HIDDEN, BASIC),
+
+ // output shrouded class files
+ // new Option("-scramble", "opt.scramble"),
+ // new Option("-scrambleall", "opt.scrambleall"),
+
+ // display warnings for generic unchecked operations
+ WARNUNCHECKED("-warnunchecked", null, HIDDEN, BASIC) {
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ helper.put("-Xlint:unchecked", option);
+ return false;
+ }
+ },
+
+ XMAXERRS("-Xmaxerrs", "opt.arg.number", "opt.maxerrs", EXTENDED, BASIC),
+
+ XMAXWARNS("-Xmaxwarns", "opt.arg.number", "opt.maxwarns", EXTENDED, BASIC),
+
+ XSTDOUT("Xstdout", "opt.arg.file", "opt.Xstdout", EXTENDED, INFO) {
+ @Override
+ public boolean process(OptionHelper helper, String option, String arg) {
+ try {
+ Log log = helper.getLog();
+ // TODO: this file should be closed at the end of compilation
+ log.setWriters(new PrintWriter(new FileWriter(arg), true));
+ } catch (java.io.IOException e) {
+ helper.error("err.error.writing.file", arg, e);
+ return true;
+ }
+ return super.process(helper, option, arg);
+ }
+ },
+
+ XPRINT("-Xprint", "opt.print", EXTENDED, BASIC),
+
+ XPRINTROUNDS("-XprintRounds", "opt.printRounds", EXTENDED, BASIC),
+
+ XPRINTPROCESSORINFO("-XprintProcessorInfo", "opt.printProcessorInfo", EXTENDED, BASIC),
+
+ XPREFER("-Xprefer:", "opt.prefer", EXTENDED, BASIC, ONEOF, "source", "newer"),
+
+ XPKGINFO("-Xpkginfo:", "opt.pkginfo", EXTENDED, BASIC, ONEOF, "always", "legacy", "nonempty"),
+
+ /* -O is a no-op, accepted for backward compatibility. */
+ O("-O", null, HIDDEN, BASIC),
+
+ /* -Xjcov produces tables to support the code coverage tool jcov. */
+ XJCOV("-Xjcov", null, HIDDEN, BASIC),
+
+ /* This is a back door to the compiler's option table.
+ * -XDx=y sets the option x to the value y.
+ * -XDx sets the option x to the value x.
+ */
+ XD("-XD", null, HIDDEN, BASIC) {
+ String s;
+ @Override
+ public boolean matches(String s) {
+ this.s = s;
+ return s.startsWith(text);
+ }
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ s = s.substring(text.length());
+ int eq = s.indexOf('=');
+ String key = (eq < 0) ? s : s.substring(0, eq);
+ String value = (eq < 0) ? s : s.substring(eq+1);
+ helper.put(key, value);
+ return false;
+ }
+ },
+
+ // This option exists only for the purpose of documenting itself.
+ // It's actually implemented by the CommandLine class.
+ AT("@", "opt.arg.file", "opt.AT", STANDARD, INFO) {
+ { hasSuffix = true; }
+
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ throw new AssertionError("the @ flag should be caught by CommandLine.");
+ }
+ },
+
+ /*
+ * TODO: With apt, the matches method accepts anything if
+ * -XclassAsDecls is used; code elsewhere does the lookup to
+ * see if the class name is both legal and found.
+ *
+ * In apt, the process method adds the candidate class file
+ * name to a separate list.
+ */
+ SOURCEFILE("sourcefile", null, HIDDEN, INFO) {
+ String s;
+ @Override
+ public boolean matches(String s) {
+ this.s = s;
+ return s.endsWith(".java") // Java source file
+ || SourceVersion.isName(s); // Legal type name
+ }
+ @Override
+ public boolean process(OptionHelper helper, String option) {
+ if (s.endsWith(".java") ) {
+ File f = new File(s);
+ if (!f.exists()) {
+ helper.error("err.file.not.found", f);
+ return true;
+ }
+ if (!f.isFile()) {
+ helper.error("err.file.not.file", f);
+ return true;
+ }
+ helper.addFile(f);
+ }
+ else
+ helper.addClassName(s);
+ return false;
+ }
+ };
+
+ /** The kind of an Option. This is used by the -help and -X options. */
+ public enum OptionKind {
+ /** A standard option, documented by -help. */
+ STANDARD,
+ /** An extended option, documented by -X. */
+ EXTENDED,
+ /** A hidden option, not documented. */
+ HIDDEN,
+ }
+
+ /** The group for an Option. This determines the situations in which the
+ * option is applicable. */
+ enum OptionGroup {
+ /** A basic option, available for use on the command line or via the
+ * Compiler API. */
+ BASIC,
+ /** An option for javac's standard JavaFileManager. Other file managers
+ * may or may not support these options. */
+ FILEMANAGER,
+ /** A command-line option that requests information, such as -help. */
+ INFO,
+ /** A command-line "option" representing a file or class name. */
+ OPERAND
+ }
+
+ /** The kind of choice for "choice" options. */
+ enum ChoiceKind {
+ /** The expected value is exactly one of the set of choices. */
+ ONEOF,
+ /** The expected value is one of more of the set of choices. */
+ ANYOF
+ }
+
+ public final String text;
+
+ final OptionKind kind;
+
+ final OptionGroup group;
+
+ /** Documentation key for arguments.
+ */
+ final String argsNameKey;
+
+ /** Documentation key for description.
+ */
+ final String descrKey;
+
+ /** Suffix option (-foo=bar or -foo:bar)
+ */
+ boolean hasSuffix;
+
+ /** The kind of choices for this option, if any.
+ */
+ final ChoiceKind choiceKind;
+
+ /** The choices for this option, if any, and whether or not the choices
+ * are hidden
+ */
+ final Map<String,Boolean> choices;
+
+
+ Option(String text, String descrKey,
+ OptionKind kind, OptionGroup group) {
+ this(text, null, descrKey, kind, group, null, null);
+ }
+
+ Option(String text, String argsNameKey, String descrKey,
+ OptionKind kind, OptionGroup group) {
+ this(text, argsNameKey, descrKey, kind, group, null, null);
+ }
+
+ Option(String text, String descrKey,
+ OptionKind kind, OptionGroup group,
+ ChoiceKind choiceKind, Map<String,Boolean> choices) {
+ this(text, null, descrKey, kind, group, choiceKind, choices);
+ }
+
+ Option(String text, String descrKey,
+ OptionKind kind, OptionGroup group,
+ ChoiceKind choiceKind, String... choices) {
+ this(text, null, descrKey, kind, group, choiceKind, createChoices(choices));
+ }
+ // where
+ private static Map<String,Boolean> createChoices(String... choices) {
+ Map<String,Boolean> map = new LinkedHashMap<String,Boolean>();
+ for (String c: choices)
+ map.put(c, false);
+ return map;
+ }
+
+ private Option(String text, String argsNameKey, String descrKey,
+ OptionKind kind, OptionGroup group,
+ ChoiceKind choiceKind, Map<String,Boolean> choices) {
+ this.text = text;
+ this.argsNameKey = argsNameKey;
+ this.descrKey = descrKey;
+ this.kind = kind;
+ this.group = group;
+ this.choiceKind = choiceKind;
+ this.choices = choices;
+ char lastChar = text.charAt(text.length()-1);
+ hasSuffix = lastChar == ':' || lastChar == '=';
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public OptionKind getKind() {
+ return kind;
+ }
+
+ public boolean hasArg() {
+ return argsNameKey != null && !hasSuffix;
+ }
+
+ public boolean matches(String option) {
+ if (!hasSuffix)
+ return option.equals(text);
+
+ if (!option.startsWith(text))
+ return false;
+
+ if (choices != null) {
+ String arg = option.substring(text.length());
+ if (choiceKind == ChoiceKind.ONEOF)
+ return choices.keySet().contains(arg);
+ else {
+ for (String a: arg.split(",+")) {
+ if (!choices.keySet().contains(a))
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ public boolean process(OptionHelper helper, String option, String arg) {
+ if (choices != null) {
+ if (choiceKind == ChoiceKind.ONEOF) {
+ // some clients like to see just one of option+choice set
+ for (String s: choices.keySet())
+ helper.remove(option + s);
+ String opt = option + arg;
+ helper.put(opt, opt);
+ // some clients like to see option (without trailing ":")
+ // set to arg
+ String nm = option.substring(0, option.length() - 1);
+ helper.put(nm, arg);
+ } else {
+ // set option+word for each word in arg
+ for (String a: arg.split(",+")) {
+ String opt = option + a;
+ helper.put(opt, opt);
+ }
+ }
+ }
+ helper.put(option, arg);
+ return false;
+ }
+
+ public boolean process(OptionHelper helper, String option) {
+ if (hasSuffix)
+ return process(helper, text, option.substring(text.length()));
+ else
+ return process(helper, option, option);
+ }
+
+ void help(Log log, OptionKind kind) {
+ if (this.kind != kind)
+ return;
+
+ log.printRawLines(WriterKind.NOTICE,
+ String.format(" %-26s %s",
+ helpSynopsis(log),
+ log.localize(PrefixKind.JAVAC, descrKey)));
+
+ }
+
+ private String helpSynopsis(Log log) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(text);
+ if (argsNameKey == null) {
+ if (choices != null) {
+ String sep = "{";
+ for (Map.Entry<String,Boolean> e: choices.entrySet()) {
+ if (!e.getValue()) {
+ sb.append(sep);
+ sb.append(e.getKey());
+ sep = ",";
+ }
+ }
+ sb.append("}");
+ }
+ } else {
+ if (!hasSuffix)
+ sb.append(" ");
+ sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
+
+ }
+
+ return sb.toString();
+ }
+
+ // For -XpkgInfo:value
+ public enum PkgInfo {
+ ALWAYS, LEGACY, NONEMPTY;
+ public static PkgInfo get(Options options) {
+ String v = options.get(XPKGINFO);
+ return (v == null
+ ? PkgInfo.LEGACY
+ : PkgInfo.valueOf(v.toUpperCase()));
+ }
+ }
+
+ private static Map<String,Boolean> getXLintChoices() {
+ Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>();
+ choices.put("all", false);
+ for (Lint.LintCategory c : Lint.LintCategory.values())
+ choices.put(c.option, c.hidden);
+ for (Lint.LintCategory c : Lint.LintCategory.values())
+ choices.put("-" + c.option, c.hidden);
+ choices.put("none", false);
+ return choices;
+ }
+
+ static Set<Option> getJavaCompilerOptions() {
+ return EnumSet.allOf(Option.class);
+ }
+
+ public static Set<Option> getJavacFileManagerOptions() {
+ return getOptions(EnumSet.of(FILEMANAGER));
+ }
+
+ public static Set<Option> getJavacToolOptions() {
+ return getOptions(EnumSet.of(BASIC));
+ }
+
+ static Set<Option> getOptions(Set<OptionGroup> desired) {
+ Set<Option> options = EnumSet.noneOf(Option.class);
+ for (Option option : Option.values())
+ if (desired.contains(option.group))
+ options.add(option);
+ return Collections.unmodifiableSet(options);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/OptionHelper.java Tue Dec 13 14:33:39 2011 -0800
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.tools.javac.main;
+
+import com.sun.tools.javac.util.Log;
+import com.sun.tools.javac.util.Log.PrefixKind;
+import java.io.File;
+
+/**
+ * Helper object to be used by {@link Option#process}, providing access to
+ * the compilation environment.
+ *
+ * <p><b>This is NOT part of any supported API.
+ * If you write code that depends on this, you do so at your own
+ * risk. This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ */
+
+public abstract class OptionHelper {
+
+ /** Get the current value of an option. */
+ public abstract String get(Option option);
+
+ /** Set the value of an option. */
+ public abstract void put(String name, String value);
+
+ /** Remove any prior value for an option. */
+ public abstract void remove(String name);
+
+ /** Get access to the Log for the compilation. */
+ public abstract Log getLog();
+
+ /** Get the name of the tool, such as "javac", to be used in info like -help. */
+ public abstract String getOwnName();
+
+ /** Report an error. */
+ abstract void error(String key, Object... args);
+
+ /** Record a file to be compiled. */
+ abstract void addFile(File f);
+
+ /** Record the name of a class for annotation processing. */
+ abstract void addClassName(String s);
+
+ /** An implementation of OptionHelper that mostly throws exceptions. */
+ public static class GrumpyHelper extends OptionHelper {
+ private final Log log;
+
+ public GrumpyHelper(Log log) {
+ this.log = log;
+ }
+
+ @Override
+ public Log getLog() {
+ return log;
+ }
+
+ @Override
+ public String getOwnName() {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public String get(Option option) {
+ throw new IllegalArgumentException();
+ }
+
+ @Override
+ public void put(String name, String value) {
+ throw new IllegalArgumentException();
+ }
+
+ @Override
+ public void remove(String name) {
+ throw new IllegalArgumentException();
+ }
+
+ @Override
+ void error(String key, Object... args) {
+ throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
+ }
+
+ @Override
+ public void addFile(File f) {
+ throw new IllegalArgumentException(f.getPath());
+ }
+
+ @Override
+ public void addClassName(String s) {
+ throw new IllegalArgumentException(s);
+ }
+ }
+
+}
--- a/langtools/src/share/classes/com/sun/tools/javac/main/OptionName.java Tue Dec 13 11:21:28 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.tools.javac.main;
-
-
-/**
- * TODO: describe com.sun.tools.javac.main.OptionName
- *
- * <p><b>This is NOT part of any supported API.
- * If you write code that depends on this, you do so at your own
- * risk. This code and its internal interfaces are subject to change
- * or deletion without notice.</b></p>
- */
-public enum OptionName {
- G("-g"),
- G_NONE("-g:none"),
- G_CUSTOM("-g:"),
- XLINT("-Xlint"),
- XLINT_CUSTOM("-Xlint:"),
- DIAGS("-XDdiags="),
- NOWARN("-nowarn"),
- VERBOSE("-verbose"),
- DEPRECATION("-deprecation"),
- CLASSPATH("-classpath"),
- CP("-cp"),
- SOURCEPATH("-sourcepath"),
- BOOTCLASSPATH("-bootclasspath"),
- XBOOTCLASSPATH_PREPEND("-Xbootclasspath/p:"),
- XBOOTCLASSPATH_APPEND("-Xbootclasspath/a:"),
- XBOOTCLASSPATH("-Xbootclasspath:"),
- EXTDIRS("-extdirs"),
- DJAVA_EXT_DIRS("-Djava.ext.dirs="),
- ENDORSEDDIRS("-endorseddirs"),
- DJAVA_ENDORSED_DIRS("-Djava.endorsed.dirs="),
- PROC("-proc:"),
- PROCESSOR("-processor"),
- PROCESSORPATH("-processorpath"),
- D("-d"),
- S("-s"),
- IMPLICIT("-implicit:"),
- ENCODING("-encoding"),
- SOURCE("-source"),
- TARGET("-target"),
- VERSION("-version"),
- FULLVERSION("-fullversion"),
- HELP("-help"),
- A("-A"),
- X("-X"),
- J("-J"),
- MOREINFO("-moreinfo"),
- WERROR("-Werror"),
- COMPLEXINFERENCE("-complexinference"),
- PROMPT("-prompt"),
- DOE("-doe"),
- PRINTSOURCE("-printsource"),
- WARNUNCHECKED("-warnunchecked"),
- XMAXERRS("-Xmaxerrs"),
- XMAXWARNS("-Xmaxwarns"),
- XSTDOUT("-Xstdout"),
- XPKGINFO("-Xpkginfo:"),
- XPRINT("-Xprint"),
- XPRINTROUNDS("-XprintRounds"),
- XPRINTPROCESSORINFO("-XprintProcessorInfo"),
- XPREFER("-Xprefer:"),
- O("-O"),
- XJCOV("-Xjcov"),
- XD("-XD"),
- AT("@"),
- SOURCEFILE("sourcefile");
-
- public final String optionName;
-
- OptionName(String optionName) {
- this.optionName = optionName;
- }
-
- @Override
- public String toString() {
- return optionName;
- }
-
-}
--- a/langtools/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Tue Dec 13 11:21:28 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,651 +0,0 @@
-/*
- * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.tools.javac.main;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.util.EnumSet;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import javax.lang.model.SourceVersion;
-
-import com.sun.tools.javac.code.Lint;
-import com.sun.tools.javac.code.Source;
-import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.jvm.Target;
-import com.sun.tools.javac.main.JavacOption.HiddenOption;
-import com.sun.tools.javac.main.JavacOption.Option;
-import com.sun.tools.javac.main.JavacOption.XOption;
-import com.sun.tools.javac.processing.JavacProcessingEnvironment;
-import com.sun.tools.javac.util.ListBuffer;
-import com.sun.tools.javac.util.Log;
-import com.sun.tools.javac.util.Log.PrefixKind;
-import com.sun.tools.javac.util.Options;
-
-import static com.sun.tools.javac.main.OptionName.*;
-
-/**
- * TODO: describe com.sun.tools.javac.main.RecognizedOptions
- *
- * <p><b>This is NOT part of any supported API.
- * If you write code that depends on this, you do so at your own
- * risk. This code and its internal interfaces are subject to change
- * or deletion without notice.</b></p>
- */
-public class RecognizedOptions {
-
- private RecognizedOptions() {}
-
- public interface OptionHelper {
-
- void setOut(PrintWriter out);
-
- void error(String key, Object... args);
-
- void printVersion();
-
- void printFullVersion();
-
- void printHelp();
-
- void printXhelp();
-
- void addFile(File f);
-
- void addClassName(String s);
-
- }
-
- public static class GrumpyHelper implements OptionHelper {
- private Log log;
-
- public GrumpyHelper(Log log) {
- this.log = log;
- }
-
- public void setOut(PrintWriter out) {
- throw new IllegalArgumentException();
- }
-
- public void error(String key, Object... args) {
- throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
- }
-
- public void printVersion() {
- throw new IllegalArgumentException();
- }
-
- public void printFullVersion() {
- throw new IllegalArgumentException();
- }
-
- public void printHelp() {
- throw new IllegalArgumentException();
- }
-
- public void printXhelp() {
- throw new IllegalArgumentException();
- }
-
- public void addFile(File f) {
- throw new IllegalArgumentException(f.getPath());
- }
-
- public void addClassName(String s) {
- throw new IllegalArgumentException(s);
- }
-
- }
-
- static Set<OptionName> javacOptions = EnumSet.of(
- G,
- G_NONE,
- G_CUSTOM,
- XLINT,
- XLINT_CUSTOM,
- NOWARN,
- VERBOSE,
- DEPRECATION,
- CLASSPATH,
- CP,
- SOURCEPATH,
- BOOTCLASSPATH,
- XBOOTCLASSPATH_PREPEND,
- XBOOTCLASSPATH_APPEND,
- XBOOTCLASSPATH,
- EXTDIRS,
- DJAVA_EXT_DIRS,
- ENDORSEDDIRS,
- DJAVA_ENDORSED_DIRS,
- PROC,
- PROCESSOR,
- PROCESSORPATH,
- D,
- S,
- IMPLICIT,
- ENCODING,
- SOURCE,
- TARGET,
- VERSION,
- FULLVERSION,
- DIAGS,
- HELP,
- A,
- X,
- J,
- MOREINFO,
- WERROR,
- // COMPLEXINFERENCE,
- PROMPT,
- DOE,
- PRINTSOURCE,
- WARNUNCHECKED,
- XMAXERRS,
- XMAXWARNS,
- XSTDOUT,
- XPKGINFO,
- XPRINT,
- XPRINTROUNDS,
- XPRINTPROCESSORINFO,
- XPREFER,
- O,
- XJCOV,
- XD,
- AT,
- SOURCEFILE);
-
- static Set<OptionName> javacFileManagerOptions = EnumSet.of(
- CLASSPATH,
- CP,
- SOURCEPATH,
- BOOTCLASSPATH,
- XBOOTCLASSPATH_PREPEND,
- XBOOTCLASSPATH_APPEND,
- XBOOTCLASSPATH,
- EXTDIRS,
- DJAVA_EXT_DIRS,
- ENDORSEDDIRS,
- DJAVA_ENDORSED_DIRS,
- PROCESSORPATH,
- D,
- S,
- ENCODING,
- SOURCE);
-
- static Set<OptionName> javacToolOptions = EnumSet.of(
- G,
- G_NONE,
- G_CUSTOM,
- XLINT,
- XLINT_CUSTOM,
- NOWARN,
- VERBOSE,
- DEPRECATION,
- PROC,
- PROCESSOR,
- IMPLICIT,
- SOURCE,
- TARGET,
- // VERSION,
- // FULLVERSION,
- // HELP,
- A,
- // X,
- // J,
- MOREINFO,
- WERROR,
- // COMPLEXINFERENCE,
- PROMPT,
- DOE,
- PRINTSOURCE,
- WARNUNCHECKED,
- XMAXERRS,
- XMAXWARNS,
- // XSTDOUT,
- XPKGINFO,
- XPRINT,
- XPRINTROUNDS,
- XPRINTPROCESSORINFO,
- XPREFER,
- O,
- XJCOV,
- XD);
-
- static Option[] getJavaCompilerOptions(OptionHelper helper) {
- return getOptions(helper, javacOptions);
- }
-
- public static Option[] getJavacFileManagerOptions(OptionHelper helper) {
- return getOptions(helper, javacFileManagerOptions);
- }
-
- public static Option[] getJavacToolOptions(OptionHelper helper) {
- return getOptions(helper, javacToolOptions);
- }
-
- static Option[] getOptions(OptionHelper helper, Set<OptionName> desired) {
- ListBuffer<Option> options = new ListBuffer<Option>();
- for (Option option : getAll(helper))
- if (desired.contains(option.getName()))
- options.append(option);
- return options.toArray(new Option[options.length()]);
- }
-
- /**
- * Get all the recognized options.
- * @param helper an {@code OptionHelper} to help when processing options
- * @return an array of options
- */
- public static Option[] getAll(final OptionHelper helper) {
- return new Option[] {
- new Option(G, "opt.g"),
- new Option(G_NONE, "opt.g.none") {
- @Override
- public boolean process(Options options, String option) {
- options.put("-g:", "none");
- return false;
- }
- },
-
- new Option(G_CUSTOM, "opt.g.lines.vars.source",
- Option.ChoiceKind.ANYOF, "lines", "vars", "source"),
-
- new XOption(XLINT, "opt.Xlint"),
- new XOption(XLINT_CUSTOM, "opt.Xlint.suboptlist",
- Option.ChoiceKind.ANYOF, getXLintChoices()),
-
- // -nowarn is retained for command-line backward compatibility
- new Option(NOWARN, "opt.nowarn") {
- @Override
- public boolean process(Options options, String option) {
- options.put("-Xlint:none", option);
- return false;
- }
- },
-
- new Option(VERBOSE, "opt.verbose"),
-
- // -deprecation is retained for command-line backward compatibility
- new Option(DEPRECATION, "opt.deprecation") {
- @Override
- public boolean process(Options options, String option) {
- options.put("-Xlint:deprecation", option);
- return false;
- }
- },
-
- new Option(CLASSPATH, "opt.arg.path", "opt.classpath"),
- new Option(CP, "opt.arg.path", "opt.classpath") {
- @Override
- public boolean process(Options options, String option, String arg) {
- return super.process(options, "-classpath", arg);
- }
- },
- new Option(SOURCEPATH, "opt.arg.path", "opt.sourcepath"),
- new Option(BOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") {
- @Override
- public boolean process(Options options, String option, String arg) {
- options.remove("-Xbootclasspath/p:");
- options.remove("-Xbootclasspath/a:");
- return super.process(options, option, arg);
- }
- },
- new XOption(XBOOTCLASSPATH_PREPEND,"opt.arg.path", "opt.Xbootclasspath.p"),
- new XOption(XBOOTCLASSPATH_APPEND, "opt.arg.path", "opt.Xbootclasspath.a"),
- new XOption(XBOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") {
- @Override
- public boolean process(Options options, String option, String arg) {
- options.remove("-Xbootclasspath/p:");
- options.remove("-Xbootclasspath/a:");
- return super.process(options, "-bootclasspath", arg);
- }
- },
- new Option(EXTDIRS, "opt.arg.dirs", "opt.extdirs"),
- new XOption(DJAVA_EXT_DIRS, "opt.arg.dirs", "opt.extdirs") {
- @Override
- public boolean process(Options options, String option, String arg) {
- return super.process(options, "-extdirs", arg);
- }
- },
- new Option(ENDORSEDDIRS, "opt.arg.dirs", "opt.endorseddirs"),
- new XOption(DJAVA_ENDORSED_DIRS, "opt.arg.dirs", "opt.endorseddirs") {
- @Override
- public boolean process(Options options, String option, String arg) {
- return super.process(options, "-endorseddirs", arg);
- }
- },
- new Option(PROC, "opt.proc.none.only",
- Option.ChoiceKind.ONEOF, "none", "only"),
- new Option(PROCESSOR, "opt.arg.class.list", "opt.processor"),
- new Option(PROCESSORPATH, "opt.arg.path", "opt.processorpath"),
- new Option(D, "opt.arg.directory", "opt.d"),
- new Option(S, "opt.arg.directory", "opt.sourceDest"),
- new Option(IMPLICIT, "opt.implicit",
- Option.ChoiceKind.ONEOF, "none", "class"),
- new Option(ENCODING, "opt.arg.encoding", "opt.encoding"),
- new Option(SOURCE, "opt.arg.release", "opt.source") {
- @Override
- public boolean process(Options options, String option, String operand) {
- Source source = Source.lookup(operand);
- if (source == null) {
- helper.error("err.invalid.source", operand);
- return true;
- }
- return super.process(options, option, operand);
- }
- },
- new Option(TARGET, "opt.arg.release", "opt.target") {
- @Override
- public boolean process(Options options, String option, String operand) {
- Target target = Target.lookup(operand);
- if (target == null) {
- helper.error("err.invalid.target", operand);
- return true;
- }
- return super.process(options, option, operand);
- }
- },
- new Option(VERSION, "opt.version") {
- @Override
- public boolean process(Options options, String option) {
- helper.printVersion();
- return super.process(options, option);
- }
- },
- new HiddenOption(FULLVERSION) {
- @Override
- public boolean process(Options options, String option) {
- helper.printFullVersion();
- return super.process(options, option);
- }
- },
- new HiddenOption(DIAGS) {
- @Override
- public boolean process(Options options, String option) {
- Option xd = getOptions(helper, EnumSet.of(XD))[0];
- option = option.substring(option.indexOf('=') + 1);
- String diagsOption = option.contains("%") ?
- "-XDdiagsFormat=" :
- "-XDdiags=";
- diagsOption += option;
- if (xd.matches(diagsOption))
- return xd.process(options, diagsOption);
- else
- return false;
- }
- },
- new Option(HELP, "opt.help") {
- @Override
- public boolean process(Options options, String option) {
- helper.printHelp();
- return super.process(options, option);
- }
- },
- new Option(A, "opt.arg.key.equals.value","opt.A") {
- @Override
- String helpSynopsis(Log log) {
- hasSuffix = true;
- return super.helpSynopsis(log);
- }
-
- @Override
- public boolean matches(String arg) {
- return arg.startsWith("-A");
- }
-
- @Override
- public boolean hasArg() {
- return false;
- }
- // Mapping for processor options created in
- // JavacProcessingEnvironment
- @Override
- public boolean process(Options options, String option) {
- int argLength = option.length();
- if (argLength == 2) {
- helper.error("err.empty.A.argument");
- return true;
- }
- int sepIndex = option.indexOf('=');
- String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
- if (!JavacProcessingEnvironment.isValidOptionName(key)) {
- helper.error("err.invalid.A.key", option);
- return true;
- }
- return process(options, option, option);
- }
- },
- new Option(X, "opt.X") {
- @Override
- public boolean process(Options options, String option) {
- helper.printXhelp();
- return super.process(options, option);
- }
- },
-
- // This option exists only for the purpose of documenting itself.
- // It's actually implemented by the launcher.
- new Option(J, "opt.arg.flag", "opt.J") {
- @Override
- String helpSynopsis(Log log) {
- hasSuffix = true;
- return super.helpSynopsis(log);
- }
- @Override
- public boolean process(Options options, String option) {
- throw new AssertionError
- ("the -J flag should be caught by the launcher.");
- }
- },
-
- // stop after parsing and attributing.
- // new HiddenOption("-attrparseonly"),
-
- // new Option("-moreinfo", "opt.moreinfo") {
- new HiddenOption(MOREINFO) {
- @Override
- public boolean process(Options options, String option) {
- Type.moreInfo = true;
- return super.process(options, option);
- }
- },
-
- // treat warnings as errors
- new Option(WERROR, "opt.Werror"),
-
- // use complex inference from context in the position of a method call argument
- new HiddenOption(COMPLEXINFERENCE),
-
- // generare source stubs
- // new HiddenOption("-stubs"),
-
- // relax some constraints to allow compiling from stubs
- // new HiddenOption("-relax"),
-
- // output source after translating away inner classes
- // new Option("-printflat", "opt.printflat"),
- // new HiddenOption("-printflat"),
-
- // display scope search details
- // new Option("-printsearch", "opt.printsearch"),
- // new HiddenOption("-printsearch"),
-
- // prompt after each error
- // new Option("-prompt", "opt.prompt"),
- new HiddenOption(PROMPT),
-
- // dump stack on error
- new HiddenOption(DOE),
-
- // output source after type erasure
- // new Option("-s", "opt.s"),
- new HiddenOption(PRINTSOURCE),
-
- // output shrouded class files
- // new Option("-scramble", "opt.scramble"),
- // new Option("-scrambleall", "opt.scrambleall"),
-
- // display warnings for generic unchecked operations
- new HiddenOption(WARNUNCHECKED) {
- @Override
- public boolean process(Options options, String option) {
- options.put("-Xlint:unchecked", option);
- return false;
- }
- },
-
- new XOption(XMAXERRS, "opt.arg.number", "opt.maxerrs"),
- new XOption(XMAXWARNS, "opt.arg.number", "opt.maxwarns"),
- new XOption(XSTDOUT, "opt.arg.file", "opt.Xstdout") {
- @Override
- public boolean process(Options options, String option, String arg) {
- try {
- helper.setOut(new PrintWriter(new FileWriter(arg), true));
- } catch (java.io.IOException e) {
- helper.error("err.error.writing.file", arg, e);
- return true;
- }
- return super.process(options, option, arg);
- }
- },
-
- new XOption(XPRINT, "opt.print"),
-
- new XOption(XPRINTROUNDS, "opt.printRounds"),
-
- new XOption(XPRINTPROCESSORINFO, "opt.printProcessorInfo"),
-
- new XOption(XPREFER, "opt.prefer",
- Option.ChoiceKind.ONEOF, "source", "newer"),
-
- new XOption(XPKGINFO, "opt.pkginfo",
- Option.ChoiceKind.ONEOF, "always", "legacy", "nonempty"),
-
- /* -O is a no-op, accepted for backward compatibility. */
- new HiddenOption(O),
-
- /* -Xjcov produces tables to support the code coverage tool jcov. */
- new HiddenOption(XJCOV),
-
- /* This is a back door to the compiler's option table.
- * -XDx=y sets the option x to the value y.
- * -XDx sets the option x to the value x.
- */
- new HiddenOption(XD) {
- String s;
- @Override
- public boolean matches(String s) {
- this.s = s;
- return s.startsWith(name.optionName);
- }
- @Override
- public boolean process(Options options, String option) {
- s = s.substring(name.optionName.length());
- int eq = s.indexOf('=');
- String key = (eq < 0) ? s : s.substring(0, eq);
- String value = (eq < 0) ? s : s.substring(eq+1);
- options.put(key, value);
- return false;
- }
- },
-
- // This option exists only for the purpose of documenting itself.
- // It's actually implemented by the CommandLine class.
- new Option(AT, "opt.arg.file", "opt.AT") {
- @Override
- String helpSynopsis(Log log) {
- hasSuffix = true;
- return super.helpSynopsis(log);
- }
- @Override
- public boolean process(Options options, String option) {
- throw new AssertionError
- ("the @ flag should be caught by CommandLine.");
- }
- },
-
- /*
- * TODO: With apt, the matches method accepts anything if
- * -XclassAsDecls is used; code elsewhere does the lookup to
- * see if the class name is both legal and found.
- *
- * In apt, the process method adds the candidate class file
- * name to a separate list.
- */
- new HiddenOption(SOURCEFILE) {
- String s;
- @Override
- public boolean matches(String s) {
- this.s = s;
- return s.endsWith(".java") // Java source file
- || SourceVersion.isName(s); // Legal type name
- }
- @Override
- public boolean process(Options options, String option) {
- if (s.endsWith(".java") ) {
- File f = new File(s);
- if (!f.exists()) {
- helper.error("err.file.not.found", f);
- return true;
- }
- if (!f.isFile()) {
- helper.error("err.file.not.file", f);
- return true;
- }
- helper.addFile(f);
- }
- else
- helper.addClassName(s);
- return false;
- }
- },
- };
- }
-
- public enum PkgInfo {
- ALWAYS, LEGACY, NONEMPTY;
- public static PkgInfo get(Options options) {
- String v = options.get(XPKGINFO);
- return (v == null
- ? PkgInfo.LEGACY
- : PkgInfo.valueOf(v.toUpperCase()));
- }
- }
-
- private static Map<String,Boolean> getXLintChoices() {
- Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>();
- choices.put("all", false);
- for (Lint.LintCategory c : Lint.LintCategory.values())
- choices.put(c.option, c.hidden);
- for (Lint.LintCategory c : Lint.LintCategory.values())
- choices.put("-" + c.option, c.hidden);
- choices.put("none", false);
- return choices;
- }
-
-}