6307187: clean up code for -Xlint:options

Tue, 11 Mar 2008 13:14:55 -0700

author
jjg
date
Tue, 11 Mar 2008 13:14:55 -0700
changeset 11
b66d15dfd001
parent 10
508c01999047
child 12
7366066839bb

6307187: clean up code for -Xlint:options
Summary: introduce common code for handling one-of and any-of options
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/code/Lint.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/JavacOption.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/OptionName.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java file | annotate | diff | comparison | revisions
test/tools/javac/6341866/T6341866.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Lint.java	Thu Mar 06 10:25:04 2008 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Lint.java	Tue Mar 11 13:14:55 2008 -0700
     1.3 @@ -194,7 +194,7 @@
     1.4              return map.get(option);
     1.5          }
     1.6  
     1.7 -        private final String option;
     1.8 +        public final String option;
     1.9      };
    1.10  
    1.11      /**
     2.1 --- a/src/share/classes/com/sun/tools/javac/main/JavacOption.java	Thu Mar 06 10:25:04 2008 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavacOption.java	Tue Mar 11 13:14:55 2008 -0700
     2.3 @@ -28,6 +28,8 @@
     2.4  import com.sun.tools.javac.util.Log;
     2.5  import com.sun.tools.javac.util.Options;
     2.6  import java.io.PrintWriter;
     2.7 +import java.util.Arrays;
     2.8 +import java.util.Collection;
     2.9  
    2.10  /**
    2.11   * TODO: describe com.sun.tools.javac.main.JavacOption
    2.12 @@ -41,19 +43,29 @@
    2.13  
    2.14      OptionKind getKind();
    2.15  
    2.16 -    /** Does this option take a (separate) operand? */
    2.17 +    /** Does this option take a (separate) operand?
    2.18 +     *  @return true if this option takes a separate operand
    2.19 +     */
    2.20      boolean hasArg();
    2.21  
    2.22      /** Does argument string match option pattern?
    2.23 -     *  @param arg        The command line argument string.
    2.24 +     *  @param arg   the command line argument string
    2.25 +     *  @return true if {@code arg} matches this option
    2.26       */
    2.27      boolean matches(String arg);
    2.28  
    2.29 -    /** Process the option (with arg). Return true if error detected.
    2.30 +    /** Process an option with an argument.
    2.31 +     *  @param options the accumulated set of analyzed options
    2.32 +     *  @param option  the option to be processed
    2.33 +     *  @param arg     the arg for the option to be processed
    2.34 +     *  @return true if an error was detected
    2.35       */
    2.36      boolean process(Options options, String option, String arg);
    2.37  
    2.38 -    /** Process the option (without arg). Return true if error detected.
    2.39 +    /** Process the option with no argument.
    2.40 +     *  @param options the accumulated set of analyzed options
    2.41 +     *  @param option  the option to be processed
    2.42 +     *  @return true if an error was detected
    2.43       */
    2.44      boolean process(Options options, String option);
    2.45  
    2.46 @@ -65,6 +77,11 @@
    2.47          HIDDEN,
    2.48      }
    2.49  
    2.50 +    enum ChoiceKind {
    2.51 +        ONEOF,
    2.52 +        ANYOF
    2.53 +    }
    2.54 +
    2.55      /** This class represents an option recognized by the main program
    2.56       */
    2.57      static class Option implements JavacOption {
    2.58 @@ -85,6 +102,14 @@
    2.59           */
    2.60          boolean hasSuffix;
    2.61  
    2.62 +        /** The kind of choices for this option, if any.
    2.63 +         */
    2.64 +        ChoiceKind choiceKind;
    2.65 +
    2.66 +        /** The choices for this option, if any.
    2.67 +         */
    2.68 +        Collection<String> choices;
    2.69 +
    2.70          Option(OptionName name, String argsNameKey, String descrKey) {
    2.71              this.name = name;
    2.72              this.argsNameKey = argsNameKey;
    2.73 @@ -92,51 +117,116 @@
    2.74              char lastChar = name.optionName.charAt(name.optionName.length()-1);
    2.75              hasSuffix = lastChar == ':' || lastChar == '=';
    2.76          }
    2.77 +
    2.78          Option(OptionName name, String descrKey) {
    2.79              this(name, null, descrKey);
    2.80          }
    2.81  
    2.82 +        Option(OptionName name, String descrKey, ChoiceKind choiceKind, String... choices) {
    2.83 +            this(name, descrKey, choiceKind, Arrays.asList(choices));
    2.84 +        }
    2.85 +
    2.86 +        Option(OptionName name, String descrKey, ChoiceKind choiceKind, Collection<String> choices) {
    2.87 +            this(name, null, descrKey);
    2.88 +            if (choiceKind == null || choices == null)
    2.89 +                throw new NullPointerException();
    2.90 +            this.choiceKind = choiceKind;
    2.91 +            this.choices = choices;
    2.92 +        }
    2.93 +
    2.94 +        @Override
    2.95          public String toString() {
    2.96              return name.optionName;
    2.97          }
    2.98  
    2.99 -        /** Does this option take a (separate) operand?
   2.100 -         */
   2.101          public boolean hasArg() {
   2.102              return argsNameKey != null && !hasSuffix;
   2.103          }
   2.104  
   2.105 -        /** Does argument string match option pattern?
   2.106 -         *  @param arg        The command line argument string.
   2.107 -         */
   2.108 -        public boolean matches(String arg) {
   2.109 -            return hasSuffix ? arg.startsWith(name.optionName) : arg.equals(name.optionName);
   2.110 +        public boolean matches(String option) {
   2.111 +            if (!hasSuffix)
   2.112 +                return option.equals(name.optionName);
   2.113 +
   2.114 +            if (!option.startsWith(name.optionName))
   2.115 +                return false;
   2.116 +
   2.117 +            if (choices != null) {
   2.118 +                String arg = option.substring(name.optionName.length());
   2.119 +                if (choiceKind == ChoiceKind.ONEOF)
   2.120 +                    return choices.contains(arg);
   2.121 +                else {
   2.122 +                    for (String a: arg.split(",+")) {
   2.123 +                        if (!choices.contains(a))
   2.124 +                            return false;
   2.125 +                    }
   2.126 +                }
   2.127 +            }
   2.128 +
   2.129 +            return true;
   2.130          }
   2.131  
   2.132          /** Print a line of documentation describing this option, if standard.
   2.133 +         * @param out the stream to which to write the documentation
   2.134           */
   2.135          void help(PrintWriter out) {
   2.136              String s = "  " + helpSynopsis();
   2.137              out.print(s);
   2.138 -            for (int j = s.length(); j < 29; j++) out.print(" ");
   2.139 +            for (int j = Math.min(s.length(), 28); j < 29; j++) out.print(" ");
   2.140              Log.printLines(out, Main.getLocalizedString(descrKey));
   2.141          }
   2.142 +
   2.143          String helpSynopsis() {
   2.144 -            return name +
   2.145 -                (argsNameKey == null ? "" :
   2.146 -                 ((hasSuffix ? "" : " ") +
   2.147 -                  Main.getLocalizedString(argsNameKey)));
   2.148 +            StringBuilder sb = new StringBuilder();
   2.149 +            sb.append(name);
   2.150 +            if (argsNameKey == null) {
   2.151 +                if (choices != null) {
   2.152 +                    String sep = "{";
   2.153 +                    for (String c: choices) {
   2.154 +                        sb.append(sep);
   2.155 +                        sb.append(c);
   2.156 +                        sep = ",";
   2.157 +                    }
   2.158 +                    sb.append("}");
   2.159 +                }
   2.160 +            } else {
   2.161 +                if (!hasSuffix)
   2.162 +                    sb.append(" ");
   2.163 +                sb.append(Main.getLocalizedString(argsNameKey));
   2.164 +            }
   2.165 +
   2.166 +            return sb.toString();
   2.167          }
   2.168  
   2.169          /** Print a line of documentation describing this option, if non-standard.
   2.170 +         *  @param out the stream to which to write the documentation
   2.171           */
   2.172          void xhelp(PrintWriter out) {}
   2.173  
   2.174          /** Process the option (with arg). Return true if error detected.
   2.175           */
   2.176          public boolean process(Options options, String option, String arg) {
   2.177 -            if (options != null)
   2.178 +            if (options != null) {
   2.179 +                if (choices != null) {
   2.180 +                    if (choiceKind == ChoiceKind.ONEOF) {
   2.181 +                        // some clients like to see just one of option+choice set
   2.182 +                        for (String c: choices)
   2.183 +                            options.remove(option + c);
   2.184 +                        String opt = option + arg;
   2.185 +                        options.put(opt, opt);
   2.186 +                        // some clients like to see option (without trailing ":")
   2.187 +                        // set to arg
   2.188 +                        String nm = option.substring(0, option.length() - 1);
   2.189 +                        options.put(nm, arg);
   2.190 +                    } else {
   2.191 +                        // set option+word for each word in arg
   2.192 +                        for (String a: arg.split(",+")) {
   2.193 +                            String opt = option + a;
   2.194 +                            options.put(opt, opt);
   2.195 +                        }
   2.196 +                    }
   2.197 +                }
   2.198                  options.put(option, arg);
   2.199 +            }
   2.200              return false;
   2.201          }
   2.202  
   2.203 @@ -163,8 +253,17 @@
   2.204          XOption(OptionName name, String descrKey) {
   2.205              this(name, null, descrKey);
   2.206          }
   2.207 +        XOption(OptionName name, String descrKey, ChoiceKind kind, String... choices) {
   2.208 +            super(name, descrKey, kind, choices);
   2.209 +        }
   2.210 +        XOption(OptionName name, String descrKey, ChoiceKind kind, Collection<String> choices) {
   2.211 +            super(name, descrKey, kind, choices);
   2.212 +        }
   2.213 +        @Override
   2.214          void help(PrintWriter out) {}
   2.215 +        @Override
   2.216          void xhelp(PrintWriter out) { super.help(out); }
   2.217 +        @Override
   2.218          public OptionKind getKind() { return OptionKind.EXTENDED; }
   2.219      };
   2.220  
   2.221 @@ -177,8 +276,11 @@
   2.222          HiddenOption(OptionName name, String argsNameKey) {
   2.223              super(name, argsNameKey, null);
   2.224          }
   2.225 +        @Override
   2.226          void help(PrintWriter out) {}
   2.227 +        @Override
   2.228          void xhelp(PrintWriter out) {}
   2.229 +        @Override
   2.230          public OptionKind getKind() { return OptionKind.HIDDEN; }
   2.231      };
   2.232  
     3.1 --- a/src/share/classes/com/sun/tools/javac/main/OptionName.java	Thu Mar 06 10:25:04 2008 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javac/main/OptionName.java	Tue Mar 11 13:14:55 2008 -0700
     3.3 @@ -37,13 +37,9 @@
     3.4  public enum OptionName {
     3.5      G("-g"),
     3.6      G_NONE("-g:none"),
     3.7 -    G_CUSTOM("-g:{lines,vars,source}"),
     3.8 +    G_CUSTOM("-g:"),
     3.9      XLINT("-Xlint"),
    3.10 -    XLINT_CUSTOM("-Xlint:{"
    3.11 -                 + "all,"
    3.12 -                 + "cast,deprecation,divzero,empty,unchecked,fallthrough,path,serial,finally,overrides,"
    3.13 -                 + "-cast,-deprecation,-divzero,-empty,-unchecked,-fallthrough,-path,-serial,-finally,-overrides,"
    3.14 -                 + "none}"),
    3.15 +    XLINT_CUSTOM("-Xlint:"),
    3.16      NOWARN("-nowarn"),
    3.17      VERBOSE("-verbose"),
    3.18      DEPRECATION("-deprecation"),
    3.19 @@ -58,12 +54,12 @@
    3.20      DJAVA_EXT_DIRS("-Djava.ext.dirs="),
    3.21      ENDORSEDDIRS("-endorseddirs"),
    3.22      DJAVA_ENDORSED_DIRS("-Djava.endorsed.dirs="),
    3.23 -    PROC_CUSTOM("-proc:{none,only}"),
    3.24 +    PROC("-proc:"),
    3.25      PROCESSOR("-processor"),
    3.26      PROCESSORPATH("-processorpath"),
    3.27      D("-d"),
    3.28      S("-s"),
    3.29 -    IMPLICIT("-implicit:{none,class}"),
    3.30 +    IMPLICIT("-implicit:"),
    3.31      ENCODING("-encoding"),
    3.32      SOURCE("-source"),
    3.33      TARGET("-target"),
    3.34 @@ -86,7 +82,7 @@
    3.35      XPRINT("-Xprint"),
    3.36      XPRINTROUNDS("-XprintRounds"),
    3.37      XPRINTPROCESSORINFO("-XprintProcessorInfo"),
    3.38 -    XPREFER("-Xprefer:{source,newer}"),
    3.39 +    XPREFER("-Xprefer:"),
    3.40      O("-O"),
    3.41      XJCOV("-Xjcov"),
    3.42      XD("-XD"),
     4.1 --- a/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java	Thu Mar 06 10:25:04 2008 -0800
     4.2 +++ b/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java	Tue Mar 11 13:14:55 2008 -0700
     4.3 @@ -25,21 +25,23 @@
     4.4  
     4.5  package com.sun.tools.javac.main;
     4.6  
     4.7 +import com.sun.tools.javac.code.Lint;
     4.8  import com.sun.tools.javac.code.Source;
     4.9  import com.sun.tools.javac.code.Type;
    4.10  import com.sun.tools.javac.jvm.Target;
    4.11  import com.sun.tools.javac.main.JavacOption.HiddenOption;
    4.12  import com.sun.tools.javac.main.JavacOption.Option;
    4.13  import com.sun.tools.javac.main.JavacOption.XOption;
    4.14 -import com.sun.tools.javac.util.List;
    4.15  import com.sun.tools.javac.util.ListBuffer;
    4.16 -import com.sun.tools.javac.util.Log;
    4.17  import com.sun.tools.javac.util.Options;
    4.18  import com.sun.tools.javac.processing.JavacProcessingEnvironment;
    4.19  import java.io.File;
    4.20  import java.io.FileWriter;
    4.21  import java.io.PrintWriter;
    4.22 +import java.util.Arrays;
    4.23 +import java.util.Collection;
    4.24  import java.util.EnumSet;
    4.25 +import java.util.LinkedHashSet;
    4.26  import java.util.Set;
    4.27  import java.util.StringTokenizer;
    4.28  import javax.lang.model.SourceVersion;
    4.29 @@ -134,7 +136,7 @@
    4.30          DJAVA_EXT_DIRS,
    4.31          ENDORSEDDIRS,
    4.32          DJAVA_ENDORSED_DIRS,
    4.33 -        PROC_CUSTOM,
    4.34 +        PROC,
    4.35          PROCESSOR,
    4.36          PROCESSORPATH,
    4.37          D,
    4.38 @@ -195,7 +197,7 @@
    4.39          NOWARN,
    4.40          VERBOSE,
    4.41          DEPRECATION,
    4.42 -        PROC_CUSTOM,
    4.43 +        PROC,
    4.44          PROCESSOR,
    4.45          IMPLICIT,
    4.46          SOURCE,
    4.47 @@ -245,79 +247,58 @@
    4.48      }
    4.49  
    4.50      /**
    4.51 -     * @param out the writer to use for diagnostic output
    4.52 +     * Get all the recognized options.
    4.53 +     * @param helper an {@code OptionHelper} to help when processing options
    4.54 +     * @return an array of options
    4.55       */
    4.56      public static Option[] getAll(final OptionHelper helper) {
    4.57 -        return new Option[]{
    4.58 +        return new Option[] {
    4.59          new Option(G,                                           "opt.g"),
    4.60          new Option(G_NONE,                                      "opt.g.none") {
    4.61 +            @Override
    4.62              public boolean process(Options options, String option) {
    4.63                  options.put("-g:", "none");
    4.64                  return false;
    4.65              }
    4.66          },
    4.67  
    4.68 -        new Option(G_CUSTOM,                                    "opt.g.lines.vars.source") {
    4.69 -            public boolean matches(String s) {
    4.70 -                return s.startsWith("-g:");
    4.71 -            }
    4.72 +        new Option(G_CUSTOM,                                    "opt.g.lines.vars.source",
    4.73 +                Option.ChoiceKind.ANYOF, "lines", "vars", "source"),
    4.74 +
    4.75 +        new XOption(XLINT,                                      "opt.Xlint"),
    4.76 +        new XOption(XLINT_CUSTOM,                               "opt.Xlint.suboptlist",
    4.77 +                Option.ChoiceKind.ANYOF, getXLintChoices()),
    4.78 +
    4.79 +        // -nowarn is retained for command-line backward compatibility
    4.80 +        new Option(NOWARN,                                      "opt.nowarn") {
    4.81 +            @Override
    4.82              public boolean process(Options options, String option) {
    4.83 -                String suboptions = option.substring(3);
    4.84 -                options.put("-g:", suboptions);
    4.85 -                // enter all the -g suboptions as "-g:suboption"
    4.86 -                for (StringTokenizer t = new StringTokenizer(suboptions, ","); t.hasMoreTokens(); ) {
    4.87 -                    String tok = t.nextToken();
    4.88 -                    String opt = "-g:" + tok;
    4.89 -                    options.put(opt, opt);
    4.90 -                }
    4.91 +                options.put("-Xlint:none", option);
    4.92                  return false;
    4.93              }
    4.94          },
    4.95  
    4.96 -        new XOption(XLINT,                                      "opt.Xlint"),
    4.97 -        new XOption(XLINT_CUSTOM,                               "opt.Xlint.suboptlist") {
    4.98 -            public boolean matches(String s) {
    4.99 -                return s.startsWith("-Xlint:");
   4.100 -            }
   4.101 -            public boolean process(Options options, String option) {
   4.102 -                String suboptions = option.substring(7);
   4.103 -                options.put("-Xlint:", suboptions);
   4.104 -                // enter all the -Xlint suboptions as "-Xlint:suboption"
   4.105 -                for (StringTokenizer t = new StringTokenizer(suboptions, ","); t.hasMoreTokens(); ) {
   4.106 -                    String tok = t.nextToken();
   4.107 -                    String opt = "-Xlint:" + tok;
   4.108 -                    options.put(opt, opt);
   4.109 -                }
   4.110 -                return false;
   4.111 -            }
   4.112 -        },
   4.113 -
   4.114 -        // -nowarn is retained for command-line backward compatibility
   4.115 -        new Option(NOWARN,                                      "opt.nowarn") {
   4.116 -                public boolean process(Options options, String option) {
   4.117 -                    options.put("-Xlint:none", option);
   4.118 -                    return false;
   4.119 -                }
   4.120 -            },
   4.121 -
   4.122          new Option(VERBOSE,                                     "opt.verbose"),
   4.123  
   4.124          // -deprecation is retained for command-line backward compatibility
   4.125          new Option(DEPRECATION,                                 "opt.deprecation") {
   4.126 -                public boolean process(Options options, String option) {
   4.127 -                    options.put("-Xlint:deprecation", option);
   4.128 -                    return false;
   4.129 -                }
   4.130 -            },
   4.131 +            @Override
   4.132 +            public boolean process(Options options, String option) {
   4.133 +                options.put("-Xlint:deprecation", option);
   4.134 +                return false;
   4.135 +            }
   4.136 +        },
   4.137  
   4.138          new Option(CLASSPATH,              "opt.arg.path",      "opt.classpath"),
   4.139          new Option(CP,                     "opt.arg.path",      "opt.classpath") {
   4.140 +            @Override
   4.141              public boolean process(Options options, String option, String arg) {
   4.142                  return super.process(options, "-classpath", arg);
   4.143              }
   4.144          },
   4.145          new Option(SOURCEPATH,             "opt.arg.path",      "opt.sourcepath"),
   4.146          new Option(BOOTCLASSPATH,          "opt.arg.path",      "opt.bootclasspath") {
   4.147 +            @Override
   4.148              public boolean process(Options options, String option, String arg) {
   4.149                  options.remove("-Xbootclasspath/p:");
   4.150                  options.remove("-Xbootclasspath/a:");
   4.151 @@ -327,6 +308,7 @@
   4.152          new XOption(XBOOTCLASSPATH_PREPEND,"opt.arg.path", "opt.Xbootclasspath.p"),
   4.153          new XOption(XBOOTCLASSPATH_APPEND, "opt.arg.path", "opt.Xbootclasspath.a"),
   4.154          new XOption(XBOOTCLASSPATH,        "opt.arg.path", "opt.bootclasspath") {
   4.155 +            @Override
   4.156              public boolean process(Options options, String option, String arg) {
   4.157                  options.remove("-Xbootclasspath/p:");
   4.158                  options.remove("-Xbootclasspath/a:");
   4.159 @@ -335,48 +317,29 @@
   4.160          },
   4.161          new Option(EXTDIRS,                "opt.arg.dirs",      "opt.extdirs"),
   4.162          new XOption(DJAVA_EXT_DIRS,        "opt.arg.dirs",      "opt.extdirs") {
   4.163 +            @Override
   4.164              public boolean process(Options options, String option, String arg) {
   4.165                  return super.process(options, "-extdirs", arg);
   4.166              }
   4.167          },
   4.168          new Option(ENDORSEDDIRS,            "opt.arg.dirs",     "opt.endorseddirs"),
   4.169          new XOption(DJAVA_ENDORSED_DIRS,    "opt.arg.dirs",     "opt.endorseddirs") {
   4.170 +            @Override
   4.171              public boolean process(Options options, String option, String arg) {
   4.172                  return super.process(options, "-endorseddirs", arg);
   4.173              }
   4.174          },
   4.175 -        new Option(PROC_CUSTOM,                                 "opt.proc.none.only") {
   4.176 -            public boolean matches(String s) {
   4.177 -                return s.equals("-proc:none") || s.equals("-proc:only");
   4.178 -            }
   4.179 -
   4.180 -            public boolean process(Options options, String option) {
   4.181 -                if (option.equals("-proc:none")) {
   4.182 -                    options.remove("-proc:only");
   4.183 -                } else {
   4.184 -                    options.remove("-proc:none");
   4.185 -                }
   4.186 -                options.put(option, option);
   4.187 -                return false;
   4.188 -            }
   4.189 -        },
   4.190 +        new Option(PROC,                                 "opt.proc.none.only",
   4.191 +                Option.ChoiceKind.ONEOF, "none", "only"),
   4.192          new Option(PROCESSOR,           "opt.arg.class.list",   "opt.processor"),
   4.193          new Option(PROCESSORPATH,       "opt.arg.path",         "opt.processorpath"),
   4.194          new Option(D,                   "opt.arg.directory",    "opt.d"),
   4.195          new Option(S,                   "opt.arg.directory",    "opt.sourceDest"),
   4.196 -        new Option(IMPLICIT,                                    "opt.implicit") {
   4.197 -            public boolean matches(String s) {
   4.198 -                return s.equals("-implicit:none") || s.equals("-implicit:class");
   4.199 -            }
   4.200 -            public boolean process(Options options, String option, String operand) {
   4.201 -                int sep = option.indexOf(":");
   4.202 -                options.put(option.substring(0, sep), option.substring(sep+1));
   4.203 -                options.put(option,option);
   4.204 -                return false;
   4.205 -            }
   4.206 -        },
   4.207 +        new Option(IMPLICIT,                                    "opt.implicit",
   4.208 +                Option.ChoiceKind.ONEOF, "none", "class"),
   4.209          new Option(ENCODING,            "opt.arg.encoding",     "opt.encoding"),
   4.210          new Option(SOURCE,              "opt.arg.release",      "opt.source") {
   4.211 +            @Override
   4.212              public boolean process(Options options, String option, String operand) {
   4.213                  Source source = Source.lookup(operand);
   4.214                  if (source == null) {
   4.215 @@ -387,6 +350,7 @@
   4.216              }
   4.217          },
   4.218          new Option(TARGET,              "opt.arg.release",      "opt.target") {
   4.219 +            @Override
   4.220              public boolean process(Options options, String option, String operand) {
   4.221                  Target target = Target.lookup(operand);
   4.222                  if (target == null) {
   4.223 @@ -397,54 +361,62 @@
   4.224              }
   4.225          },
   4.226          new Option(VERSION,                                     "opt.version") {
   4.227 +            @Override
   4.228              public boolean process(Options options, String option) {
   4.229                  helper.printVersion();
   4.230                  return super.process(options, option);
   4.231              }
   4.232          },
   4.233          new HiddenOption(FULLVERSION) {
   4.234 +            @Override
   4.235              public boolean process(Options options, String option) {
   4.236                  helper.printFullVersion();
   4.237                  return super.process(options, option);
   4.238              }
   4.239          },
   4.240          new Option(HELP,                                        "opt.help") {
   4.241 +            @Override
   4.242              public boolean process(Options options, String option) {
   4.243                  helper.printHelp();
   4.244                  return super.process(options, option);
   4.245              }
   4.246          },
   4.247          new Option(A,                "opt.arg.key.equals.value","opt.A") {
   4.248 -                String helpSynopsis() {
   4.249 -                    hasSuffix = true;
   4.250 -                    return super.helpSynopsis();
   4.251 +            @Override
   4.252 +            String helpSynopsis() {
   4.253 +                hasSuffix = true;
   4.254 +                return super.helpSynopsis();
   4.255 +            }
   4.256 +
   4.257 +            @Override
   4.258 +            public boolean matches(String arg) {
   4.259 +                return arg.startsWith("-A");
   4.260 +            }
   4.261 +
   4.262 +            @Override
   4.263 +            public boolean hasArg() {
   4.264 +                return false;
   4.265 +            }
   4.266 +            // Mapping for processor options created in
   4.267 +            // JavacProcessingEnvironment
   4.268 +            @Override
   4.269 +            public boolean process(Options options, String option) {
   4.270 +                int argLength = option.length();
   4.271 +                if (argLength == 2) {
   4.272 +                    helper.error("err.empty.A.argument");
   4.273 +                    return true;
   4.274                  }
   4.275 -
   4.276 -                public boolean matches(String arg) {
   4.277 -                    return arg.startsWith("-A");
   4.278 +                int sepIndex = option.indexOf('=');
   4.279 +                String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
   4.280 +                if (!JavacProcessingEnvironment.isValidOptionName(key)) {
   4.281 +                    helper.error("err.invalid.A.key", option);
   4.282 +                    return true;
   4.283                  }
   4.284 -
   4.285 -                public boolean hasArg() {
   4.286 -                    return false;
   4.287 -                }
   4.288 -                // Mapping for processor options created in
   4.289 -                // JavacProcessingEnvironment
   4.290 -                public boolean process(Options options, String option) {
   4.291 -                    int argLength = option.length();
   4.292 -                    if (argLength == 2) {
   4.293 -                        helper.error("err.empty.A.argument");
   4.294 -                        return true;
   4.295 -                    }
   4.296 -                    int sepIndex = option.indexOf('=');
   4.297 -                    String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
   4.298 -                    if (!JavacProcessingEnvironment.isValidOptionName(key)) {
   4.299 -                        helper.error("err.invalid.A.key", option);
   4.300 -                        return true;
   4.301 -                    }
   4.302 -                    return process(options, option, option);
   4.303 -                }
   4.304 +                return process(options, option, option);
   4.305 +            }
   4.306          },
   4.307          new Option(X,                                           "opt.X") {
   4.308 +            @Override
   4.309              public boolean process(Options options, String option) {
   4.310                  helper.printXhelp();
   4.311                  return super.process(options, option);
   4.312 @@ -454,10 +426,12 @@
   4.313          // This option exists only for the purpose of documenting itself.
   4.314          // It's actually implemented by the launcher.
   4.315          new Option(J,                   "opt.arg.flag",         "opt.J") {
   4.316 +            @Override
   4.317              String helpSynopsis() {
   4.318                  hasSuffix = true;
   4.319                  return super.helpSynopsis();
   4.320              }
   4.321 +            @Override
   4.322              public boolean process(Options options, String option) {
   4.323                  throw new AssertionError
   4.324                      ("the -J flag should be caught by the launcher.");
   4.325 @@ -469,6 +443,7 @@
   4.326  
   4.327          // new Option("-moreinfo",                                      "opt.moreinfo") {
   4.328          new HiddenOption(MOREINFO) {
   4.329 +            @Override
   4.330              public boolean process(Options options, String option) {
   4.331                  Type.moreInfo = true;
   4.332                  return super.process(options, option);
   4.333 @@ -512,6 +487,7 @@
   4.334  
   4.335          // display warnings for generic unchecked operations
   4.336          new HiddenOption(WARNUNCHECKED) {
   4.337 +            @Override
   4.338              public boolean process(Options options, String option) {
   4.339                  options.put("-Xlint:unchecked", option);
   4.340                  return false;
   4.341 @@ -521,6 +497,7 @@
   4.342          new XOption(XMAXERRS,           "opt.arg.number",       "opt.maxerrs"),
   4.343          new XOption(XMAXWARNS,          "opt.arg.number",       "opt.maxwarns"),
   4.344          new XOption(XSTDOUT,            "opt.arg.file",         "opt.Xstdout") {
   4.345 +            @Override
   4.346              public boolean process(Options options, String option, String arg) {
   4.347                  try {
   4.348                      helper.setOut(new PrintWriter(new FileWriter(arg), true));
   4.349 @@ -538,17 +515,8 @@
   4.350  
   4.351          new XOption(XPRINTPROCESSORINFO,                        "opt.printProcessorInfo"),
   4.352  
   4.353 -        new XOption(XPREFER,                                     "opt.prefer") {
   4.354 -            public boolean matches(String s) {
   4.355 -                return s.equals("-Xprefer:source") || s.equals("-Xprefer:newer");
   4.356 -            }
   4.357 -            public boolean process(Options options, String option, String operand) {
   4.358 -                int sep = option.indexOf(":");
   4.359 -                options.put(option.substring(0, sep), option.substring(sep+1));
   4.360 -                options.put(option,option);
   4.361 -                return false;
   4.362 -            }
   4.363 -        },
   4.364 +        new XOption(XPREFER,                                    "opt.prefer",
   4.365 +                Option.ChoiceKind.ONEOF, "source", "newer"),
   4.366  
   4.367          /* -O is a no-op, accepted for backward compatibility. */
   4.368          new HiddenOption(O),
   4.369 @@ -562,10 +530,12 @@
   4.370           */
   4.371          new HiddenOption(XD) {
   4.372              String s;
   4.373 +            @Override
   4.374              public boolean matches(String s) {
   4.375                  this.s = s;
   4.376                  return s.startsWith(name.optionName);
   4.377              }
   4.378 +            @Override
   4.379              public boolean process(Options options, String option) {
   4.380                  s = s.substring(name.optionName.length());
   4.381                  int eq = s.indexOf('=');
   4.382 @@ -586,11 +556,13 @@
   4.383           */
   4.384          new HiddenOption(SOURCEFILE) {
   4.385              String s;
   4.386 +            @Override
   4.387              public boolean matches(String s) {
   4.388                  this.s = s;
   4.389                  return s.endsWith(".java")  // Java source file
   4.390                      || SourceVersion.isName(s);   // Legal type name
   4.391              }
   4.392 +            @Override
   4.393              public boolean process(Options options, String option) {
   4.394                  if (s.endsWith(".java") ) {
   4.395                      File f = new File(s);
   4.396 @@ -612,4 +584,15 @@
   4.397      };
   4.398      }
   4.399  
   4.400 +    private static Collection<String> getXLintChoices() {
   4.401 +        Collection<String> choices = new LinkedHashSet<String>();
   4.402 +        choices.add("all");
   4.403 +        for (Lint.LintCategory c : Lint.LintCategory.values())
   4.404 +            choices.add(c.option);
   4.405 +        for (Lint.LintCategory c : Lint.LintCategory.values())
   4.406 +            choices.add("-" + c.option);
   4.407 +        choices.add("none");
   4.408 +        return choices;
   4.409 +    }
   4.410 +
   4.411  }
     5.1 --- a/test/tools/javac/6341866/T6341866.java	Thu Mar 06 10:25:04 2008 -0800
     5.2 +++ b/test/tools/javac/6341866/T6341866.java	Tue Mar 11 13:14:55 2008 -0700
     5.3 @@ -186,7 +186,7 @@
     5.4      }
     5.5  
     5.6      static void error(String msg) {
     5.7 -        System.err.println(msg);
     5.8 +        System.err.println("ERROR: " + msg);
     5.9      }
    5.10  
    5.11      static File services(Class<?> service) {

mercurial