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

Wed, 21 Jan 2015 10:42:49 +0000

author
mcimadamore
date
Wed, 21 Jan 2015 10:42:49 +0000
changeset 2710
584566b6d5e4
parent 2413
fe033d997ddf
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8069181: java.lang.AssertionError when compiling JDK 1.4 code in JDK 8
Summary: remove erroneous call to modifiersOpt() in variable parsing
Reviewed-by: jfranck, jlahoda

     1 /*
     2  * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.javac.main;
    28 import java.io.File;
    29 import java.io.FileWriter;
    30 import java.io.PrintWriter;
    31 import java.util.Collections;
    32 import java.util.EnumSet;
    33 import java.util.LinkedHashMap;
    34 import java.util.Map;
    35 import java.util.Set;
    37 import javax.lang.model.SourceVersion;
    39 import com.sun.tools.doclint.DocLint;
    40 import com.sun.tools.javac.code.Lint;
    41 import com.sun.tools.javac.code.Source;
    42 import com.sun.tools.javac.code.Type;
    43 import com.sun.tools.javac.jvm.Profile;
    44 import com.sun.tools.javac.jvm.Target;
    45 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
    46 import com.sun.tools.javac.util.Log;
    47 import com.sun.tools.javac.util.Log.PrefixKind;
    48 import com.sun.tools.javac.util.Log.WriterKind;
    49 import com.sun.tools.javac.util.Options;
    50 import com.sun.tools.javac.util.StringUtils;
    51 import static com.sun.tools.javac.main.Option.ChoiceKind.*;
    52 import static com.sun.tools.javac.main.Option.OptionGroup.*;
    53 import static com.sun.tools.javac.main.Option.OptionKind.*;
    55 /**
    56  * Options for javac. The specific Option to handle a command-line option
    57  * is identified by searching the members of this enum in order, looking
    58  * the first {@link #matches match}. The action for an Option is performed
    59  * by calling {@link #process process}, and by providing a suitable
    60  * {@link OptionHelper} to provide access the compiler state.
    61  *
    62  * <p><b>This is NOT part of any supported API.
    63  * If you write code that depends on this, you do so at your own
    64  * risk.  This code and its internal interfaces are subject to change
    65  * or deletion without notice.</b></p>
    66  */
    67 public enum Option {
    68     G("-g", "opt.g", STANDARD, BASIC),
    70     G_NONE("-g:none", "opt.g.none", STANDARD, BASIC) {
    71         @Override
    72         public boolean process(OptionHelper helper, String option) {
    73             helper.put("-g:", "none");
    74             return false;
    75         }
    76     },
    78     G_CUSTOM("-g:",  "opt.g.lines.vars.source",
    79             STANDARD, BASIC, ANYOF, "lines", "vars", "source"),
    81     XLINT("-Xlint", "opt.Xlint", EXTENDED, BASIC),
    83     XLINT_CUSTOM("-Xlint:", "opt.Xlint.suboptlist",
    84             EXTENDED,   BASIC, ANYOF, getXLintChoices()),
    86     XDOCLINT("-Xdoclint", "opt.Xdoclint", EXTENDED, BASIC),
    88     XDOCLINT_CUSTOM("-Xdoclint:", "opt.Xdoclint.subopts", "opt.Xdoclint.custom", EXTENDED, BASIC) {
    89         @Override
    90         public boolean matches(String option) {
    91             return DocLint.isValidOption(
    92                     option.replace(XDOCLINT_CUSTOM.text, DocLint.XMSGS_CUSTOM_PREFIX));
    93         }
    95         @Override
    96         public boolean process(OptionHelper helper, String option) {
    97             String prev = helper.get(XDOCLINT_CUSTOM);
    98             String next = (prev == null) ? option : (prev + " " + option);
    99             helper.put(XDOCLINT_CUSTOM.text, next);
   100             return false;
   101         }
   102     },
   104     // -nowarn is retained for command-line backward compatibility
   105     NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC) {
   106         @Override
   107         public boolean process(OptionHelper helper, String option) {
   108             helper.put("-Xlint:none", option);
   109             return false;
   110         }
   111     },
   113     VERBOSE("-verbose", "opt.verbose", STANDARD, BASIC),
   115     // -deprecation is retained for command-line backward compatibility
   116     DEPRECATION("-deprecation", "opt.deprecation", STANDARD, BASIC) {
   117         @Override
   118         public boolean process(OptionHelper helper, String option) {
   119             helper.put("-Xlint:deprecation", option);
   120             return false;
   121         }
   122     },
   124     CLASSPATH("-classpath", "opt.arg.path", "opt.classpath", STANDARD, FILEMANAGER),
   126     CP("-cp", "opt.arg.path", "opt.classpath", STANDARD, FILEMANAGER) {
   127         @Override
   128         public boolean process(OptionHelper helper, String option, String arg) {
   129             return super.process(helper, "-classpath", arg);
   130         }
   131     },
   133     SOURCEPATH("-sourcepath", "opt.arg.path", "opt.sourcepath", STANDARD, FILEMANAGER),
   135     BOOTCLASSPATH("-bootclasspath", "opt.arg.path", "opt.bootclasspath", STANDARD, FILEMANAGER) {
   136         @Override
   137         public boolean process(OptionHelper helper, String option, String arg) {
   138             helper.remove("-Xbootclasspath/p:");
   139             helper.remove("-Xbootclasspath/a:");
   140             return super.process(helper, option, arg);
   141         }
   142     },
   144     XBOOTCLASSPATH_PREPEND("-Xbootclasspath/p:", "opt.arg.path", "opt.Xbootclasspath.p", EXTENDED, FILEMANAGER),
   146     XBOOTCLASSPATH_APPEND("-Xbootclasspath/a:", "opt.arg.path", "opt.Xbootclasspath.a", EXTENDED, FILEMANAGER),
   148     XBOOTCLASSPATH("-Xbootclasspath:", "opt.arg.path", "opt.bootclasspath", EXTENDED, FILEMANAGER) {
   149         @Override
   150         public boolean process(OptionHelper helper, String option, String arg) {
   151             helper.remove("-Xbootclasspath/p:");
   152             helper.remove("-Xbootclasspath/a:");
   153             return super.process(helper, "-bootclasspath", arg);
   154         }
   155     },
   157     EXTDIRS("-extdirs", "opt.arg.dirs", "opt.extdirs", STANDARD, FILEMANAGER),
   159     DJAVA_EXT_DIRS("-Djava.ext.dirs=", "opt.arg.dirs", "opt.extdirs", EXTENDED, FILEMANAGER) {
   160         @Override
   161         public boolean process(OptionHelper helper, String option, String arg) {
   162             return super.process(helper, "-extdirs", arg);
   163         }
   164     },
   166     ENDORSEDDIRS("-endorseddirs", "opt.arg.dirs", "opt.endorseddirs", STANDARD, FILEMANAGER),
   168     DJAVA_ENDORSED_DIRS("-Djava.endorsed.dirs=", "opt.arg.dirs", "opt.endorseddirs", EXTENDED, FILEMANAGER) {
   169         @Override
   170         public boolean process(OptionHelper helper, String option, String arg) {
   171             return super.process(helper, "-endorseddirs", arg);
   172         }
   173     },
   175     PROC("-proc:", "opt.proc.none.only", STANDARD, BASIC,  ONEOF, "none", "only"),
   177     PROCESSOR("-processor", "opt.arg.class.list", "opt.processor", STANDARD, BASIC),
   179     PROCESSORPATH("-processorpath", "opt.arg.path", "opt.processorpath", STANDARD, FILEMANAGER),
   181     PARAMETERS("-parameters","opt.parameters", STANDARD, BASIC),
   183     D("-d", "opt.arg.directory", "opt.d", STANDARD, FILEMANAGER),
   185     S("-s", "opt.arg.directory", "opt.sourceDest", STANDARD, FILEMANAGER),
   187     H("-h", "opt.arg.directory", "opt.headerDest", STANDARD, FILEMANAGER),
   189     IMPLICIT("-implicit:", "opt.implicit", STANDARD, BASIC, ONEOF, "none", "class"),
   191     ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER) {
   192         @Override
   193         public boolean process(OptionHelper helper, String option, String operand) {
   194             return super.process(helper, option, operand);
   195         }
   197     },
   199     SOURCE("-source", "opt.arg.release", "opt.source", STANDARD, BASIC) {
   200         @Override
   201         public boolean process(OptionHelper helper, String option, String operand) {
   202             Source source = Source.lookup(operand);
   203             if (source == null) {
   204                 helper.error("err.invalid.source", operand);
   205                 return true;
   206             }
   207             return super.process(helper, option, operand);
   208         }
   209     },
   211     TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) {
   212         @Override
   213         public boolean process(OptionHelper helper, String option, String operand) {
   214             Target target = Target.lookup(operand);
   215             if (target == null) {
   216                 helper.error("err.invalid.target", operand);
   217                 return true;
   218             }
   219             return super.process(helper, option, operand);
   220         }
   221     },
   223     PROFILE("-profile", "opt.arg.profile", "opt.profile", STANDARD, BASIC) {
   224         @Override
   225         public boolean process(OptionHelper helper, String option, String operand) {
   226             Profile profile = Profile.lookup(operand);
   227             if (profile == null) {
   228                 helper.error("err.invalid.profile", operand);
   229                 return true;
   230             }
   231             return super.process(helper, option, operand);
   232         }
   233     },
   235     VERSION("-version", "opt.version", STANDARD, INFO) {
   236         @Override
   237         public boolean process(OptionHelper helper, String option) {
   238             Log log = helper.getLog();
   239             String ownName = helper.getOwnName();
   240             log.printLines(PrefixKind.JAVAC, "version", ownName,  JavaCompiler.version());
   241             return super.process(helper, option);
   242         }
   243     },
   245     FULLVERSION("-fullversion", null, HIDDEN, INFO) {
   246         @Override
   247         public boolean process(OptionHelper helper, String option) {
   248             Log log = helper.getLog();
   249             String ownName = helper.getOwnName();
   250             log.printLines(PrefixKind.JAVAC, "fullVersion", ownName,  JavaCompiler.fullVersion());
   251             return super.process(helper, option);
   252         }
   253     },
   255     DIAGS("-XDdiags=", null, HIDDEN, INFO) {
   256         @Override
   257         public boolean process(OptionHelper helper, String option) {
   258             option = option.substring(option.indexOf('=') + 1);
   259             String diagsOption = option.contains("%") ?
   260                 "-XDdiagsFormat=" :
   261                 "-XDdiags=";
   262             diagsOption += option;
   263             if (XD.matches(diagsOption))
   264                 return XD.process(helper, diagsOption);
   265             else
   266                 return false;
   267         }
   268     },
   270     HELP("-help", "opt.help", STANDARD, INFO) {
   271         @Override
   272         public boolean process(OptionHelper helper, String option) {
   273             Log log = helper.getLog();
   274             String ownName = helper.getOwnName();
   275             log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName);
   276             for (Option o: getJavaCompilerOptions()) {
   277                 o.help(log, OptionKind.STANDARD);
   278             }
   279             log.printNewline();
   280             return super.process(helper, option);
   281         }
   282     },
   284     A("-A", "opt.arg.key.equals.value", "opt.A", STANDARD, BASIC, true) {
   285         @Override
   286         public boolean matches(String arg) {
   287             return arg.startsWith("-A");
   288         }
   290         @Override
   291         public boolean hasArg() {
   292             return false;
   293         }
   294         // Mapping for processor options created in
   295         // JavacProcessingEnvironment
   296         @Override
   297         public boolean process(OptionHelper helper, String option) {
   298             int argLength = option.length();
   299             if (argLength == 2) {
   300                 helper.error("err.empty.A.argument");
   301                 return true;
   302             }
   303             int sepIndex = option.indexOf('=');
   304             String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
   305             if (!JavacProcessingEnvironment.isValidOptionName(key)) {
   306                 helper.error("err.invalid.A.key", option);
   307                 return true;
   308             }
   309             return process(helper, option, option);
   310         }
   311     },
   313     X("-X", "opt.X", STANDARD, INFO) {
   314         @Override
   315         public boolean process(OptionHelper helper, String option) {
   316             Log log = helper.getLog();
   317             for (Option o: getJavaCompilerOptions()) {
   318                 o.help(log, OptionKind.EXTENDED);
   319             }
   320             log.printNewline();
   321             log.printLines(PrefixKind.JAVAC, "msg.usage.nonstandard.footer");
   322             return super.process(helper, option);
   323         }
   324     },
   326     // This option exists only for the purpose of documenting itself.
   327     // It's actually implemented by the launcher.
   328     J("-J", "opt.arg.flag", "opt.J", STANDARD, INFO, true) {
   329         @Override
   330         public boolean process(OptionHelper helper, String option) {
   331             throw new AssertionError
   332                 ("the -J flag should be caught by the launcher.");
   333         }
   334     },
   336     MOREINFO("-moreinfo", null, HIDDEN, BASIC) {
   337         @Override
   338         public boolean process(OptionHelper helper, String option) {
   339             Type.moreInfo = true;
   340             return super.process(helper, option);
   341         }
   342     },
   344     // treat warnings as errors
   345     WERROR("-Werror", "opt.Werror", STANDARD, BASIC),
   347     // prompt after each error
   348     // new Option("-prompt",                                        "opt.prompt"),
   349     PROMPT("-prompt", null, HIDDEN, BASIC),
   351     // dump stack on error
   352     DOE("-doe", null, HIDDEN, BASIC),
   354     // output source after type erasure
   355     PRINTSOURCE("-printsource", null, HIDDEN, BASIC),
   357     // display warnings for generic unchecked operations
   358     WARNUNCHECKED("-warnunchecked", null, HIDDEN, BASIC) {
   359         @Override
   360         public boolean process(OptionHelper helper, String option) {
   361             helper.put("-Xlint:unchecked", option);
   362             return false;
   363         }
   364     },
   366     XMAXERRS("-Xmaxerrs", "opt.arg.number", "opt.maxerrs", EXTENDED, BASIC),
   368     XMAXWARNS("-Xmaxwarns", "opt.arg.number", "opt.maxwarns", EXTENDED, BASIC),
   370     XSTDOUT("-Xstdout", "opt.arg.file", "opt.Xstdout", EXTENDED, INFO) {
   371         @Override
   372         public boolean process(OptionHelper helper, String option, String arg) {
   373             try {
   374                 Log log = helper.getLog();
   375                 // TODO: this file should be closed at the end of compilation
   376                 log.setWriters(new PrintWriter(new FileWriter(arg), true));
   377             } catch (java.io.IOException e) {
   378                 helper.error("err.error.writing.file", arg, e);
   379                 return true;
   380             }
   381             return super.process(helper, option, arg);
   382         }
   383     },
   385     XPRINT("-Xprint", "opt.print", EXTENDED, BASIC),
   387     XPRINTROUNDS("-XprintRounds", "opt.printRounds", EXTENDED, BASIC),
   389     XPRINTPROCESSORINFO("-XprintProcessorInfo", "opt.printProcessorInfo", EXTENDED, BASIC),
   391     XPREFER("-Xprefer:", "opt.prefer", EXTENDED, BASIC, ONEOF, "source", "newer"),
   393     // see enum PkgInfo
   394     XPKGINFO("-Xpkginfo:", "opt.pkginfo", EXTENDED, BASIC, ONEOF, "always", "legacy", "nonempty"),
   396     /* -O is a no-op, accepted for backward compatibility. */
   397     O("-O", null, HIDDEN, BASIC),
   399     /* -Xjcov produces tables to support the code coverage tool jcov. */
   400     XJCOV("-Xjcov", null, HIDDEN, BASIC),
   402     PLUGIN("-Xplugin:", "opt.arg.plugin", "opt.plugin", EXTENDED, BASIC) {
   403         @Override
   404         public boolean process(OptionHelper helper, String option) {
   405             String p = option.substring(option.indexOf(':') + 1);
   406             String prev = helper.get(PLUGIN);
   407             helper.put(PLUGIN.text, (prev == null) ? p : prev + '\0' + p.trim());
   408             return false;
   409         }
   410     },
   412     XDIAGS("-Xdiags:", "opt.diags", EXTENDED, BASIC, ONEOF, "compact", "verbose"),
   414     /* This is a back door to the compiler's option table.
   415      * -XDx=y sets the option x to the value y.
   416      * -XDx sets the option x to the value x.
   417      */
   418     XD("-XD", null, HIDDEN, BASIC) {
   419         @Override
   420         public boolean matches(String s) {
   421             return s.startsWith(text);
   422         }
   423         @Override
   424         public boolean process(OptionHelper helper, String option) {
   425             option = option.substring(text.length());
   426             int eq = option.indexOf('=');
   427             String key = (eq < 0) ? option : option.substring(0, eq);
   428             String value = (eq < 0) ? option : option.substring(eq+1);
   429             helper.put(key, value);
   430             return false;
   431         }
   432     },
   434     // This option exists only for the purpose of documenting itself.
   435     // It's actually implemented by the CommandLine class.
   436     AT("@", "opt.arg.file", "opt.AT", STANDARD, INFO, true) {
   437         @Override
   438         public boolean process(OptionHelper helper, String option) {
   439             throw new AssertionError("the @ flag should be caught by CommandLine.");
   440         }
   441     },
   443     /*
   444      * TODO: With apt, the matches method accepts anything if
   445      * -XclassAsDecls is used; code elsewhere does the lookup to
   446      * see if the class name is both legal and found.
   447      *
   448      * In apt, the process method adds the candidate class file
   449      * name to a separate list.
   450      */
   451     SOURCEFILE("sourcefile", null, HIDDEN, INFO) {
   452         @Override
   453         public boolean matches(String s) {
   454             return s.endsWith(".java")  // Java source file
   455                 || SourceVersion.isName(s);   // Legal type name
   456         }
   457         @Override
   458         public boolean process(OptionHelper helper, String option) {
   459             if (option.endsWith(".java") ) {
   460                 File f = new File(option);
   461                 if (!f.exists()) {
   462                     helper.error("err.file.not.found", f);
   463                     return true;
   464                 }
   465                 if (!f.isFile()) {
   466                     helper.error("err.file.not.file", f);
   467                     return true;
   468                 }
   469                 helper.addFile(f);
   470             } else {
   471                 helper.addClassName(option);
   472             }
   473             return false;
   474         }
   475     };
   477     /** The kind of an Option. This is used by the -help and -X options. */
   478     public enum OptionKind {
   479         /** A standard option, documented by -help. */
   480         STANDARD,
   481         /** An extended option, documented by -X. */
   482         EXTENDED,
   483         /** A hidden option, not documented. */
   484         HIDDEN,
   485     }
   487     /** The group for an Option. This determines the situations in which the
   488      *  option is applicable. */
   489     enum OptionGroup {
   490         /** A basic option, available for use on the command line or via the
   491          *  Compiler API. */
   492         BASIC,
   493         /** An option for javac's standard JavaFileManager. Other file managers
   494          *  may or may not support these options. */
   495         FILEMANAGER,
   496         /** A command-line option that requests information, such as -help. */
   497         INFO,
   498         /** A command-line "option" representing a file or class name. */
   499         OPERAND
   500     }
   502     /** The kind of choice for "choice" options. */
   503     enum ChoiceKind {
   504         /** The expected value is exactly one of the set of choices. */
   505         ONEOF,
   506         /** The expected value is one of more of the set of choices. */
   507         ANYOF
   508     }
   510     public final String text;
   512     final OptionKind kind;
   514     final OptionGroup group;
   516     /** Documentation key for arguments.
   517      */
   518     final String argsNameKey;
   520     /** Documentation key for description.
   521      */
   522     final String descrKey;
   524     /** Suffix option (-foo=bar or -foo:bar)
   525      */
   526     final boolean hasSuffix;
   528     /** The kind of choices for this option, if any.
   529      */
   530     final ChoiceKind choiceKind;
   532     /** The choices for this option, if any, and whether or not the choices
   533      *  are hidden
   534      */
   535     final Map<String,Boolean> choices;
   538     Option(String text, String descrKey,
   539             OptionKind kind, OptionGroup group) {
   540         this(text, null, descrKey, kind, group, null, null, false);
   541     }
   543     Option(String text, String argsNameKey, String descrKey,
   544             OptionKind kind, OptionGroup group) {
   545         this(text, argsNameKey, descrKey, kind, group, null, null, false);
   546     }
   548     Option(String text, String argsNameKey, String descrKey,
   549             OptionKind kind, OptionGroup group, boolean doHasSuffix) {
   550         this(text, argsNameKey, descrKey, kind, group, null, null, doHasSuffix);
   551     }
   553     Option(String text, String descrKey,
   554             OptionKind kind, OptionGroup group,
   555             ChoiceKind choiceKind, Map<String,Boolean> choices) {
   556         this(text, null, descrKey, kind, group, choiceKind, choices, false);
   557     }
   559     Option(String text, String descrKey,
   560             OptionKind kind, OptionGroup group,
   561             ChoiceKind choiceKind, String... choices) {
   562         this(text, null, descrKey, kind, group, choiceKind,
   563                 createChoices(choices), false);
   564     }
   565     // where
   566         private static Map<String,Boolean> createChoices(String... choices) {
   567             Map<String,Boolean> map = new LinkedHashMap<String,Boolean>();
   568             for (String c: choices)
   569                 map.put(c, false);
   570             return map;
   571         }
   573     private Option(String text, String argsNameKey, String descrKey,
   574             OptionKind kind, OptionGroup group,
   575             ChoiceKind choiceKind, Map<String,Boolean> choices,
   576             boolean doHasSuffix) {
   577         this.text = text;
   578         this.argsNameKey = argsNameKey;
   579         this.descrKey = descrKey;
   580         this.kind = kind;
   581         this.group = group;
   582         this.choiceKind = choiceKind;
   583         this.choices = choices;
   584         char lastChar = text.charAt(text.length()-1);
   585         this.hasSuffix = doHasSuffix || lastChar == ':' || lastChar == '=';
   586     }
   588     public String getText() {
   589         return text;
   590     }
   592     public OptionKind getKind() {
   593         return kind;
   594     }
   596     public boolean hasArg() {
   597         return argsNameKey != null && !hasSuffix;
   598     }
   600     public boolean matches(String option) {
   601         if (!hasSuffix)
   602             return option.equals(text);
   604         if (!option.startsWith(text))
   605             return false;
   607         if (choices != null) {
   608             String arg = option.substring(text.length());
   609             if (choiceKind == ChoiceKind.ONEOF)
   610                 return choices.keySet().contains(arg);
   611             else {
   612                 for (String a: arg.split(",+")) {
   613                     if (!choices.keySet().contains(a))
   614                         return false;
   615                 }
   616             }
   617         }
   619         return true;
   620     }
   622     public boolean process(OptionHelper helper, String option, String arg) {
   623         if (choices != null) {
   624             if (choiceKind == ChoiceKind.ONEOF) {
   625                 // some clients like to see just one of option+choice set
   626                 for (String s: choices.keySet())
   627                     helper.remove(option + s);
   628                 String opt = option + arg;
   629                 helper.put(opt, opt);
   630                 // some clients like to see option (without trailing ":")
   631                 // set to arg
   632                 String nm = option.substring(0, option.length() - 1);
   633                 helper.put(nm, arg);
   634             } else {
   635                 // set option+word for each word in arg
   636                 for (String a: arg.split(",+")) {
   637                     String opt = option + a;
   638                     helper.put(opt, opt);
   639                 }
   640             }
   641         }
   642         helper.put(option, arg);
   643         return false;
   644     }
   646     public boolean process(OptionHelper helper, String option) {
   647         if (hasSuffix)
   648             return process(helper, text, option.substring(text.length()));
   649         else
   650             return process(helper, option, option);
   651     }
   653     void help(Log log, OptionKind kind) {
   654         if (this.kind != kind)
   655             return;
   657         log.printRawLines(WriterKind.NOTICE,
   658                 String.format("  %-26s %s",
   659                     helpSynopsis(log),
   660                     log.localize(PrefixKind.JAVAC, descrKey)));
   662     }
   664     private String helpSynopsis(Log log) {
   665         StringBuilder sb = new StringBuilder();
   666         sb.append(text);
   667         if (argsNameKey == null) {
   668             if (choices != null) {
   669                 String sep = "{";
   670                 for (Map.Entry<String,Boolean> e: choices.entrySet()) {
   671                     if (!e.getValue()) {
   672                         sb.append(sep);
   673                         sb.append(e.getKey());
   674                         sep = ",";
   675                     }
   676                 }
   677                 sb.append("}");
   678             }
   679         } else {
   680             if (!hasSuffix)
   681                 sb.append(" ");
   682             sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
   684         }
   686         return sb.toString();
   687     }
   689     // For -XpkgInfo:value
   690     public enum PkgInfo {
   691         /**
   692          * Always generate package-info.class for every package-info.java file.
   693          * The file may be empty if there annotations with a RetentionPolicy
   694          * of CLASS or RUNTIME.  This option may be useful in conjunction with
   695          * build systems (such as Ant) that expect javac to generate at least
   696          * one .class file for every .java file.
   697          */
   698         ALWAYS,
   699         /**
   700          * Generate a package-info.class file if package-info.java contains
   701          * annotations. The file may be empty if all the annotations have
   702          * a RetentionPolicy of SOURCE.
   703          * This value is just for backwards compatibility with earlier behavior.
   704          * Either of the other two values are to be preferred to using this one.
   705          */
   706         LEGACY,
   707         /**
   708          * Generate a package-info.class file if and only if there are annotations
   709          * in package-info.java to be written into it.
   710          */
   711         NONEMPTY;
   713         public static PkgInfo get(Options options) {
   714             String v = options.get(XPKGINFO);
   715             return (v == null
   716                     ? PkgInfo.LEGACY
   717                     : PkgInfo.valueOf(StringUtils.toUpperCase(v)));
   718         }
   719     }
   721     private static Map<String,Boolean> getXLintChoices() {
   722         Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>();
   723         choices.put("all", false);
   724         for (Lint.LintCategory c : Lint.LintCategory.values())
   725             choices.put(c.option, c.hidden);
   726         for (Lint.LintCategory c : Lint.LintCategory.values())
   727             choices.put("-" + c.option, c.hidden);
   728         choices.put("none", false);
   729         return choices;
   730     }
   732     static Set<Option> getJavaCompilerOptions() {
   733         return EnumSet.allOf(Option.class);
   734     }
   736     public static Set<Option> getJavacFileManagerOptions() {
   737         return getOptions(EnumSet.of(FILEMANAGER));
   738     }
   740     public static Set<Option> getJavacToolOptions() {
   741         return getOptions(EnumSet.of(BASIC));
   742     }
   744     static Set<Option> getOptions(Set<OptionGroup> desired) {
   745         Set<Option> options = EnumSet.noneOf(Option.class);
   746         for (Option option : Option.values())
   747             if (desired.contains(option.group))
   748                 options.add(option);
   749         return Collections.unmodifiableSet(options);
   750     }
   752 }

mercurial