Merge jdk8-b19

Fri, 23 Dec 2011 16:39:22 -0800

author
lana
date
Fri, 23 Dec 2011 16:39:22 -0800
changeset 1166
77b2c066084c
parent 1155
3c71fcc22b99
parent 1165
1ae5988e201b
child 1167
ffd294128a48
child 1170
67512b631961

Merge

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
     1.1 --- a/make/jprt.properties	Thu Dec 22 19:00:58 2011 -0800
     1.2 +++ b/make/jprt.properties	Fri Dec 23 16:39:22 2011 -0800
     1.3 @@ -25,23 +25,38 @@
     1.4  
     1.5  # Properties for jprt
     1.6  
     1.7 -# The release to build
     1.8 +# Locked down to jdk8
     1.9  jprt.tools.default.release=jdk8
    1.10  
    1.11  # The different build flavors we want, we override here so we just get these 2
    1.12  jprt.build.flavors=product,fastdebug
    1.13  
    1.14  # Standard list of jprt build targets for this source tree
    1.15 -jprt.build.targets= 						\
    1.16 -    solaris_sparc_5.10-{product|fastdebug}, 			\
    1.17 -    solaris_sparcv9_5.10-{product|fastdebug}, 			\
    1.18 -    solaris_i586_5.10-{product|fastdebug}, 			\
    1.19 -    solaris_x64_5.10-{product|fastdebug}, 			\
    1.20 -    linux_i586_2.6-{product|fastdebug}, 			\
    1.21 -    linux_x64_2.6-{product|fastdebug}, 				\
    1.22 -    windows_i586_5.1-{product|fastdebug}, 			\
    1.23 +jprt.build.targets=                                             \
    1.24 +    solaris_sparc_5.10-{product|fastdebug},                     \
    1.25 +    solaris_sparcv9_5.10-{product|fastdebug},                   \
    1.26 +    solaris_i586_5.10-{product|fastdebug},                      \
    1.27 +    solaris_x64_5.10-{product|fastdebug},                       \
    1.28 +    linux_i586_2.6-{product|fastdebug},                         \
    1.29 +    linux_x64_2.6-{product|fastdebug},                          \
    1.30 +    windows_i586_5.1-{product|fastdebug},                       \
    1.31      windows_x64_5.2-{product|fastdebug}
    1.32  
    1.33 +# Test target list (no fastdebug & limited c2 testing)
    1.34 +jprt.my.test.target.set= 					\
    1.35 +    solaris_sparc_5.10-product-c1-TESTNAME,                     \
    1.36 +    solaris_sparcv9_5.10-product-c2-TESTNAME,                   \
    1.37 +    solaris_i586_5.10-product-c1-TESTNAME,                      \
    1.38 +    solaris_x64_5.10-product-c2-TESTNAME,                       \
    1.39 +    linux_i586_2.6-product-{c1|c2}-TESTNAME,                    \
    1.40 +    linux_x64_2.6-product-c2-TESTNAME,                          \
    1.41 +    windows_i586_5.1-product-c1-TESTNAME,                       \
    1.42 +    windows_x64_5.2-product-c2-TESTNAME
    1.43 +
    1.44 +# Default test targets
    1.45 +jprt.make.rule.test.targets=					\
    1.46 +    ${jprt.my.test.target.set:TESTNAME=jtreg}
    1.47 +
    1.48  # Directories to be excluded from the source bundles
    1.49  jprt.bundle.exclude.src.dirs=build dist webrev
    1.50  
     2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Thu Dec 22 19:00:58 2011 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Fri Dec 23 16:39:22 2011 -0800
     2.3 @@ -216,6 +216,7 @@
     2.4  doclet.Same_package_name_used=Package name format used twice: {0}
     2.5  doclet.Serialization.Excluded_Class=Non-transient field {1} uses excluded class {0}.
     2.6  doclet.Serialization.Nonexcluded_Class=Non-transient field {1} uses hidden, non-included class {0}.
     2.7 +doclet.exception_encountered=Exception encountered while processing {1}\n{0}
     2.8  doclet.usage=Provided by Standard doclet:\n\
     2.9    -d <directory>                    Destination directory for output files\n\
    2.10    -use                              Create class and package usage pages\n\
     3.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTool.java	Thu Dec 22 19:00:58 2011 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTool.java	Fri Dec 23 16:39:22 2011 -0800
     3.3 @@ -25,18 +25,15 @@
     3.4  
     3.5  package com.sun.tools.javac.api;
     3.6  
     3.7 -import java.io.File;
     3.8  import java.io.InputStream;
     3.9  import java.io.OutputStream;
    3.10  import java.io.OutputStreamWriter;
    3.11  import java.io.PrintWriter;
    3.12  import java.io.Writer;
    3.13  import java.nio.charset.Charset;
    3.14 -import java.util.ArrayList;
    3.15  import java.util.Collections;
    3.16  import java.util.EnumSet;
    3.17  import java.util.Iterator;
    3.18 -import java.util.List;
    3.19  import java.util.Locale;
    3.20  import java.util.Set;
    3.21  import javax.lang.model.SourceVersion;
    3.22 @@ -44,17 +41,15 @@
    3.23  
    3.24  import com.sun.source.util.JavacTask;
    3.25  import com.sun.tools.javac.file.JavacFileManager;
    3.26 -import com.sun.tools.javac.main.JavacOption.OptionKind;
    3.27 -import com.sun.tools.javac.main.JavacOption;
    3.28  import com.sun.tools.javac.main.Main;
    3.29 -import com.sun.tools.javac.main.RecognizedOptions.GrumpyHelper;
    3.30 -import com.sun.tools.javac.main.RecognizedOptions;
    3.31 +import com.sun.tools.javac.main.Option;
    3.32 +import com.sun.tools.javac.main.OptionHelper;
    3.33 +import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
    3.34  import com.sun.tools.javac.util.ClientCodeException;
    3.35  import com.sun.tools.javac.util.Context;
    3.36  import com.sun.tools.javac.util.Log;
    3.37  import com.sun.tools.javac.util.Log.PrefixKind;
    3.38  import com.sun.tools.javac.util.Options;
    3.39 -import com.sun.tools.javac.util.Pair;
    3.40  
    3.41  /**
    3.42   * TODO: describe com.sun.tools.javac.api.Tool
    3.43 @@ -67,23 +62,10 @@
    3.44   * @author Peter von der Ah\u00e9
    3.45   */
    3.46  public final class JavacTool implements JavaCompiler {
    3.47 -    private final List<Pair<String,String>> options
    3.48 -        = new ArrayList<Pair<String,String>>();
    3.49 -    private final Context dummyContext = new Context();
    3.50 -
    3.51 -    private final PrintWriter silent = new PrintWriter(new OutputStream(){
    3.52 -        public void write(int b) {}
    3.53 -    });
    3.54 -
    3.55 -    private final Main sharedCompiler = new Main("javac", silent);
    3.56 -    {
    3.57 -        sharedCompiler.setOptions(Options.instance(dummyContext));
    3.58 -    }
    3.59 -
    3.60      /**
    3.61 -     * Constructor used by service provider mechanism.  The correct way to
    3.62 -     * obtain an instance of this class is using create or the service provider
    3.63 -     * mechanism.
    3.64 +     * Constructor used by service provider mechanism.  The recommended way to
    3.65 +     * obtain an instance of this class is by using {@link #create} or the
    3.66 +     * service provider mechanism.
    3.67       * @see javax.tools.JavaCompilerTool
    3.68       * @see javax.tools.ToolProvider
    3.69       * @see #create
    3.70 @@ -99,49 +81,6 @@
    3.71          return new JavacTool();
    3.72      }
    3.73  
    3.74 -    private String argsToString(Object... args) {
    3.75 -        String newArgs = null;
    3.76 -        if (args.length > 0) {
    3.77 -            StringBuilder sb = new StringBuilder();
    3.78 -            String separator = "";
    3.79 -            for (Object arg : args) {
    3.80 -                sb.append(separator).append(arg.toString());
    3.81 -                separator = File.pathSeparator;
    3.82 -            }
    3.83 -            newArgs = sb.toString();
    3.84 -        }
    3.85 -        return newArgs;
    3.86 -    }
    3.87 -
    3.88 -    private void setOption1(String name, OptionKind kind, Object... args) {
    3.89 -        String arg = argsToString(args);
    3.90 -        JavacOption option = sharedCompiler.getOption(name);
    3.91 -        if (option == null || !match(kind, option.getKind()))
    3.92 -            throw new IllegalArgumentException(name);
    3.93 -        if ((args.length != 0) != option.hasArg())
    3.94 -            throw new IllegalArgumentException(name);
    3.95 -        if (option.hasArg()) {
    3.96 -            if (option.process(null, name, arg)) // FIXME
    3.97 -                throw new IllegalArgumentException(name);
    3.98 -        } else {
    3.99 -            if (option.process(null, name)) // FIXME
   3.100 -                throw new IllegalArgumentException(name);
   3.101 -        }
   3.102 -        options.add(new Pair<String,String>(name,arg));
   3.103 -    }
   3.104 -
   3.105 -    public void setOption(String name, Object... args) {
   3.106 -        setOption1(name, OptionKind.NORMAL, args);
   3.107 -    }
   3.108 -
   3.109 -    public void setExtendedOption(String name, Object... args)  {
   3.110 -        setOption1(name, OptionKind.EXTENDED, args);
   3.111 -    }
   3.112 -
   3.113 -    private static boolean match(OptionKind clientKind, OptionKind optionKind) {
   3.114 -        return (clientKind == (optionKind == OptionKind.HIDDEN ? OptionKind.EXTENDED : optionKind));
   3.115 -    }
   3.116 -
   3.117      public JavacFileManager getStandardFileManager(
   3.118          DiagnosticListener<? super JavaFileObject> diagnosticListener,
   3.119          Locale locale,
   3.120 @@ -209,7 +148,9 @@
   3.121              if (fileManager == null)
   3.122                  fileManager = getStandardFileManager(diagnosticListener, null, null);
   3.123              fileManager = ccw.wrap(fileManager);
   3.124 +
   3.125              context.put(JavaFileManager.class, fileManager);
   3.126 +
   3.127              processOptions(context, fileManager, options);
   3.128              Main compiler = new Main("javacTask", context.get(Log.outKey));
   3.129              return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
   3.130 @@ -225,11 +166,28 @@
   3.131          if (options == null)
   3.132              return;
   3.133  
   3.134 -        Options optionTable = Options.instance(context);
   3.135 +        final Options optionTable = Options.instance(context);
   3.136          Log log = Log.instance(context);
   3.137  
   3.138 -        JavacOption[] recognizedOptions =
   3.139 -            RecognizedOptions.getJavacToolOptions(new GrumpyHelper(log));
   3.140 +        Option[] recognizedOptions =
   3.141 +                Option.getJavacToolOptions().toArray(new Option[0]);
   3.142 +        OptionHelper optionHelper = new GrumpyHelper(log) {
   3.143 +            @Override
   3.144 +            public String get(Option option) {
   3.145 +                return optionTable.get(option.getText());
   3.146 +            }
   3.147 +
   3.148 +            @Override
   3.149 +            public void put(String name, String value) {
   3.150 +                optionTable.put(name, value);
   3.151 +            }
   3.152 +
   3.153 +            @Override
   3.154 +            public void remove(String name) {
   3.155 +                optionTable.remove(name);
   3.156 +            }
   3.157 +        };
   3.158 +
   3.159          Iterator<String> flags = options.iterator();
   3.160          while (flags.hasNext()) {
   3.161              String flag = flags.next();
   3.162 @@ -247,19 +205,19 @@
   3.163                  }
   3.164              }
   3.165  
   3.166 -            JavacOption option = recognizedOptions[j];
   3.167 +            Option option = recognizedOptions[j];
   3.168              if (option.hasArg()) {
   3.169                  if (!flags.hasNext()) {
   3.170                      String msg = log.localize(PrefixKind.JAVAC, "err.req.arg", flag);
   3.171                      throw new IllegalArgumentException(msg);
   3.172                  }
   3.173                  String operand = flags.next();
   3.174 -                if (option.process(optionTable, flag, operand))
   3.175 +                if (option.process(optionHelper, flag, operand))
   3.176                      // should not happen as the GrumpyHelper will throw exceptions
   3.177                      // in case of errors
   3.178                      throw new IllegalArgumentException(flag + " " + operand);
   3.179              } else {
   3.180 -                if (option.process(optionTable, flag))
   3.181 +                if (option.process(optionHelper, flag))
   3.182                      // should not happen as the GrumpyHelper will throw exceptions
   3.183                      // in case of errors
   3.184                      throw new IllegalArgumentException(flag);
   3.185 @@ -283,9 +241,8 @@
   3.186      }
   3.187  
   3.188      public int isSupportedOption(String option) {
   3.189 -        JavacOption[] recognizedOptions =
   3.190 -            RecognizedOptions.getJavacToolOptions(new GrumpyHelper(null));
   3.191 -        for (JavacOption o : recognizedOptions) {
   3.192 +        Set<Option> recognizedOptions = Option.getJavacToolOptions();
   3.193 +        for (Option o : recognizedOptions) {
   3.194              if (o.matches(option))
   3.195                  return o.hasArg() ? 1 : 0;
   3.196          }
     4.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java	Thu Dec 22 19:00:58 2011 -0800
     4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java	Fri Dec 23 16:39:22 2011 -0800
     4.3 @@ -32,7 +32,7 @@
     4.4  import com.sun.tools.javac.util.*;
     4.5  import com.sun.tools.javac.jvm.Target;
     4.6  
     4.7 -import static com.sun.tools.javac.main.OptionName.*;
     4.8 +import static com.sun.tools.javac.main.Option.*;
     4.9  
    4.10  /** The source language version accepted.
    4.11   *
     5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Dec 22 19:00:58 2011 -0800
     5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Dec 23 16:39:22 2011 -0800
     5.3 @@ -48,7 +48,6 @@
     5.4  import static com.sun.tools.javac.code.TypeTags.*;
     5.5  import static com.sun.tools.javac.code.TypeTags.WILDCARD;
     5.6  
     5.7 -import static com.sun.tools.javac.main.OptionName.*;
     5.8  import static com.sun.tools.javac.tree.JCTree.Tag.*;
     5.9  
    5.10  /** Type checking helper class for the attribution phase.
    5.11 @@ -110,7 +109,7 @@
    5.12          allowAnnotations = source.allowAnnotations();
    5.13          allowCovariantReturns = source.allowCovariantReturns();
    5.14          allowSimplifiedVarargs = source.allowSimplifiedVarargs();
    5.15 -        complexInference = options.isSet(COMPLEXINFERENCE);
    5.16 +        complexInference = options.isSet("complexinference");
    5.17          skipAnnotations = options.isSet("skipAnnotations");
    5.18          warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts");
    5.19          suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile");
    5.20 @@ -2482,7 +2481,7 @@
    5.21                      warnDeprecated(pos, s);
    5.22                  }
    5.23              });
    5.24 -        };
    5.25 +        }
    5.26      }
    5.27  
    5.28      void checkSunAPI(final DiagnosticPosition pos, final Symbol s) {
     6.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java	Thu Dec 22 19:00:58 2011 -0800
     6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java	Fri Dec 23 16:39:22 2011 -0800
     6.3 @@ -34,7 +34,7 @@
     6.4  import com.sun.tools.javac.code.Symbol.*;
     6.5  import com.sun.tools.javac.code.Type.*;
     6.6  import com.sun.tools.javac.jvm.*;
     6.7 -import com.sun.tools.javac.main.RecognizedOptions.PkgInfo;
     6.8 +import com.sun.tools.javac.main.Option.PkgInfo;
     6.9  import com.sun.tools.javac.tree.*;
    6.10  import com.sun.tools.javac.tree.JCTree.*;
    6.11  import com.sun.tools.javac.util.*;
     7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Thu Dec 22 19:00:58 2011 -0800
     7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Dec 23 16:39:22 2011 -0800
     7.3 @@ -29,7 +29,7 @@
     7.4  
     7.5  import com.sun.tools.javac.code.*;
     7.6  import com.sun.tools.javac.jvm.*;
     7.7 -import com.sun.tools.javac.main.RecognizedOptions.PkgInfo;
     7.8 +import com.sun.tools.javac.main.Option.PkgInfo;
     7.9  import com.sun.tools.javac.tree.*;
    7.10  import com.sun.tools.javac.util.*;
    7.11  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
     8.1 --- a/src/share/classes/com/sun/tools/javac/file/Locations.java	Thu Dec 22 19:00:58 2011 -0800
     8.2 +++ b/src/share/classes/com/sun/tools/javac/file/Locations.java	Fri Dec 23 16:39:22 2011 -0800
     8.3 @@ -47,14 +47,14 @@
     8.4  import javax.tools.StandardLocation;
     8.5  
     8.6  import com.sun.tools.javac.code.Lint;
     8.7 -import com.sun.tools.javac.main.OptionName;
     8.8 +import com.sun.tools.javac.main.Option;
     8.9  import com.sun.tools.javac.util.ListBuffer;
    8.10  import com.sun.tools.javac.util.Log;
    8.11  import com.sun.tools.javac.util.Options;
    8.12  
    8.13  import javax.tools.JavaFileManager;
    8.14  import static javax.tools.StandardLocation.*;
    8.15 -import static com.sun.tools.javac.main.OptionName.*;
    8.16 +import static com.sun.tools.javac.main.Option.*;
    8.17  
    8.18  /** This class converts command line arguments, environment variables
    8.19   *  and system properties (in File.pathSeparator-separated String form)
    8.20 @@ -318,23 +318,23 @@
    8.21       */
    8.22      protected abstract class LocationHandler {
    8.23          final Location location;
    8.24 -        final Set<OptionName> options;
    8.25 +        final Set<Option> options;
    8.26  
    8.27          /**
    8.28           * Create a handler. The location and options provide a way to map
    8.29           * from a location or an option to the corresponding handler.
    8.30           * @see #initHandlers
    8.31           */
    8.32 -        protected LocationHandler(Location location, OptionName... options) {
    8.33 +        protected LocationHandler(Location location, Option... options) {
    8.34              this.location = location;
    8.35              this.options = options.length == 0 ?
    8.36 -                EnumSet.noneOf(OptionName.class):
    8.37 +                EnumSet.noneOf(Option.class):
    8.38                  EnumSet.copyOf(Arrays.asList(options));
    8.39          }
    8.40  
    8.41          // TODO: TEMPORARY, while Options still used for command line options
    8.42          void update(Options optionTable) {
    8.43 -            for (OptionName o: options) {
    8.44 +            for (Option o: options) {
    8.45                  String v = optionTable.get(o);
    8.46                  if (v != null) {
    8.47                      handleOption(o, v);
    8.48 @@ -343,7 +343,7 @@
    8.49          }
    8.50  
    8.51          /** @see JavaFileManager#handleOption. */
    8.52 -        abstract boolean handleOption(OptionName option, String value);
    8.53 +        abstract boolean handleOption(Option option, String value);
    8.54          /** @see JavaFileManager#getLocation. */
    8.55          abstract Collection<File> getLocation();
    8.56          /** @see JavaFileManager#setLocation. */
    8.57 @@ -359,12 +359,12 @@
    8.58      private class OutputLocationHandler extends LocationHandler {
    8.59          private File outputDir;
    8.60  
    8.61 -        OutputLocationHandler(Location location, OptionName... options) {
    8.62 +        OutputLocationHandler(Location location, Option... options) {
    8.63              super(location, options);
    8.64          }
    8.65  
    8.66          @Override
    8.67 -        boolean handleOption(OptionName option, String value) {
    8.68 +        boolean handleOption(Option option, String value) {
    8.69              if (!options.contains(option))
    8.70                  return false;
    8.71  
    8.72 @@ -410,12 +410,12 @@
    8.73      private class SimpleLocationHandler extends LocationHandler {
    8.74          protected Collection<File> searchPath;
    8.75  
    8.76 -        SimpleLocationHandler(Location location, OptionName... options) {
    8.77 +        SimpleLocationHandler(Location location, Option... options) {
    8.78              super(location, options);
    8.79          }
    8.80  
    8.81          @Override
    8.82 -        boolean handleOption(OptionName option, String value) {
    8.83 +        boolean handleOption(Option option, String value) {
    8.84              if (!options.contains(option))
    8.85                  return false;
    8.86              searchPath = value == null ? null :
    8.87 @@ -452,7 +452,7 @@
    8.88      private class ClassPathLocationHandler extends SimpleLocationHandler {
    8.89          ClassPathLocationHandler() {
    8.90              super(StandardLocation.CLASS_PATH,
    8.91 -                    OptionName.CLASSPATH, OptionName.CP);
    8.92 +                    Option.CLASSPATH, Option.CP);
    8.93          }
    8.94  
    8.95          @Override
    8.96 @@ -500,7 +500,7 @@
    8.97       */
    8.98      private class BootClassPathLocationHandler extends LocationHandler {
    8.99          private Collection<File> searchPath;
   8.100 -        final Map<OptionName, String> optionValues = new EnumMap<OptionName,String>(OptionName.class);
   8.101 +        final Map<Option, String> optionValues = new EnumMap<Option,String>(Option.class);
   8.102  
   8.103          /**
   8.104           * rt.jar as found on the default bootclasspath.
   8.105 @@ -515,11 +515,11 @@
   8.106  
   8.107          BootClassPathLocationHandler() {
   8.108              super(StandardLocation.PLATFORM_CLASS_PATH,
   8.109 -                    OptionName.BOOTCLASSPATH, OptionName.XBOOTCLASSPATH,
   8.110 -                    OptionName.XBOOTCLASSPATH_PREPEND,
   8.111 -                    OptionName.XBOOTCLASSPATH_APPEND,
   8.112 -                    OptionName.ENDORSEDDIRS, OptionName.DJAVA_ENDORSED_DIRS,
   8.113 -                    OptionName.EXTDIRS, OptionName.DJAVA_EXT_DIRS);
   8.114 +                    Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH,
   8.115 +                    Option.XBOOTCLASSPATH_PREPEND,
   8.116 +                    Option.XBOOTCLASSPATH_APPEND,
   8.117 +                    Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS,
   8.118 +                    Option.EXTDIRS, Option.DJAVA_EXT_DIRS);
   8.119          }
   8.120  
   8.121          boolean isDefault() {
   8.122 @@ -533,7 +533,7 @@
   8.123          }
   8.124  
   8.125          @Override
   8.126 -        boolean handleOption(OptionName option, String value) {
   8.127 +        boolean handleOption(Option option, String value) {
   8.128              if (!options.contains(option))
   8.129                  return false;
   8.130  
   8.131 @@ -549,14 +549,14 @@
   8.132          // where
   8.133              // TODO: would be better if option aliasing was handled at a higher
   8.134              // level
   8.135 -            private OptionName canonicalize(OptionName option) {
   8.136 +            private Option canonicalize(Option option) {
   8.137                  switch (option) {
   8.138                      case XBOOTCLASSPATH:
   8.139 -                        return OptionName.BOOTCLASSPATH;
   8.140 +                        return Option.BOOTCLASSPATH;
   8.141                      case DJAVA_ENDORSED_DIRS:
   8.142 -                        return OptionName.ENDORSEDDIRS;
   8.143 +                        return Option.ENDORSEDDIRS;
   8.144                      case DJAVA_EXT_DIRS:
   8.145 -                        return OptionName.EXTDIRS;
   8.146 +                        return Option.EXTDIRS;
   8.147                      default:
   8.148                          return option;
   8.149                  }
   8.150 @@ -636,29 +636,29 @@
   8.151      }
   8.152  
   8.153      Map<Location, LocationHandler> handlersForLocation;
   8.154 -    Map<OptionName, LocationHandler> handlersForOption;
   8.155 +    Map<Option, LocationHandler> handlersForOption;
   8.156  
   8.157      void initHandlers() {
   8.158          handlersForLocation = new HashMap<Location, LocationHandler>();
   8.159 -        handlersForOption = new EnumMap<OptionName, LocationHandler>(OptionName.class);
   8.160 +        handlersForOption = new EnumMap<Option, LocationHandler>(Option.class);
   8.161  
   8.162          LocationHandler[] handlers = {
   8.163              new BootClassPathLocationHandler(),
   8.164              new ClassPathLocationHandler(),
   8.165 -            new SimpleLocationHandler(StandardLocation.SOURCE_PATH, OptionName.SOURCEPATH),
   8.166 -            new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, OptionName.PROCESSORPATH),
   8.167 -            new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), OptionName.D),
   8.168 -            new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), OptionName.S)
   8.169 +            new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH),
   8.170 +            new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH),
   8.171 +            new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), Option.D),
   8.172 +            new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), Option.S)
   8.173          };
   8.174  
   8.175          for (LocationHandler h: handlers) {
   8.176              handlersForLocation.put(h.location, h);
   8.177 -            for (OptionName o: h.options)
   8.178 +            for (Option o: h.options)
   8.179                  handlersForOption.put(o, h);
   8.180          }
   8.181      }
   8.182  
   8.183 -    boolean handleOption(OptionName option, String value) {
   8.184 +    boolean handleOption(Option option, String value) {
   8.185          LocationHandler h = handlersForOption.get(option);
   8.186          return (h == null ? false : h.handleOption(option, value));
   8.187      }
     9.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Thu Dec 22 19:00:58 2011 -0800
     9.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Dec 23 16:39:22 2011 -0800
     9.3 @@ -59,7 +59,7 @@
     9.4  import static com.sun.tools.javac.jvm.ClassFile.*;
     9.5  import static com.sun.tools.javac.jvm.ClassFile.Version.*;
     9.6  
     9.7 -import static com.sun.tools.javac.main.OptionName.*;
     9.8 +import static com.sun.tools.javac.main.Option.*;
     9.9  
    9.10  /** This class provides operations to read a classfile into an internal
    9.11   *  representation. The internal representation is anchored in a
    10.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Thu Dec 22 19:00:58 2011 -0800
    10.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Fri Dec 23 16:39:22 2011 -0800
    10.3 @@ -45,7 +45,7 @@
    10.4  import static com.sun.tools.javac.code.Kinds.*;
    10.5  import static com.sun.tools.javac.code.TypeTags.*;
    10.6  import static com.sun.tools.javac.jvm.UninitializedType.*;
    10.7 -import static com.sun.tools.javac.main.OptionName.*;
    10.8 +import static com.sun.tools.javac.main.Option.*;
    10.9  import static javax.tools.StandardLocation.CLASS_OUTPUT;
   10.10  
   10.11  
    11.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Thu Dec 22 19:00:58 2011 -0800
    11.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Dec 23 16:39:22 2011 -0800
    11.3 @@ -45,7 +45,7 @@
    11.4  import static com.sun.tools.javac.code.TypeTags.*;
    11.5  import static com.sun.tools.javac.jvm.ByteCodes.*;
    11.6  import static com.sun.tools.javac.jvm.CRTFlags.*;
    11.7 -import static com.sun.tools.javac.main.OptionName.*;
    11.8 +import static com.sun.tools.javac.main.Option.*;
    11.9  import static com.sun.tools.javac.tree.JCTree.Tag.*;
   11.10  import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
   11.11  
    12.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Target.java	Thu Dec 22 19:00:58 2011 -0800
    12.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Target.java	Fri Dec 23 16:39:22 2011 -0800
    12.3 @@ -31,7 +31,7 @@
    12.4  import com.sun.tools.javac.code.Symbol;
    12.5  import com.sun.tools.javac.util.*;
    12.6  
    12.7 -import static com.sun.tools.javac.main.OptionName.*;
    12.8 +import static com.sun.tools.javac.main.Option.*;
    12.9  
   12.10  /** The classfile version target.
   12.11   *
    13.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Thu Dec 22 19:00:58 2011 -0800
    13.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Dec 23 16:39:22 2011 -0800
    13.3 @@ -62,7 +62,7 @@
    13.4  import com.sun.tools.javac.util.Log.WriterKind;
    13.5  
    13.6  import static javax.tools.StandardLocation.CLASS_OUTPUT;
    13.7 -import static com.sun.tools.javac.main.OptionName.*;
    13.8 +import static com.sun.tools.javac.main.Option.*;
    13.9  import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
   13.10  import static com.sun.tools.javac.util.ListBuffer.lb;
   13.11  
   13.12 @@ -817,8 +817,8 @@
   13.13  
   13.14          // forcibly set the equivalent of -Xlint:-options, so that no further
   13.15          // warnings about command line options are generated from this point on
   13.16 -        options.put(XLINT_CUSTOM + "-" + LintCategory.OPTIONS.option, "true");
   13.17 -        options.remove(XLINT_CUSTOM + LintCategory.OPTIONS.option);
   13.18 +        options.put(XLINT_CUSTOM.text + "-" + LintCategory.OPTIONS.option, "true");
   13.19 +        options.remove(XLINT_CUSTOM.text + LintCategory.OPTIONS.option);
   13.20  
   13.21          start_msec = now();
   13.22  
    14.1 --- a/src/share/classes/com/sun/tools/javac/main/JavacOption.java	Thu Dec 22 19:00:58 2011 -0800
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,299 +0,0 @@
    14.4 -/*
    14.5 - * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
    14.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.7 - *
    14.8 - * This code is free software; you can redistribute it and/or modify it
    14.9 - * under the terms of the GNU General Public License version 2 only, as
   14.10 - * published by the Free Software Foundation.  Oracle designates this
   14.11 - * particular file as subject to the "Classpath" exception as provided
   14.12 - * by Oracle in the LICENSE file that accompanied this code.
   14.13 - *
   14.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   14.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14.17 - * version 2 for more details (a copy is included in the LICENSE file that
   14.18 - * accompanied this code).
   14.19 - *
   14.20 - * You should have received a copy of the GNU General Public License version
   14.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   14.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   14.23 - *
   14.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   14.25 - * or visit www.oracle.com if you need additional information or have any
   14.26 - * questions.
   14.27 - */
   14.28 -
   14.29 -package com.sun.tools.javac.main;
   14.30 -
   14.31 -import java.util.LinkedHashMap;
   14.32 -import java.util.Map;
   14.33 -import com.sun.tools.javac.util.Log;
   14.34 -import com.sun.tools.javac.util.Log.PrefixKind;
   14.35 -import com.sun.tools.javac.util.Log.WriterKind;
   14.36 -import com.sun.tools.javac.util.Options;
   14.37 -
   14.38 -/**
   14.39 - * TODO: describe com.sun.tools.javac.main.JavacOption
   14.40 - *
   14.41 - * <p><b>This is NOT part of any supported API.
   14.42 - * If you write code that depends on this, you do so at your own
   14.43 - * risk.  This code and its internal interfaces are subject to change
   14.44 - * or deletion without notice.</b></p>
   14.45 - */
   14.46 -public interface JavacOption {
   14.47 -
   14.48 -    OptionKind getKind();
   14.49 -
   14.50 -    /** Does this option take a (separate) operand?
   14.51 -     *  @return true if this option takes a separate operand
   14.52 -     */
   14.53 -    boolean hasArg();
   14.54 -
   14.55 -    /** Does argument string match option pattern?
   14.56 -     *  @param arg   the command line argument string
   14.57 -     *  @return true if {@code arg} matches this option
   14.58 -     */
   14.59 -    boolean matches(String arg);
   14.60 -
   14.61 -    /** Process an option with an argument.
   14.62 -     *  @param options the accumulated set of analyzed options
   14.63 -     *  @param option  the option to be processed
   14.64 -     *  @param arg     the arg for the option to be processed
   14.65 -     *  @return true if an error was detected
   14.66 -     */
   14.67 -    boolean process(Options options, String option, String arg);
   14.68 -
   14.69 -    /** Process the option with no argument.
   14.70 -     *  @param options the accumulated set of analyzed options
   14.71 -     *  @param option  the option to be processed
   14.72 -     *  @return true if an error was detected
   14.73 -     */
   14.74 -    boolean process(Options options, String option);
   14.75 -
   14.76 -    OptionName getName();
   14.77 -
   14.78 -    enum OptionKind {
   14.79 -        NORMAL,
   14.80 -        EXTENDED,
   14.81 -        HIDDEN,
   14.82 -    }
   14.83 -
   14.84 -    enum ChoiceKind {
   14.85 -        ONEOF,
   14.86 -        ANYOF
   14.87 -    }
   14.88 -
   14.89 -    /** This class represents an option recognized by the main program
   14.90 -     */
   14.91 -    static class Option implements JavacOption {
   14.92 -
   14.93 -        /** Option string.
   14.94 -         */
   14.95 -        OptionName name;
   14.96 -
   14.97 -        /** Documentation key for arguments.
   14.98 -         */
   14.99 -        String argsNameKey;
  14.100 -
  14.101 -        /** Documentation key for description.
  14.102 -         */
  14.103 -        String descrKey;
  14.104 -
  14.105 -        /** Suffix option (-foo=bar or -foo:bar)
  14.106 -         */
  14.107 -        boolean hasSuffix;
  14.108 -
  14.109 -        /** The kind of choices for this option, if any.
  14.110 -         */
  14.111 -        ChoiceKind choiceKind;
  14.112 -
  14.113 -        /** The choices for this option, if any, and whether or not the choices
  14.114 -         *  are hidden
  14.115 -         */
  14.116 -        Map<String,Boolean> choices;
  14.117 -
  14.118 -        Option(OptionName name, String argsNameKey, String descrKey) {
  14.119 -            this.name = name;
  14.120 -            this.argsNameKey = argsNameKey;
  14.121 -            this.descrKey = descrKey;
  14.122 -            char lastChar = name.optionName.charAt(name.optionName.length()-1);
  14.123 -            hasSuffix = lastChar == ':' || lastChar == '=';
  14.124 -        }
  14.125 -
  14.126 -        Option(OptionName name, String descrKey) {
  14.127 -            this(name, null, descrKey);
  14.128 -        }
  14.129 -
  14.130 -        Option(OptionName name, String descrKey, ChoiceKind choiceKind, String... choices) {
  14.131 -            this(name, descrKey, choiceKind, createChoices(choices));
  14.132 -        }
  14.133 -
  14.134 -        private static Map<String,Boolean> createChoices(String... choices) {
  14.135 -            Map<String,Boolean> map = new LinkedHashMap<String,Boolean>();
  14.136 -            for (String c: choices)
  14.137 -                map.put(c, false);
  14.138 -            return map;
  14.139 -        }
  14.140 -
  14.141 -        Option(OptionName name, String descrKey, ChoiceKind choiceKind,
  14.142 -                Map<String,Boolean> choices) {
  14.143 -            this(name, null, descrKey);
  14.144 -            if (choiceKind == null || choices == null)
  14.145 -                throw new NullPointerException();
  14.146 -            this.choiceKind = choiceKind;
  14.147 -            this.choices = choices;
  14.148 -        }
  14.149 -
  14.150 -        @Override
  14.151 -        public String toString() {
  14.152 -            return name.optionName;
  14.153 -        }
  14.154 -
  14.155 -        public boolean hasArg() {
  14.156 -            return argsNameKey != null && !hasSuffix;
  14.157 -        }
  14.158 -
  14.159 -        public boolean matches(String option) {
  14.160 -            if (!hasSuffix)
  14.161 -                return option.equals(name.optionName);
  14.162 -
  14.163 -            if (!option.startsWith(name.optionName))
  14.164 -                return false;
  14.165 -
  14.166 -            if (choices != null) {
  14.167 -                String arg = option.substring(name.optionName.length());
  14.168 -                if (choiceKind == ChoiceKind.ONEOF)
  14.169 -                    return choices.keySet().contains(arg);
  14.170 -                else {
  14.171 -                    for (String a: arg.split(",+")) {
  14.172 -                        if (!choices.keySet().contains(a))
  14.173 -                            return false;
  14.174 -                    }
  14.175 -                }
  14.176 -            }
  14.177 -
  14.178 -            return true;
  14.179 -        }
  14.180 -
  14.181 -        /** Print a line of documentation describing this option, if standard.
  14.182 -         * @param out the stream to which to write the documentation
  14.183 -         */
  14.184 -        void help(Log log) {
  14.185 -            log.printRawLines(WriterKind.NOTICE,
  14.186 -                    String.format("  %-26s %s",
  14.187 -                        helpSynopsis(log),
  14.188 -                        log.localize(PrefixKind.JAVAC, descrKey)));
  14.189 -        }
  14.190 -
  14.191 -        String helpSynopsis(Log log) {
  14.192 -            StringBuilder sb = new StringBuilder();
  14.193 -            sb.append(name);
  14.194 -            if (argsNameKey == null) {
  14.195 -                if (choices != null) {
  14.196 -                    String sep = "{";
  14.197 -                    for (Map.Entry<String,Boolean> e: choices.entrySet()) {
  14.198 -                        if (!e.getValue()) {
  14.199 -                            sb.append(sep);
  14.200 -                            sb.append(e.getKey());
  14.201 -                            sep = ",";
  14.202 -                        }
  14.203 -                    }
  14.204 -                    sb.append("}");
  14.205 -                }
  14.206 -            } else {
  14.207 -                if (!hasSuffix)
  14.208 -                    sb.append(" ");
  14.209 -                sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
  14.210 -            }
  14.211 -
  14.212 -            return sb.toString();
  14.213 -        }
  14.214 -
  14.215 -        /** Print a line of documentation describing this option, if non-standard.
  14.216 -         *  @param out the stream to which to write the documentation
  14.217 -         */
  14.218 -        void xhelp(Log log) {}
  14.219 -
  14.220 -        /** Process the option (with arg). Return true if error detected.
  14.221 -         */
  14.222 -        public boolean process(Options options, String option, String arg) {
  14.223 -            if (options != null) {
  14.224 -                if (choices != null) {
  14.225 -                    if (choiceKind == ChoiceKind.ONEOF) {
  14.226 -                        // some clients like to see just one of option+choice set
  14.227 -                        for (String s: choices.keySet())
  14.228 -                            options.remove(option + s);
  14.229 -                        String opt = option + arg;
  14.230 -                        options.put(opt, opt);
  14.231 -                        // some clients like to see option (without trailing ":")
  14.232 -                        // set to arg
  14.233 -                        String nm = option.substring(0, option.length() - 1);
  14.234 -                        options.put(nm, arg);
  14.235 -                    } else {
  14.236 -                        // set option+word for each word in arg
  14.237 -                        for (String a: arg.split(",+")) {
  14.238 -                            String opt = option + a;
  14.239 -                            options.put(opt, opt);
  14.240 -                        }
  14.241 -                    }
  14.242 -                }
  14.243 -                options.put(option, arg);
  14.244 -            }
  14.245 -            return false;
  14.246 -        }
  14.247 -
  14.248 -        /** Process the option (without arg). Return true if error detected.
  14.249 -         */
  14.250 -        public boolean process(Options options, String option) {
  14.251 -            if (hasSuffix)
  14.252 -                return process(options, name.optionName, option.substring(name.optionName.length()));
  14.253 -            else
  14.254 -                return process(options, option, option);
  14.255 -        }
  14.256 -
  14.257 -        public OptionKind getKind() { return OptionKind.NORMAL; }
  14.258 -
  14.259 -        public OptionName getName() { return name; }
  14.260 -    };
  14.261 -
  14.262 -    /** A nonstandard or extended (-X) option
  14.263 -     */
  14.264 -    static class XOption extends Option {
  14.265 -        XOption(OptionName name, String argsNameKey, String descrKey) {
  14.266 -            super(name, argsNameKey, descrKey);
  14.267 -        }
  14.268 -        XOption(OptionName name, String descrKey) {
  14.269 -            this(name, null, descrKey);
  14.270 -        }
  14.271 -        XOption(OptionName name, String descrKey, ChoiceKind kind, String... choices) {
  14.272 -            super(name, descrKey, kind, choices);
  14.273 -        }
  14.274 -        XOption(OptionName name, String descrKey, ChoiceKind kind, Map<String,Boolean> choices) {
  14.275 -            super(name, descrKey, kind, choices);
  14.276 -        }
  14.277 -        @Override
  14.278 -        void help(Log log) {}
  14.279 -        @Override
  14.280 -        void xhelp(Log log) { super.help(log); }
  14.281 -        @Override
  14.282 -        public OptionKind getKind() { return OptionKind.EXTENDED; }
  14.283 -    };
  14.284 -
  14.285 -    /** A hidden (implementor) option
  14.286 -     */
  14.287 -    static class HiddenOption extends Option {
  14.288 -        HiddenOption(OptionName name) {
  14.289 -            super(name, null, null);
  14.290 -        }
  14.291 -        HiddenOption(OptionName name, String argsNameKey) {
  14.292 -            super(name, argsNameKey, null);
  14.293 -        }
  14.294 -        @Override
  14.295 -        void help(Log log) {}
  14.296 -        @Override
  14.297 -        void xhelp(Log log) {}
  14.298 -        @Override
  14.299 -        public OptionKind getKind() { return OptionKind.HIDDEN; }
  14.300 -    };
  14.301 -
  14.302 -}
    15.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java	Thu Dec 22 19:00:58 2011 -0800
    15.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java	Fri Dec 23 16:39:22 2011 -0800
    15.3 @@ -42,14 +42,12 @@
    15.4  import com.sun.tools.javac.file.CacheFSInfo;
    15.5  import com.sun.tools.javac.file.JavacFileManager;
    15.6  import com.sun.tools.javac.jvm.Target;
    15.7 -import com.sun.tools.javac.main.JavacOption.Option;
    15.8 -import com.sun.tools.javac.main.RecognizedOptions.OptionHelper;
    15.9  import com.sun.tools.javac.util.*;
   15.10  import com.sun.tools.javac.util.Log.WriterKind;
   15.11  import com.sun.tools.javac.util.Log.PrefixKind;
   15.12  import com.sun.tools.javac.processing.AnnotationProcessingError;
   15.13  
   15.14 -import static com.sun.tools.javac.main.OptionName.*;
   15.15 +import static com.sun.tools.javac.main.Option.*;
   15.16  
   15.17  /** This class provides a commandline interface to the GJC compiler.
   15.18   *
   15.19 @@ -99,42 +97,51 @@
   15.20          public final int exitCode;
   15.21      }
   15.22  
   15.23 -    private Option[] recognizedOptions = RecognizedOptions.getJavaCompilerOptions(new OptionHelper() {
   15.24 +    private Option[] recognizedOptions =
   15.25 +            Option.getJavaCompilerOptions().toArray(new Option[0]);
   15.26  
   15.27 -        public void setOut(PrintWriter out) {
   15.28 -            Main.this.out = out;
   15.29 -            Main.this.log.setWriters(out);
   15.30 +    private OptionHelper optionHelper = new OptionHelper() {
   15.31 +        @Override
   15.32 +        public String get(Option option) {
   15.33 +            return options.get(option);
   15.34          }
   15.35  
   15.36 +        @Override
   15.37 +        public void put(String name, String value) {
   15.38 +            options.put(name, value);
   15.39 +        }
   15.40 +
   15.41 +        @Override
   15.42 +        public void remove(String name) {
   15.43 +            options.remove(name);
   15.44 +        }
   15.45 +
   15.46 +        @Override
   15.47 +        public Log getLog() {
   15.48 +            return log;
   15.49 +        }
   15.50 +
   15.51 +        @Override
   15.52 +        public String getOwnName() {
   15.53 +            return ownName;
   15.54 +        }
   15.55 +
   15.56 +        @Override
   15.57          public void error(String key, Object... args) {
   15.58              Main.this.error(key, args);
   15.59          }
   15.60  
   15.61 -        public void printVersion() {
   15.62 -            log.printLines(PrefixKind.JAVAC, "version", ownName,  JavaCompiler.version());
   15.63 -        }
   15.64 -
   15.65 -        public void printFullVersion() {
   15.66 -            log.printLines(PrefixKind.JAVAC, "fullVersion", ownName,  JavaCompiler.fullVersion());
   15.67 -        }
   15.68 -
   15.69 -        public void printHelp() {
   15.70 -            help();
   15.71 -        }
   15.72 -
   15.73 -        public void printXhelp() {
   15.74 -            xhelp();
   15.75 -        }
   15.76 -
   15.77 +        @Override
   15.78          public void addFile(File f) {
   15.79              filenames.add(f);
   15.80          }
   15.81  
   15.82 +        @Override
   15.83          public void addClassName(String s) {
   15.84              classnames.append(s);
   15.85          }
   15.86  
   15.87 -    });
   15.88 +    };
   15.89  
   15.90      /**
   15.91       * Construct a compiler instance.
   15.92 @@ -161,26 +168,6 @@
   15.93       */
   15.94      public ListBuffer<String> classnames = null; // XXX sb protected
   15.95  
   15.96 -    /** Print a string that explains usage.
   15.97 -     */
   15.98 -    void help() {
   15.99 -        log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName);
  15.100 -        for (int i=0; i<recognizedOptions.length; i++) {
  15.101 -            recognizedOptions[i].help(log);
  15.102 -        }
  15.103 -        log.printNewline();
  15.104 -    }
  15.105 -
  15.106 -    /** Print a string that explains usage for X options.
  15.107 -     */
  15.108 -    void xhelp() {
  15.109 -        for (int i=0; i<recognizedOptions.length; i++) {
  15.110 -            recognizedOptions[i].xhelp(log);
  15.111 -        }
  15.112 -        log.printNewline();
  15.113 -        log.printLines(PrefixKind.JAVAC, "msg.usage.nonstandard.footer");
  15.114 -    }
  15.115 -
  15.116      /** Report a usage error.
  15.117       */
  15.118      void error(String key, Object... args) {
  15.119 @@ -253,10 +240,10 @@
  15.120                  }
  15.121                  String operand = flags[ac];
  15.122                  ac++;
  15.123 -                if (option.process(options, flag, operand))
  15.124 +                if (option.process(optionHelper, flag, operand))
  15.125                      return null;
  15.126              } else {
  15.127 -                if (option.process(options, flag))
  15.128 +                if (option.process(optionHelper, flag))
  15.129                      return null;
  15.130              }
  15.131          }
  15.132 @@ -317,8 +304,8 @@
  15.133          return filenames;
  15.134      }
  15.135      // where
  15.136 -        private boolean checkDirectory(OptionName optName) {
  15.137 -            String value = options.get(optName);
  15.138 +        private boolean checkDirectory(Option option) {
  15.139 +            String value = options.get(option);
  15.140              if (value == null)
  15.141                  return true;
  15.142              File file = new File(value);
  15.143 @@ -375,7 +362,7 @@
  15.144           */
  15.145          try {
  15.146              if (args.length == 0 && fileObjects.isEmpty()) {
  15.147 -                help();
  15.148 +                Option.HELP.process(optionHelper, "-help");
  15.149                  return Result.CMDERR;
  15.150              }
  15.151  
  15.152 @@ -407,8 +394,7 @@
  15.153              boolean forceStdOut = options.isSet("stdout");
  15.154              if (forceStdOut) {
  15.155                  log.flush();
  15.156 -                out = new PrintWriter(System.out, true);
  15.157 -                log.setWriters(out);
  15.158 +                log.setWriters(new PrintWriter(System.out, true));
  15.159              }
  15.160  
  15.161              // allow System property in following line as a Mustang legacy
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/share/classes/com/sun/tools/javac/main/Option.java	Fri Dec 23 16:39:22 2011 -0800
    16.3 @@ -0,0 +1,710 @@
    16.4 +/*
    16.5 + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
    16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.7 + *
    16.8 + * This code is free software; you can redistribute it and/or modify it
    16.9 + * under the terms of the GNU General Public License version 2 only, as
   16.10 + * published by the Free Software Foundation.  Oracle designates this
   16.11 + * particular file as subject to the "Classpath" exception as provided
   16.12 + * by Oracle in the LICENSE file that accompanied this code.
   16.13 + *
   16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.17 + * version 2 for more details (a copy is included in the LICENSE file that
   16.18 + * accompanied this code).
   16.19 + *
   16.20 + * You should have received a copy of the GNU General Public License version
   16.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.23 + *
   16.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   16.25 + * or visit www.oracle.com if you need additional information or have any
   16.26 + * questions.
   16.27 + */
   16.28 +
   16.29 +package com.sun.tools.javac.main;
   16.30 +
   16.31 +import java.util.Collections;
   16.32 +import com.sun.tools.javac.util.Log.PrefixKind;
   16.33 +import com.sun.tools.javac.util.Log.WriterKind;
   16.34 +import com.sun.tools.javac.util.Log;
   16.35 +import com.sun.tools.javac.code.Lint;
   16.36 +import com.sun.tools.javac.code.Source;
   16.37 +import com.sun.tools.javac.code.Type;
   16.38 +import com.sun.tools.javac.jvm.Target;
   16.39 +import com.sun.tools.javac.util.Options;
   16.40 +import com.sun.tools.javac.processing.JavacProcessingEnvironment;
   16.41 +import java.io.File;
   16.42 +import java.io.FileWriter;
   16.43 +import java.io.PrintWriter;
   16.44 +import java.util.EnumSet;
   16.45 +import java.util.LinkedHashMap;
   16.46 +import java.util.Map;
   16.47 +import java.util.Set;
   16.48 +import javax.lang.model.SourceVersion;
   16.49 +
   16.50 +import static com.sun.tools.javac.main.Option.ChoiceKind.*;
   16.51 +import static com.sun.tools.javac.main.Option.OptionKind.*;
   16.52 +import static com.sun.tools.javac.main.Option.OptionGroup.*;
   16.53 +
   16.54 +/**
   16.55 + * Options for javac. The specific Option to handle a command-line option
   16.56 + * is identified by searching the members of this enum in order, looking
   16.57 + * the first {@link #matches match}. The action for an Option is performed
   16.58 + * by calling {@link #process process}, and by providing a suitable
   16.59 + * {@link OptionHelper} to provide access the compiler state.
   16.60 + *
   16.61 + * <p><b>This is NOT part of any supported API.
   16.62 + * If you write code that depends on this, you do so at your own
   16.63 + * risk.  This code and its internal interfaces are subject to change
   16.64 + * or deletion without notice.</b></p>
   16.65 + */
   16.66 +public enum Option {
   16.67 +    G("-g", "opt.g", STANDARD, BASIC),
   16.68 +
   16.69 +    G_NONE("-g:none", "opt.g.none", STANDARD, BASIC) {
   16.70 +        @Override
   16.71 +        public boolean process(OptionHelper helper, String option) {
   16.72 +            helper.put("-g:", "none");
   16.73 +            return false;
   16.74 +        }
   16.75 +    },
   16.76 +
   16.77 +    G_CUSTOM("-g:",  "opt.g.lines.vars.source",
   16.78 +            STANDARD, BASIC, ANYOF, "lines", "vars", "source"),
   16.79 +
   16.80 +    XLINT("-Xlint", "opt.Xlint", EXTENDED, BASIC),
   16.81 +
   16.82 +    XLINT_CUSTOM("-Xlint:", "opt.Xlint.suboptlist",
   16.83 +            EXTENDED,   BASIC, ANYOF, getXLintChoices()),
   16.84 +
   16.85 +    // -nowarn is retained for command-line backward compatibility
   16.86 +    NOWARN("-nowarn", "opt.nowarn", STANDARD, BASIC) {
   16.87 +        @Override
   16.88 +        public boolean process(OptionHelper helper, String option) {
   16.89 +            helper.put("-Xlint:none", option);
   16.90 +            return false;
   16.91 +        }
   16.92 +    },
   16.93 +
   16.94 +    VERBOSE("-verbose", "opt.verbose", STANDARD, BASIC),
   16.95 +
   16.96 +    // -deprecation is retained for command-line backward compatibility
   16.97 +    DEPRECATION("-deprecation", "opt.deprecation", STANDARD, BASIC) {
   16.98 +        @Override
   16.99 +        public boolean process(OptionHelper helper, String option) {
  16.100 +            helper.put("-Xlint:deprecation", option);
  16.101 +            return false;
  16.102 +        }
  16.103 +    },
  16.104 +
  16.105 +    CLASSPATH("-classpath", "opt.arg.path", "opt.classpath", STANDARD, FILEMANAGER),
  16.106 +
  16.107 +    CP("-cp", "opt.arg.path", "opt.classpath", STANDARD, FILEMANAGER) {
  16.108 +        @Override
  16.109 +        public boolean process(OptionHelper helper, String option, String arg) {
  16.110 +            return super.process(helper, "-classpath", arg);
  16.111 +        }
  16.112 +    },
  16.113 +
  16.114 +    SOURCEPATH("-sourcepath", "opt.arg.path", "opt.sourcepath", STANDARD, FILEMANAGER),
  16.115 +
  16.116 +    BOOTCLASSPATH("-bootclasspath", "opt.arg.path", "opt.bootclasspath", STANDARD, FILEMANAGER) {
  16.117 +        @Override
  16.118 +        public boolean process(OptionHelper helper, String option, String arg) {
  16.119 +            helper.remove("-Xbootclasspath/p:");
  16.120 +            helper.remove("-Xbootclasspath/a:");
  16.121 +            return super.process(helper, option, arg);
  16.122 +        }
  16.123 +    },
  16.124 +
  16.125 +    XBOOTCLASSPATH_PREPEND("-Xbootclasspath/p:", "opt.arg.path", "opt.Xbootclasspath.p", EXTENDED, FILEMANAGER),
  16.126 +
  16.127 +    XBOOTCLASSPATH_APPEND("-Xbootclasspath/a:", "opt.arg.path", "opt.Xbootclasspath.a", EXTENDED, FILEMANAGER),
  16.128 +
  16.129 +    XBOOTCLASSPATH("-Xbootclasspath:", "opt.arg.path", "opt.bootclasspath", EXTENDED, FILEMANAGER) {
  16.130 +        @Override
  16.131 +        public boolean process(OptionHelper helper, String option, String arg) {
  16.132 +            helper.remove("-Xbootclasspath/p:");
  16.133 +            helper.remove("-Xbootclasspath/a:");
  16.134 +            return super.process(helper, "-bootclasspath", arg);
  16.135 +        }
  16.136 +    },
  16.137 +
  16.138 +    EXTDIRS("-extdirs", "opt.arg.dirs", "opt.extdirs", STANDARD, FILEMANAGER),
  16.139 +
  16.140 +    DJAVA_EXT_DIRS("-Djava.ext.dirs=", "opt.arg.dirs", "opt.extdirs", EXTENDED, FILEMANAGER) {
  16.141 +        @Override
  16.142 +        public boolean process(OptionHelper helper, String option, String arg) {
  16.143 +            return super.process(helper, "-extdirs", arg);
  16.144 +        }
  16.145 +    },
  16.146 +
  16.147 +    ENDORSEDDIRS("-endorseddirs", "opt.arg.dirs", "opt.endorseddirs", STANDARD, FILEMANAGER),
  16.148 +
  16.149 +    DJAVA_ENDORSED_DIRS("-Djava.endorsed.dirs=", "opt.arg.dirs", "opt.endorseddirs", EXTENDED, FILEMANAGER) {
  16.150 +        @Override
  16.151 +        public boolean process(OptionHelper helper, String option, String arg) {
  16.152 +            return super.process(helper, "-endorseddirs", arg);
  16.153 +        }
  16.154 +    },
  16.155 +
  16.156 +    PROC("-proc:", "opt.proc.none.only", STANDARD, BASIC,  ONEOF, "none", "only"),
  16.157 +
  16.158 +    PROCESSOR("-processor", "opt.arg.class.list", "opt.processor", STANDARD, BASIC),
  16.159 +
  16.160 +    PROCESSORPATH("-processorpath", "opt.arg.path", "opt.processorpath", STANDARD, FILEMANAGER),
  16.161 +
  16.162 +    D("-d", "opt.arg.directory", "opt.d", STANDARD, FILEMANAGER),
  16.163 +
  16.164 +    S("-s", "opt.arg.directory", "opt.sourceDest", STANDARD, FILEMANAGER),
  16.165 +
  16.166 +    IMPLICIT("-implicit:", "opt.implicit", STANDARD, BASIC, ONEOF, "none", "class"),
  16.167 +
  16.168 +    ENCODING("-encoding", "opt.arg.encoding", "opt.encoding", STANDARD, FILEMANAGER) {
  16.169 +        @Override
  16.170 +        public boolean process(OptionHelper helper, String option, String operand) {
  16.171 +//            System.err.println("process encoding " + operand);
  16.172 +            return super.process(helper, option, operand);
  16.173 +        }
  16.174 +
  16.175 +    },
  16.176 +
  16.177 +    SOURCE("-source", "opt.arg.release", "opt.source", STANDARD, BASIC) {
  16.178 +        @Override
  16.179 +        public boolean process(OptionHelper helper, String option, String operand) {
  16.180 +            Source source = Source.lookup(operand);
  16.181 +            if (source == null) {
  16.182 +                helper.error("err.invalid.source", operand);
  16.183 +                return true;
  16.184 +            }
  16.185 +            return super.process(helper, option, operand);
  16.186 +        }
  16.187 +    },
  16.188 +
  16.189 +    TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) {
  16.190 +        @Override
  16.191 +        public boolean process(OptionHelper helper, String option, String operand) {
  16.192 +            Target target = Target.lookup(operand);
  16.193 +            if (target == null) {
  16.194 +                helper.error("err.invalid.target", operand);
  16.195 +                return true;
  16.196 +            }
  16.197 +            return super.process(helper, option, operand);
  16.198 +        }
  16.199 +    },
  16.200 +
  16.201 +    VERSION("-version", "opt.version", STANDARD, INFO) {
  16.202 +        @Override
  16.203 +        public boolean process(OptionHelper helper, String option) {
  16.204 +            Log log = helper.getLog();
  16.205 +            String ownName = helper.getOwnName();
  16.206 +            log.printLines(PrefixKind.JAVAC, "version", ownName,  JavaCompiler.version());
  16.207 +            return super.process(helper, option);
  16.208 +        }
  16.209 +    },
  16.210 +
  16.211 +    FULLVERSION("-fullversion", null, HIDDEN, INFO) {
  16.212 +        @Override
  16.213 +        public boolean process(OptionHelper helper, String option) {
  16.214 +            Log log = helper.getLog();
  16.215 +            String ownName = helper.getOwnName();
  16.216 +            log.printLines(PrefixKind.JAVAC, "fullVersion", ownName,  JavaCompiler.fullVersion());
  16.217 +            return super.process(helper, option);
  16.218 +        }
  16.219 +    },
  16.220 +
  16.221 +    DIAGS("-XDdiags=", null, HIDDEN, INFO) {
  16.222 +        @Override
  16.223 +        public boolean process(OptionHelper helper, String option) {
  16.224 +            option = option.substring(option.indexOf('=') + 1);
  16.225 +            String diagsOption = option.contains("%") ?
  16.226 +                "-XDdiagsFormat=" :
  16.227 +                "-XDdiags=";
  16.228 +            diagsOption += option;
  16.229 +            if (XD.matches(diagsOption))
  16.230 +                return XD.process(helper, diagsOption);
  16.231 +            else
  16.232 +                return false;
  16.233 +        }
  16.234 +    },
  16.235 +
  16.236 +    HELP("-help", "opt.help", STANDARD, INFO) {
  16.237 +        @Override
  16.238 +        public boolean process(OptionHelper helper, String option) {
  16.239 +            Log log = helper.getLog();
  16.240 +            String ownName = helper.getOwnName();
  16.241 +            log.printLines(PrefixKind.JAVAC, "msg.usage.header", ownName);
  16.242 +            for (Option o: getJavaCompilerOptions()) {
  16.243 +                o.help(log, OptionKind.STANDARD);
  16.244 +            }
  16.245 +            log.printNewline();
  16.246 +            return super.process(helper, option);
  16.247 +        }
  16.248 +    },
  16.249 +
  16.250 +    A("-A", "opt.arg.key.equals.value", "opt.A", STANDARD, BASIC) {
  16.251 +        { hasSuffix = true; }
  16.252 +
  16.253 +        @Override
  16.254 +        public boolean matches(String arg) {
  16.255 +            return arg.startsWith("-A");
  16.256 +        }
  16.257 +
  16.258 +        @Override
  16.259 +        public boolean hasArg() {
  16.260 +            return false;
  16.261 +        }
  16.262 +        // Mapping for processor options created in
  16.263 +        // JavacProcessingEnvironment
  16.264 +        @Override
  16.265 +        public boolean process(OptionHelper helper, String option) {
  16.266 +            int argLength = option.length();
  16.267 +            if (argLength == 2) {
  16.268 +                helper.error("err.empty.A.argument");
  16.269 +                return true;
  16.270 +            }
  16.271 +            int sepIndex = option.indexOf('=');
  16.272 +            String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
  16.273 +            if (!JavacProcessingEnvironment.isValidOptionName(key)) {
  16.274 +                helper.error("err.invalid.A.key", option);
  16.275 +                return true;
  16.276 +            }
  16.277 +            return process(helper, option, option);
  16.278 +        }
  16.279 +    },
  16.280 +
  16.281 +    X("-X", "opt.X", STANDARD, INFO) {
  16.282 +        @Override
  16.283 +        public boolean process(OptionHelper helper, String option) {
  16.284 +            Log log = helper.getLog();
  16.285 +            for (Option o: getJavaCompilerOptions()) {
  16.286 +                o.help(log, OptionKind.EXTENDED);
  16.287 +            }
  16.288 +            log.printNewline();
  16.289 +            log.printLines(PrefixKind.JAVAC, "msg.usage.nonstandard.footer");
  16.290 +            return super.process(helper, option);
  16.291 +        }
  16.292 +    },
  16.293 +
  16.294 +    // This option exists only for the purpose of documenting itself.
  16.295 +    // It's actually implemented by the launcher.
  16.296 +    J("-J", "opt.arg.flag", "opt.J", STANDARD, INFO) {
  16.297 +        { hasSuffix = true; }
  16.298 +
  16.299 +        @Override
  16.300 +        public boolean process(OptionHelper helper, String option) {
  16.301 +            throw new AssertionError
  16.302 +                ("the -J flag should be caught by the launcher.");
  16.303 +        }
  16.304 +    },
  16.305 +
  16.306 +    // stop after parsing and attributing.
  16.307 +    // new HiddenOption("-attrparseonly"),
  16.308 +
  16.309 +    // new Option("-moreinfo",                                      "opt.moreinfo") {
  16.310 +    MOREINFO("-moreinfo", null, HIDDEN, BASIC) {
  16.311 +        @Override
  16.312 +        public boolean process(OptionHelper helper, String option) {
  16.313 +            Type.moreInfo = true;
  16.314 +            return super.process(helper, option);
  16.315 +        }
  16.316 +    },
  16.317 +
  16.318 +    // treat warnings as errors
  16.319 +    WERROR("-Werror", "opt.Werror", STANDARD, BASIC),
  16.320 +
  16.321 +//    // use complex inference from context in the position of a method call argument
  16.322 +//    COMPLEXINFERENCE("-complexinference", null, HIDDEN, BASIC),
  16.323 +
  16.324 +    // generare source stubs
  16.325 +    // new HiddenOption("-stubs"),
  16.326 +
  16.327 +    // relax some constraints to allow compiling from stubs
  16.328 +    // new HiddenOption("-relax"),
  16.329 +
  16.330 +    // output source after translating away inner classes
  16.331 +    // new Option("-printflat",                             "opt.printflat"),
  16.332 +    // new HiddenOption("-printflat"),
  16.333 +
  16.334 +    // display scope search details
  16.335 +    // new Option("-printsearch",                           "opt.printsearch"),
  16.336 +    // new HiddenOption("-printsearch"),
  16.337 +
  16.338 +    // prompt after each error
  16.339 +    // new Option("-prompt",                                        "opt.prompt"),
  16.340 +    PROMPT("-prompt", null, HIDDEN, BASIC),
  16.341 +
  16.342 +    // dump stack on error
  16.343 +    DOE("-doe", null, HIDDEN, BASIC),
  16.344 +
  16.345 +    // output source after type erasure
  16.346 +    // new Option("-s",                                     "opt.s"),
  16.347 +    PRINTSOURCE("-printsource", null, HIDDEN, BASIC),
  16.348 +
  16.349 +    // output shrouded class files
  16.350 +    // new Option("-scramble",                              "opt.scramble"),
  16.351 +    // new Option("-scrambleall",                           "opt.scrambleall"),
  16.352 +
  16.353 +    // display warnings for generic unchecked operations
  16.354 +    WARNUNCHECKED("-warnunchecked", null, HIDDEN, BASIC) {
  16.355 +        @Override
  16.356 +        public boolean process(OptionHelper helper, String option) {
  16.357 +            helper.put("-Xlint:unchecked", option);
  16.358 +            return false;
  16.359 +        }
  16.360 +    },
  16.361 +
  16.362 +    XMAXERRS("-Xmaxerrs", "opt.arg.number", "opt.maxerrs", EXTENDED, BASIC),
  16.363 +
  16.364 +    XMAXWARNS("-Xmaxwarns", "opt.arg.number", "opt.maxwarns", EXTENDED, BASIC),
  16.365 +
  16.366 +    XSTDOUT("-Xstdout", "opt.arg.file", "opt.Xstdout", EXTENDED, INFO) {
  16.367 +        @Override
  16.368 +        public boolean process(OptionHelper helper, String option, String arg) {
  16.369 +            try {
  16.370 +                Log log = helper.getLog();
  16.371 +                // TODO: this file should be closed at the end of compilation
  16.372 +                log.setWriters(new PrintWriter(new FileWriter(arg), true));
  16.373 +            } catch (java.io.IOException e) {
  16.374 +                helper.error("err.error.writing.file", arg, e);
  16.375 +                return true;
  16.376 +            }
  16.377 +            return super.process(helper, option, arg);
  16.378 +        }
  16.379 +    },
  16.380 +
  16.381 +    XPRINT("-Xprint", "opt.print", EXTENDED, BASIC),
  16.382 +
  16.383 +    XPRINTROUNDS("-XprintRounds", "opt.printRounds", EXTENDED, BASIC),
  16.384 +
  16.385 +    XPRINTPROCESSORINFO("-XprintProcessorInfo", "opt.printProcessorInfo", EXTENDED, BASIC),
  16.386 +
  16.387 +    XPREFER("-Xprefer:", "opt.prefer", EXTENDED, BASIC, ONEOF, "source", "newer"),
  16.388 +
  16.389 +    XPKGINFO("-Xpkginfo:", "opt.pkginfo", EXTENDED, BASIC, ONEOF, "always", "legacy", "nonempty"),
  16.390 +
  16.391 +    /* -O is a no-op, accepted for backward compatibility. */
  16.392 +    O("-O", null, HIDDEN, BASIC),
  16.393 +
  16.394 +    /* -Xjcov produces tables to support the code coverage tool jcov. */
  16.395 +    XJCOV("-Xjcov", null, HIDDEN, BASIC),
  16.396 +
  16.397 +    /* This is a back door to the compiler's option table.
  16.398 +     * -XDx=y sets the option x to the value y.
  16.399 +     * -XDx sets the option x to the value x.
  16.400 +     */
  16.401 +    XD("-XD", null, HIDDEN, BASIC) {
  16.402 +        String s;
  16.403 +        @Override
  16.404 +        public boolean matches(String s) {
  16.405 +            this.s = s;
  16.406 +            return s.startsWith(text);
  16.407 +        }
  16.408 +        @Override
  16.409 +        public boolean process(OptionHelper helper, String option) {
  16.410 +            s = s.substring(text.length());
  16.411 +            int eq = s.indexOf('=');
  16.412 +            String key = (eq < 0) ? s : s.substring(0, eq);
  16.413 +            String value = (eq < 0) ? s : s.substring(eq+1);
  16.414 +            helper.put(key, value);
  16.415 +            return false;
  16.416 +        }
  16.417 +    },
  16.418 +
  16.419 +    // This option exists only for the purpose of documenting itself.
  16.420 +    // It's actually implemented by the CommandLine class.
  16.421 +    AT("@", "opt.arg.file", "opt.AT", STANDARD, INFO) {
  16.422 +        { hasSuffix = true; }
  16.423 +
  16.424 +        @Override
  16.425 +        public boolean process(OptionHelper helper, String option) {
  16.426 +            throw new AssertionError("the @ flag should be caught by CommandLine.");
  16.427 +        }
  16.428 +    },
  16.429 +
  16.430 +    /*
  16.431 +     * TODO: With apt, the matches method accepts anything if
  16.432 +     * -XclassAsDecls is used; code elsewhere does the lookup to
  16.433 +     * see if the class name is both legal and found.
  16.434 +     *
  16.435 +     * In apt, the process method adds the candidate class file
  16.436 +     * name to a separate list.
  16.437 +     */
  16.438 +    SOURCEFILE("sourcefile", null, HIDDEN, INFO) {
  16.439 +        String s;
  16.440 +        @Override
  16.441 +        public boolean matches(String s) {
  16.442 +            this.s = s;
  16.443 +            return s.endsWith(".java")  // Java source file
  16.444 +                || SourceVersion.isName(s);   // Legal type name
  16.445 +        }
  16.446 +        @Override
  16.447 +        public boolean process(OptionHelper helper, String option) {
  16.448 +            if (s.endsWith(".java") ) {
  16.449 +                File f = new File(s);
  16.450 +                if (!f.exists()) {
  16.451 +                    helper.error("err.file.not.found", f);
  16.452 +                    return true;
  16.453 +                }
  16.454 +                if (!f.isFile()) {
  16.455 +                    helper.error("err.file.not.file", f);
  16.456 +                    return true;
  16.457 +                }
  16.458 +                helper.addFile(f);
  16.459 +            }
  16.460 +            else
  16.461 +                helper.addClassName(s);
  16.462 +            return false;
  16.463 +        }
  16.464 +    };
  16.465 +
  16.466 +    /** The kind of an Option. This is used by the -help and -X options. */
  16.467 +    public enum OptionKind {
  16.468 +        /** A standard option, documented by -help. */
  16.469 +        STANDARD,
  16.470 +        /** An extended option, documented by -X. */
  16.471 +        EXTENDED,
  16.472 +        /** A hidden option, not documented. */
  16.473 +        HIDDEN,
  16.474 +    }
  16.475 +
  16.476 +    /** The group for an Option. This determines the situations in which the
  16.477 +     *  option is applicable. */
  16.478 +    enum OptionGroup {
  16.479 +        /** A basic option, available for use on the command line or via the
  16.480 +         *  Compiler API. */
  16.481 +        BASIC,
  16.482 +        /** An option for javac's standard JavaFileManager. Other file managers
  16.483 +         *  may or may not support these options. */
  16.484 +        FILEMANAGER,
  16.485 +        /** A command-line option that requests information, such as -help. */
  16.486 +        INFO,
  16.487 +        /** A command-line "option" representing a file or class name. */
  16.488 +        OPERAND
  16.489 +    }
  16.490 +
  16.491 +    /** The kind of choice for "choice" options. */
  16.492 +    enum ChoiceKind {
  16.493 +        /** The expected value is exactly one of the set of choices. */
  16.494 +        ONEOF,
  16.495 +        /** The expected value is one of more of the set of choices. */
  16.496 +        ANYOF
  16.497 +    }
  16.498 +
  16.499 +    public final String text;
  16.500 +
  16.501 +    final OptionKind kind;
  16.502 +
  16.503 +    final OptionGroup group;
  16.504 +
  16.505 +    /** Documentation key for arguments.
  16.506 +     */
  16.507 +    final String argsNameKey;
  16.508 +
  16.509 +    /** Documentation key for description.
  16.510 +     */
  16.511 +    final String descrKey;
  16.512 +
  16.513 +    /** Suffix option (-foo=bar or -foo:bar)
  16.514 +     */
  16.515 +    boolean hasSuffix;
  16.516 +
  16.517 +    /** The kind of choices for this option, if any.
  16.518 +     */
  16.519 +    final ChoiceKind choiceKind;
  16.520 +
  16.521 +    /** The choices for this option, if any, and whether or not the choices
  16.522 +     *  are hidden
  16.523 +     */
  16.524 +    final Map<String,Boolean> choices;
  16.525 +
  16.526 +
  16.527 +    Option(String text, String descrKey,
  16.528 +            OptionKind kind, OptionGroup group) {
  16.529 +        this(text, null, descrKey, kind, group, null, null);
  16.530 +    }
  16.531 +
  16.532 +    Option(String text, String argsNameKey, String descrKey,
  16.533 +            OptionKind kind, OptionGroup group) {
  16.534 +        this(text, argsNameKey, descrKey, kind, group, null, null);
  16.535 +    }
  16.536 +
  16.537 +    Option(String text, String descrKey,
  16.538 +            OptionKind kind, OptionGroup group,
  16.539 +            ChoiceKind choiceKind, Map<String,Boolean> choices) {
  16.540 +        this(text, null, descrKey, kind, group, choiceKind, choices);
  16.541 +    }
  16.542 +
  16.543 +    Option(String text, String descrKey,
  16.544 +            OptionKind kind, OptionGroup group,
  16.545 +            ChoiceKind choiceKind, String... choices) {
  16.546 +        this(text, null, descrKey, kind, group, choiceKind, createChoices(choices));
  16.547 +    }
  16.548 +    // where
  16.549 +        private static Map<String,Boolean> createChoices(String... choices) {
  16.550 +            Map<String,Boolean> map = new LinkedHashMap<String,Boolean>();
  16.551 +            for (String c: choices)
  16.552 +                map.put(c, false);
  16.553 +            return map;
  16.554 +        }
  16.555 +
  16.556 +    private Option(String text, String argsNameKey, String descrKey,
  16.557 +            OptionKind kind, OptionGroup group,
  16.558 +            ChoiceKind choiceKind, Map<String,Boolean> choices) {
  16.559 +        this.text = text;
  16.560 +        this.argsNameKey = argsNameKey;
  16.561 +        this.descrKey = descrKey;
  16.562 +        this.kind = kind;
  16.563 +        this.group = group;
  16.564 +        this.choiceKind = choiceKind;
  16.565 +        this.choices = choices;
  16.566 +        char lastChar = text.charAt(text.length()-1);
  16.567 +        hasSuffix = lastChar == ':' || lastChar == '=';
  16.568 +    }
  16.569 +
  16.570 +    public String getText() {
  16.571 +        return text;
  16.572 +    }
  16.573 +
  16.574 +    public OptionKind getKind() {
  16.575 +        return kind;
  16.576 +    }
  16.577 +
  16.578 +    public boolean hasArg() {
  16.579 +        return argsNameKey != null && !hasSuffix;
  16.580 +    }
  16.581 +
  16.582 +    public boolean matches(String option) {
  16.583 +        if (!hasSuffix)
  16.584 +            return option.equals(text);
  16.585 +
  16.586 +        if (!option.startsWith(text))
  16.587 +            return false;
  16.588 +
  16.589 +        if (choices != null) {
  16.590 +            String arg = option.substring(text.length());
  16.591 +            if (choiceKind == ChoiceKind.ONEOF)
  16.592 +                return choices.keySet().contains(arg);
  16.593 +            else {
  16.594 +                for (String a: arg.split(",+")) {
  16.595 +                    if (!choices.keySet().contains(a))
  16.596 +                        return false;
  16.597 +                }
  16.598 +            }
  16.599 +        }
  16.600 +
  16.601 +        return true;
  16.602 +    }
  16.603 +
  16.604 +    public boolean process(OptionHelper helper, String option, String arg) {
  16.605 +        if (choices != null) {
  16.606 +            if (choiceKind == ChoiceKind.ONEOF) {
  16.607 +                // some clients like to see just one of option+choice set
  16.608 +                for (String s: choices.keySet())
  16.609 +                    helper.remove(option + s);
  16.610 +                String opt = option + arg;
  16.611 +                helper.put(opt, opt);
  16.612 +                // some clients like to see option (without trailing ":")
  16.613 +                // set to arg
  16.614 +                String nm = option.substring(0, option.length() - 1);
  16.615 +                helper.put(nm, arg);
  16.616 +            } else {
  16.617 +                // set option+word for each word in arg
  16.618 +                for (String a: arg.split(",+")) {
  16.619 +                    String opt = option + a;
  16.620 +                    helper.put(opt, opt);
  16.621 +                }
  16.622 +            }
  16.623 +        }
  16.624 +        helper.put(option, arg);
  16.625 +        return false;
  16.626 +    }
  16.627 +
  16.628 +    public boolean process(OptionHelper helper, String option) {
  16.629 +        if (hasSuffix)
  16.630 +            return process(helper, text, option.substring(text.length()));
  16.631 +        else
  16.632 +            return process(helper, option, option);
  16.633 +    }
  16.634 +
  16.635 +    void help(Log log, OptionKind kind) {
  16.636 +        if (this.kind != kind)
  16.637 +            return;
  16.638 +
  16.639 +        log.printRawLines(WriterKind.NOTICE,
  16.640 +                String.format("  %-26s %s",
  16.641 +                    helpSynopsis(log),
  16.642 +                    log.localize(PrefixKind.JAVAC, descrKey)));
  16.643 +
  16.644 +    }
  16.645 +
  16.646 +    private String helpSynopsis(Log log) {
  16.647 +        StringBuilder sb = new StringBuilder();
  16.648 +        sb.append(text);
  16.649 +        if (argsNameKey == null) {
  16.650 +            if (choices != null) {
  16.651 +                String sep = "{";
  16.652 +                for (Map.Entry<String,Boolean> e: choices.entrySet()) {
  16.653 +                    if (!e.getValue()) {
  16.654 +                        sb.append(sep);
  16.655 +                        sb.append(e.getKey());
  16.656 +                        sep = ",";
  16.657 +                    }
  16.658 +                }
  16.659 +                sb.append("}");
  16.660 +            }
  16.661 +        } else {
  16.662 +            if (!hasSuffix)
  16.663 +                sb.append(" ");
  16.664 +            sb.append(log.localize(PrefixKind.JAVAC, argsNameKey));
  16.665 +
  16.666 +        }
  16.667 +
  16.668 +        return sb.toString();
  16.669 +    }
  16.670 +
  16.671 +    // For -XpkgInfo:value
  16.672 +    public enum PkgInfo {
  16.673 +        ALWAYS, LEGACY, NONEMPTY;
  16.674 +        public static PkgInfo get(Options options) {
  16.675 +            String v = options.get(XPKGINFO);
  16.676 +            return (v == null
  16.677 +                    ? PkgInfo.LEGACY
  16.678 +                    : PkgInfo.valueOf(v.toUpperCase()));
  16.679 +        }
  16.680 +    }
  16.681 +
  16.682 +    private static Map<String,Boolean> getXLintChoices() {
  16.683 +        Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>();
  16.684 +        choices.put("all", false);
  16.685 +        for (Lint.LintCategory c : Lint.LintCategory.values())
  16.686 +            choices.put(c.option, c.hidden);
  16.687 +        for (Lint.LintCategory c : Lint.LintCategory.values())
  16.688 +            choices.put("-" + c.option, c.hidden);
  16.689 +        choices.put("none", false);
  16.690 +        return choices;
  16.691 +    }
  16.692 +
  16.693 +    static Set<Option> getJavaCompilerOptions() {
  16.694 +        return EnumSet.allOf(Option.class);
  16.695 +    }
  16.696 +
  16.697 +    public static Set<Option> getJavacFileManagerOptions() {
  16.698 +        return getOptions(EnumSet.of(FILEMANAGER));
  16.699 +    }
  16.700 +
  16.701 +    public static Set<Option> getJavacToolOptions() {
  16.702 +        return getOptions(EnumSet.of(BASIC));
  16.703 +    }
  16.704 +
  16.705 +    static Set<Option> getOptions(Set<OptionGroup> desired) {
  16.706 +        Set<Option> options = EnumSet.noneOf(Option.class);
  16.707 +        for (Option option : Option.values())
  16.708 +            if (desired.contains(option.group))
  16.709 +                options.add(option);
  16.710 +        return Collections.unmodifiableSet(options);
  16.711 +    }
  16.712 +
  16.713 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/share/classes/com/sun/tools/javac/main/OptionHelper.java	Fri Dec 23 16:39:22 2011 -0800
    17.3 @@ -0,0 +1,117 @@
    17.4 +/*
    17.5 + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
    17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.7 + *
    17.8 + * This code is free software; you can redistribute it and/or modify it
    17.9 + * under the terms of the GNU General Public License version 2 only, as
   17.10 + * published by the Free Software Foundation.  Oracle designates this
   17.11 + * particular file as subject to the "Classpath" exception as provided
   17.12 + * by Oracle in the LICENSE file that accompanied this code.
   17.13 + *
   17.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   17.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.17 + * version 2 for more details (a copy is included in the LICENSE file that
   17.18 + * accompanied this code).
   17.19 + *
   17.20 + * You should have received a copy of the GNU General Public License version
   17.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   17.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.23 + *
   17.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   17.25 + * or visit www.oracle.com if you need additional information or have any
   17.26 + * questions.
   17.27 + */
   17.28 +
   17.29 +package com.sun.tools.javac.main;
   17.30 +
   17.31 +import com.sun.tools.javac.util.Log;
   17.32 +import com.sun.tools.javac.util.Log.PrefixKind;
   17.33 +import java.io.File;
   17.34 +
   17.35 +/**
   17.36 + * Helper object to be used by {@link Option#process}, providing access to
   17.37 + * the compilation environment.
   17.38 + *
   17.39 + * <p><b>This is NOT part of any supported API.
   17.40 + * If you write code that depends on this, you do so at your own
   17.41 + * risk.  This code and its internal interfaces are subject to change
   17.42 + * or deletion without notice.</b></p>
   17.43 + */
   17.44 +
   17.45 +public abstract class OptionHelper {
   17.46 +
   17.47 +    /** Get the current value of an option. */
   17.48 +    public abstract String get(Option option);
   17.49 +
   17.50 +    /** Set the value of an option. */
   17.51 +    public abstract void put(String name, String value);
   17.52 +
   17.53 +    /** Remove any prior value for an option. */
   17.54 +    public abstract void remove(String name);
   17.55 +
   17.56 +    /** Get access to the Log for the compilation. */
   17.57 +    public abstract Log getLog();
   17.58 +
   17.59 +    /** Get the name of the tool, such as "javac", to be used in info like -help. */
   17.60 +    public abstract String getOwnName();
   17.61 +
   17.62 +    /** Report an error. */
   17.63 +    abstract void error(String key, Object... args);
   17.64 +
   17.65 +    /** Record a file to be compiled. */
   17.66 +    abstract void addFile(File f);
   17.67 +
   17.68 +    /** Record the name of a class for annotation processing. */
   17.69 +    abstract void addClassName(String s);
   17.70 +
   17.71 +    /** An implementation of OptionHelper that mostly throws exceptions. */
   17.72 +    public static class GrumpyHelper extends OptionHelper {
   17.73 +        private final Log log;
   17.74 +
   17.75 +        public GrumpyHelper(Log log) {
   17.76 +            this.log = log;
   17.77 +        }
   17.78 +
   17.79 +        @Override
   17.80 +        public Log getLog() {
   17.81 +            return log;
   17.82 +        }
   17.83 +
   17.84 +        @Override
   17.85 +        public String getOwnName() {
   17.86 +            throw new IllegalStateException();
   17.87 +        }
   17.88 +
   17.89 +        @Override
   17.90 +        public String get(Option option) {
   17.91 +            throw new IllegalArgumentException();
   17.92 +        }
   17.93 +
   17.94 +        @Override
   17.95 +        public void put(String name, String value) {
   17.96 +            throw new IllegalArgumentException();
   17.97 +        }
   17.98 +
   17.99 +        @Override
  17.100 +        public void remove(String name) {
  17.101 +            throw new IllegalArgumentException();
  17.102 +        }
  17.103 +
  17.104 +        @Override
  17.105 +        void error(String key, Object... args) {
  17.106 +            throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
  17.107 +        }
  17.108 +
  17.109 +        @Override
  17.110 +        public void addFile(File f) {
  17.111 +            throw new IllegalArgumentException(f.getPath());
  17.112 +        }
  17.113 +
  17.114 +        @Override
  17.115 +        public void addClassName(String s) {
  17.116 +            throw new IllegalArgumentException(s);
  17.117 +        }
  17.118 +    }
  17.119 +
  17.120 +}
    18.1 --- a/src/share/classes/com/sun/tools/javac/main/OptionName.java	Thu Dec 22 19:00:58 2011 -0800
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,105 +0,0 @@
    18.4 -/*
    18.5 - * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
    18.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.7 - *
    18.8 - * This code is free software; you can redistribute it and/or modify it
    18.9 - * under the terms of the GNU General Public License version 2 only, as
   18.10 - * published by the Free Software Foundation.  Oracle designates this
   18.11 - * particular file as subject to the "Classpath" exception as provided
   18.12 - * by Oracle in the LICENSE file that accompanied this code.
   18.13 - *
   18.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   18.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   18.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   18.17 - * version 2 for more details (a copy is included in the LICENSE file that
   18.18 - * accompanied this code).
   18.19 - *
   18.20 - * You should have received a copy of the GNU General Public License version
   18.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   18.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18.23 - *
   18.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   18.25 - * or visit www.oracle.com if you need additional information or have any
   18.26 - * questions.
   18.27 - */
   18.28 -
   18.29 -package com.sun.tools.javac.main;
   18.30 -
   18.31 -
   18.32 -/**
   18.33 - * TODO: describe com.sun.tools.javac.main.OptionName
   18.34 - *
   18.35 - * <p><b>This is NOT part of any supported API.
   18.36 - * If you write code that depends on this, you do so at your own
   18.37 - * risk.  This code and its internal interfaces are subject to change
   18.38 - * or deletion without notice.</b></p>
   18.39 - */
   18.40 -public enum OptionName {
   18.41 -    G("-g"),
   18.42 -    G_NONE("-g:none"),
   18.43 -    G_CUSTOM("-g:"),
   18.44 -    XLINT("-Xlint"),
   18.45 -    XLINT_CUSTOM("-Xlint:"),
   18.46 -    DIAGS("-XDdiags="),
   18.47 -    NOWARN("-nowarn"),
   18.48 -    VERBOSE("-verbose"),
   18.49 -    DEPRECATION("-deprecation"),
   18.50 -    CLASSPATH("-classpath"),
   18.51 -    CP("-cp"),
   18.52 -    SOURCEPATH("-sourcepath"),
   18.53 -    BOOTCLASSPATH("-bootclasspath"),
   18.54 -    XBOOTCLASSPATH_PREPEND("-Xbootclasspath/p:"),
   18.55 -    XBOOTCLASSPATH_APPEND("-Xbootclasspath/a:"),
   18.56 -    XBOOTCLASSPATH("-Xbootclasspath:"),
   18.57 -    EXTDIRS("-extdirs"),
   18.58 -    DJAVA_EXT_DIRS("-Djava.ext.dirs="),
   18.59 -    ENDORSEDDIRS("-endorseddirs"),
   18.60 -    DJAVA_ENDORSED_DIRS("-Djava.endorsed.dirs="),
   18.61 -    PROC("-proc:"),
   18.62 -    PROCESSOR("-processor"),
   18.63 -    PROCESSORPATH("-processorpath"),
   18.64 -    D("-d"),
   18.65 -    S("-s"),
   18.66 -    IMPLICIT("-implicit:"),
   18.67 -    ENCODING("-encoding"),
   18.68 -    SOURCE("-source"),
   18.69 -    TARGET("-target"),
   18.70 -    VERSION("-version"),
   18.71 -    FULLVERSION("-fullversion"),
   18.72 -    HELP("-help"),
   18.73 -    A("-A"),
   18.74 -    X("-X"),
   18.75 -    J("-J"),
   18.76 -    MOREINFO("-moreinfo"),
   18.77 -    WERROR("-Werror"),
   18.78 -    COMPLEXINFERENCE("-complexinference"),
   18.79 -    PROMPT("-prompt"),
   18.80 -    DOE("-doe"),
   18.81 -    PRINTSOURCE("-printsource"),
   18.82 -    WARNUNCHECKED("-warnunchecked"),
   18.83 -    XMAXERRS("-Xmaxerrs"),
   18.84 -    XMAXWARNS("-Xmaxwarns"),
   18.85 -    XSTDOUT("-Xstdout"),
   18.86 -    XPKGINFO("-Xpkginfo:"),
   18.87 -    XPRINT("-Xprint"),
   18.88 -    XPRINTROUNDS("-XprintRounds"),
   18.89 -    XPRINTPROCESSORINFO("-XprintProcessorInfo"),
   18.90 -    XPREFER("-Xprefer:"),
   18.91 -    O("-O"),
   18.92 -    XJCOV("-Xjcov"),
   18.93 -    XD("-XD"),
   18.94 -    AT("@"),
   18.95 -    SOURCEFILE("sourcefile");
   18.96 -
   18.97 -    public final String optionName;
   18.98 -
   18.99 -    OptionName(String optionName) {
  18.100 -        this.optionName = optionName;
  18.101 -    }
  18.102 -
  18.103 -    @Override
  18.104 -    public String toString() {
  18.105 -        return optionName;
  18.106 -    }
  18.107 -
  18.108 -}
    19.1 --- a/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java	Thu Dec 22 19:00:58 2011 -0800
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,651 +0,0 @@
    19.4 -/*
    19.5 - * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
    19.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    19.7 - *
    19.8 - * This code is free software; you can redistribute it and/or modify it
    19.9 - * under the terms of the GNU General Public License version 2 only, as
   19.10 - * published by the Free Software Foundation.  Oracle designates this
   19.11 - * particular file as subject to the "Classpath" exception as provided
   19.12 - * by Oracle in the LICENSE file that accompanied this code.
   19.13 - *
   19.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   19.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   19.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   19.17 - * version 2 for more details (a copy is included in the LICENSE file that
   19.18 - * accompanied this code).
   19.19 - *
   19.20 - * You should have received a copy of the GNU General Public License version
   19.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   19.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   19.23 - *
   19.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   19.25 - * or visit www.oracle.com if you need additional information or have any
   19.26 - * questions.
   19.27 - */
   19.28 -
   19.29 -package com.sun.tools.javac.main;
   19.30 -
   19.31 -import java.io.File;
   19.32 -import java.io.FileWriter;
   19.33 -import java.io.PrintWriter;
   19.34 -import java.util.EnumSet;
   19.35 -import java.util.LinkedHashMap;
   19.36 -import java.util.Map;
   19.37 -import java.util.Set;
   19.38 -import javax.lang.model.SourceVersion;
   19.39 -
   19.40 -import com.sun.tools.javac.code.Lint;
   19.41 -import com.sun.tools.javac.code.Source;
   19.42 -import com.sun.tools.javac.code.Type;
   19.43 -import com.sun.tools.javac.jvm.Target;
   19.44 -import com.sun.tools.javac.main.JavacOption.HiddenOption;
   19.45 -import com.sun.tools.javac.main.JavacOption.Option;
   19.46 -import com.sun.tools.javac.main.JavacOption.XOption;
   19.47 -import com.sun.tools.javac.processing.JavacProcessingEnvironment;
   19.48 -import com.sun.tools.javac.util.ListBuffer;
   19.49 -import com.sun.tools.javac.util.Log;
   19.50 -import com.sun.tools.javac.util.Log.PrefixKind;
   19.51 -import com.sun.tools.javac.util.Options;
   19.52 -
   19.53 -import static com.sun.tools.javac.main.OptionName.*;
   19.54 -
   19.55 -/**
   19.56 - * TODO: describe com.sun.tools.javac.main.RecognizedOptions
   19.57 - *
   19.58 - * <p><b>This is NOT part of any supported API.
   19.59 - * If you write code that depends on this, you do so at your own
   19.60 - * risk.  This code and its internal interfaces are subject to change
   19.61 - * or deletion without notice.</b></p>
   19.62 - */
   19.63 -public class RecognizedOptions {
   19.64 -
   19.65 -    private RecognizedOptions() {}
   19.66 -
   19.67 -    public interface OptionHelper {
   19.68 -
   19.69 -        void setOut(PrintWriter out);
   19.70 -
   19.71 -        void error(String key, Object... args);
   19.72 -
   19.73 -        void printVersion();
   19.74 -
   19.75 -        void printFullVersion();
   19.76 -
   19.77 -        void printHelp();
   19.78 -
   19.79 -        void printXhelp();
   19.80 -
   19.81 -        void addFile(File f);
   19.82 -
   19.83 -        void addClassName(String s);
   19.84 -
   19.85 -    }
   19.86 -
   19.87 -    public static class GrumpyHelper implements OptionHelper {
   19.88 -        private Log log;
   19.89 -
   19.90 -        public GrumpyHelper(Log log) {
   19.91 -            this.log = log;
   19.92 -        }
   19.93 -
   19.94 -        public void setOut(PrintWriter out) {
   19.95 -            throw new IllegalArgumentException();
   19.96 -        }
   19.97 -
   19.98 -        public void error(String key, Object... args) {
   19.99 -            throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
  19.100 -        }
  19.101 -
  19.102 -        public void printVersion() {
  19.103 -            throw new IllegalArgumentException();
  19.104 -        }
  19.105 -
  19.106 -        public void printFullVersion() {
  19.107 -            throw new IllegalArgumentException();
  19.108 -        }
  19.109 -
  19.110 -        public void printHelp() {
  19.111 -            throw new IllegalArgumentException();
  19.112 -        }
  19.113 -
  19.114 -        public void printXhelp() {
  19.115 -            throw new IllegalArgumentException();
  19.116 -        }
  19.117 -
  19.118 -        public void addFile(File f) {
  19.119 -            throw new IllegalArgumentException(f.getPath());
  19.120 -        }
  19.121 -
  19.122 -        public void addClassName(String s) {
  19.123 -            throw new IllegalArgumentException(s);
  19.124 -        }
  19.125 -
  19.126 -    }
  19.127 -
  19.128 -    static Set<OptionName> javacOptions = EnumSet.of(
  19.129 -        G,
  19.130 -        G_NONE,
  19.131 -        G_CUSTOM,
  19.132 -        XLINT,
  19.133 -        XLINT_CUSTOM,
  19.134 -        NOWARN,
  19.135 -        VERBOSE,
  19.136 -        DEPRECATION,
  19.137 -        CLASSPATH,
  19.138 -        CP,
  19.139 -        SOURCEPATH,
  19.140 -        BOOTCLASSPATH,
  19.141 -        XBOOTCLASSPATH_PREPEND,
  19.142 -        XBOOTCLASSPATH_APPEND,
  19.143 -        XBOOTCLASSPATH,
  19.144 -        EXTDIRS,
  19.145 -        DJAVA_EXT_DIRS,
  19.146 -        ENDORSEDDIRS,
  19.147 -        DJAVA_ENDORSED_DIRS,
  19.148 -        PROC,
  19.149 -        PROCESSOR,
  19.150 -        PROCESSORPATH,
  19.151 -        D,
  19.152 -        S,
  19.153 -        IMPLICIT,
  19.154 -        ENCODING,
  19.155 -        SOURCE,
  19.156 -        TARGET,
  19.157 -        VERSION,
  19.158 -        FULLVERSION,
  19.159 -        DIAGS,
  19.160 -        HELP,
  19.161 -        A,
  19.162 -        X,
  19.163 -        J,
  19.164 -        MOREINFO,
  19.165 -        WERROR,
  19.166 -        // COMPLEXINFERENCE,
  19.167 -        PROMPT,
  19.168 -        DOE,
  19.169 -        PRINTSOURCE,
  19.170 -        WARNUNCHECKED,
  19.171 -        XMAXERRS,
  19.172 -        XMAXWARNS,
  19.173 -        XSTDOUT,
  19.174 -        XPKGINFO,
  19.175 -        XPRINT,
  19.176 -        XPRINTROUNDS,
  19.177 -        XPRINTPROCESSORINFO,
  19.178 -        XPREFER,
  19.179 -        O,
  19.180 -        XJCOV,
  19.181 -        XD,
  19.182 -        AT,
  19.183 -        SOURCEFILE);
  19.184 -
  19.185 -    static Set<OptionName> javacFileManagerOptions = EnumSet.of(
  19.186 -        CLASSPATH,
  19.187 -        CP,
  19.188 -        SOURCEPATH,
  19.189 -        BOOTCLASSPATH,
  19.190 -        XBOOTCLASSPATH_PREPEND,
  19.191 -        XBOOTCLASSPATH_APPEND,
  19.192 -        XBOOTCLASSPATH,
  19.193 -        EXTDIRS,
  19.194 -        DJAVA_EXT_DIRS,
  19.195 -        ENDORSEDDIRS,
  19.196 -        DJAVA_ENDORSED_DIRS,
  19.197 -        PROCESSORPATH,
  19.198 -        D,
  19.199 -        S,
  19.200 -        ENCODING,
  19.201 -        SOURCE);
  19.202 -
  19.203 -    static Set<OptionName> javacToolOptions = EnumSet.of(
  19.204 -        G,
  19.205 -        G_NONE,
  19.206 -        G_CUSTOM,
  19.207 -        XLINT,
  19.208 -        XLINT_CUSTOM,
  19.209 -        NOWARN,
  19.210 -        VERBOSE,
  19.211 -        DEPRECATION,
  19.212 -        PROC,
  19.213 -        PROCESSOR,
  19.214 -        IMPLICIT,
  19.215 -        SOURCE,
  19.216 -        TARGET,
  19.217 -        // VERSION,
  19.218 -        // FULLVERSION,
  19.219 -        // HELP,
  19.220 -        A,
  19.221 -        // X,
  19.222 -        // J,
  19.223 -        MOREINFO,
  19.224 -        WERROR,
  19.225 -        // COMPLEXINFERENCE,
  19.226 -        PROMPT,
  19.227 -        DOE,
  19.228 -        PRINTSOURCE,
  19.229 -        WARNUNCHECKED,
  19.230 -        XMAXERRS,
  19.231 -        XMAXWARNS,
  19.232 -        // XSTDOUT,
  19.233 -        XPKGINFO,
  19.234 -        XPRINT,
  19.235 -        XPRINTROUNDS,
  19.236 -        XPRINTPROCESSORINFO,
  19.237 -        XPREFER,
  19.238 -        O,
  19.239 -        XJCOV,
  19.240 -        XD);
  19.241 -
  19.242 -    static Option[] getJavaCompilerOptions(OptionHelper helper) {
  19.243 -        return getOptions(helper, javacOptions);
  19.244 -    }
  19.245 -
  19.246 -    public static Option[] getJavacFileManagerOptions(OptionHelper helper) {
  19.247 -        return getOptions(helper, javacFileManagerOptions);
  19.248 -    }
  19.249 -
  19.250 -    public static Option[] getJavacToolOptions(OptionHelper helper) {
  19.251 -        return getOptions(helper, javacToolOptions);
  19.252 -    }
  19.253 -
  19.254 -    static Option[] getOptions(OptionHelper helper, Set<OptionName> desired) {
  19.255 -        ListBuffer<Option> options = new ListBuffer<Option>();
  19.256 -        for (Option option : getAll(helper))
  19.257 -            if (desired.contains(option.getName()))
  19.258 -                options.append(option);
  19.259 -        return options.toArray(new Option[options.length()]);
  19.260 -    }
  19.261 -
  19.262 -    /**
  19.263 -     * Get all the recognized options.
  19.264 -     * @param helper an {@code OptionHelper} to help when processing options
  19.265 -     * @return an array of options
  19.266 -     */
  19.267 -    public static Option[] getAll(final OptionHelper helper) {
  19.268 -        return new Option[] {
  19.269 -        new Option(G,                                           "opt.g"),
  19.270 -        new Option(G_NONE,                                      "opt.g.none") {
  19.271 -            @Override
  19.272 -            public boolean process(Options options, String option) {
  19.273 -                options.put("-g:", "none");
  19.274 -                return false;
  19.275 -            }
  19.276 -        },
  19.277 -
  19.278 -        new Option(G_CUSTOM,                                    "opt.g.lines.vars.source",
  19.279 -                Option.ChoiceKind.ANYOF, "lines", "vars", "source"),
  19.280 -
  19.281 -        new XOption(XLINT,                                      "opt.Xlint"),
  19.282 -        new XOption(XLINT_CUSTOM,                               "opt.Xlint.suboptlist",
  19.283 -                Option.ChoiceKind.ANYOF, getXLintChoices()),
  19.284 -
  19.285 -        // -nowarn is retained for command-line backward compatibility
  19.286 -        new Option(NOWARN,                                      "opt.nowarn") {
  19.287 -            @Override
  19.288 -            public boolean process(Options options, String option) {
  19.289 -                options.put("-Xlint:none", option);
  19.290 -                return false;
  19.291 -            }
  19.292 -        },
  19.293 -
  19.294 -        new Option(VERBOSE,                                     "opt.verbose"),
  19.295 -
  19.296 -        // -deprecation is retained for command-line backward compatibility
  19.297 -        new Option(DEPRECATION,                                 "opt.deprecation") {
  19.298 -            @Override
  19.299 -            public boolean process(Options options, String option) {
  19.300 -                options.put("-Xlint:deprecation", option);
  19.301 -                return false;
  19.302 -            }
  19.303 -        },
  19.304 -
  19.305 -        new Option(CLASSPATH,              "opt.arg.path",      "opt.classpath"),
  19.306 -        new Option(CP,                     "opt.arg.path",      "opt.classpath") {
  19.307 -            @Override
  19.308 -            public boolean process(Options options, String option, String arg) {
  19.309 -                return super.process(options, "-classpath", arg);
  19.310 -            }
  19.311 -        },
  19.312 -        new Option(SOURCEPATH,             "opt.arg.path",      "opt.sourcepath"),
  19.313 -        new Option(BOOTCLASSPATH,          "opt.arg.path",      "opt.bootclasspath") {
  19.314 -            @Override
  19.315 -            public boolean process(Options options, String option, String arg) {
  19.316 -                options.remove("-Xbootclasspath/p:");
  19.317 -                options.remove("-Xbootclasspath/a:");
  19.318 -                return super.process(options, option, arg);
  19.319 -            }
  19.320 -        },
  19.321 -        new XOption(XBOOTCLASSPATH_PREPEND,"opt.arg.path", "opt.Xbootclasspath.p"),
  19.322 -        new XOption(XBOOTCLASSPATH_APPEND, "opt.arg.path", "opt.Xbootclasspath.a"),
  19.323 -        new XOption(XBOOTCLASSPATH,        "opt.arg.path", "opt.bootclasspath") {
  19.324 -            @Override
  19.325 -            public boolean process(Options options, String option, String arg) {
  19.326 -                options.remove("-Xbootclasspath/p:");
  19.327 -                options.remove("-Xbootclasspath/a:");
  19.328 -                return super.process(options, "-bootclasspath", arg);
  19.329 -            }
  19.330 -        },
  19.331 -        new Option(EXTDIRS,                "opt.arg.dirs",      "opt.extdirs"),
  19.332 -        new XOption(DJAVA_EXT_DIRS,        "opt.arg.dirs",      "opt.extdirs") {
  19.333 -            @Override
  19.334 -            public boolean process(Options options, String option, String arg) {
  19.335 -                return super.process(options, "-extdirs", arg);
  19.336 -            }
  19.337 -        },
  19.338 -        new Option(ENDORSEDDIRS,            "opt.arg.dirs",     "opt.endorseddirs"),
  19.339 -        new XOption(DJAVA_ENDORSED_DIRS,    "opt.arg.dirs",     "opt.endorseddirs") {
  19.340 -            @Override
  19.341 -            public boolean process(Options options, String option, String arg) {
  19.342 -                return super.process(options, "-endorseddirs", arg);
  19.343 -            }
  19.344 -        },
  19.345 -        new Option(PROC,                                 "opt.proc.none.only",
  19.346 -                Option.ChoiceKind.ONEOF, "none", "only"),
  19.347 -        new Option(PROCESSOR,           "opt.arg.class.list",   "opt.processor"),
  19.348 -        new Option(PROCESSORPATH,       "opt.arg.path",         "opt.processorpath"),
  19.349 -        new Option(D,                   "opt.arg.directory",    "opt.d"),
  19.350 -        new Option(S,                   "opt.arg.directory",    "opt.sourceDest"),
  19.351 -        new Option(IMPLICIT,                                    "opt.implicit",
  19.352 -                Option.ChoiceKind.ONEOF, "none", "class"),
  19.353 -        new Option(ENCODING,            "opt.arg.encoding",     "opt.encoding"),
  19.354 -        new Option(SOURCE,              "opt.arg.release",      "opt.source") {
  19.355 -            @Override
  19.356 -            public boolean process(Options options, String option, String operand) {
  19.357 -                Source source = Source.lookup(operand);
  19.358 -                if (source == null) {
  19.359 -                    helper.error("err.invalid.source", operand);
  19.360 -                    return true;
  19.361 -                }
  19.362 -                return super.process(options, option, operand);
  19.363 -            }
  19.364 -        },
  19.365 -        new Option(TARGET,              "opt.arg.release",      "opt.target") {
  19.366 -            @Override
  19.367 -            public boolean process(Options options, String option, String operand) {
  19.368 -                Target target = Target.lookup(operand);
  19.369 -                if (target == null) {
  19.370 -                    helper.error("err.invalid.target", operand);
  19.371 -                    return true;
  19.372 -                }
  19.373 -                return super.process(options, option, operand);
  19.374 -            }
  19.375 -        },
  19.376 -        new Option(VERSION,                                     "opt.version") {
  19.377 -            @Override
  19.378 -            public boolean process(Options options, String option) {
  19.379 -                helper.printVersion();
  19.380 -                return super.process(options, option);
  19.381 -            }
  19.382 -        },
  19.383 -        new HiddenOption(FULLVERSION) {
  19.384 -            @Override
  19.385 -            public boolean process(Options options, String option) {
  19.386 -                helper.printFullVersion();
  19.387 -                return super.process(options, option);
  19.388 -            }
  19.389 -        },
  19.390 -        new HiddenOption(DIAGS) {
  19.391 -            @Override
  19.392 -            public boolean process(Options options, String option) {
  19.393 -                Option xd = getOptions(helper, EnumSet.of(XD))[0];
  19.394 -                option = option.substring(option.indexOf('=') + 1);
  19.395 -                String diagsOption = option.contains("%") ?
  19.396 -                    "-XDdiagsFormat=" :
  19.397 -                    "-XDdiags=";
  19.398 -                diagsOption += option;
  19.399 -                if (xd.matches(diagsOption))
  19.400 -                    return xd.process(options, diagsOption);
  19.401 -                else
  19.402 -                    return false;
  19.403 -            }
  19.404 -        },
  19.405 -        new Option(HELP,                                        "opt.help") {
  19.406 -            @Override
  19.407 -            public boolean process(Options options, String option) {
  19.408 -                helper.printHelp();
  19.409 -                return super.process(options, option);
  19.410 -            }
  19.411 -        },
  19.412 -        new Option(A,                "opt.arg.key.equals.value","opt.A") {
  19.413 -            @Override
  19.414 -            String helpSynopsis(Log log) {
  19.415 -                hasSuffix = true;
  19.416 -                return super.helpSynopsis(log);
  19.417 -            }
  19.418 -
  19.419 -            @Override
  19.420 -            public boolean matches(String arg) {
  19.421 -                return arg.startsWith("-A");
  19.422 -            }
  19.423 -
  19.424 -            @Override
  19.425 -            public boolean hasArg() {
  19.426 -                return false;
  19.427 -            }
  19.428 -            // Mapping for processor options created in
  19.429 -            // JavacProcessingEnvironment
  19.430 -            @Override
  19.431 -            public boolean process(Options options, String option) {
  19.432 -                int argLength = option.length();
  19.433 -                if (argLength == 2) {
  19.434 -                    helper.error("err.empty.A.argument");
  19.435 -                    return true;
  19.436 -                }
  19.437 -                int sepIndex = option.indexOf('=');
  19.438 -                String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
  19.439 -                if (!JavacProcessingEnvironment.isValidOptionName(key)) {
  19.440 -                    helper.error("err.invalid.A.key", option);
  19.441 -                    return true;
  19.442 -                }
  19.443 -                return process(options, option, option);
  19.444 -            }
  19.445 -        },
  19.446 -        new Option(X,                                           "opt.X") {
  19.447 -            @Override
  19.448 -            public boolean process(Options options, String option) {
  19.449 -                helper.printXhelp();
  19.450 -                return super.process(options, option);
  19.451 -            }
  19.452 -        },
  19.453 -
  19.454 -        // This option exists only for the purpose of documenting itself.
  19.455 -        // It's actually implemented by the launcher.
  19.456 -        new Option(J,                   "opt.arg.flag",         "opt.J") {
  19.457 -            @Override
  19.458 -            String helpSynopsis(Log log) {
  19.459 -                hasSuffix = true;
  19.460 -                return super.helpSynopsis(log);
  19.461 -            }
  19.462 -            @Override
  19.463 -            public boolean process(Options options, String option) {
  19.464 -                throw new AssertionError
  19.465 -                    ("the -J flag should be caught by the launcher.");
  19.466 -            }
  19.467 -        },
  19.468 -
  19.469 -        // stop after parsing and attributing.
  19.470 -        // new HiddenOption("-attrparseonly"),
  19.471 -
  19.472 -        // new Option("-moreinfo",                                      "opt.moreinfo") {
  19.473 -        new HiddenOption(MOREINFO) {
  19.474 -            @Override
  19.475 -            public boolean process(Options options, String option) {
  19.476 -                Type.moreInfo = true;
  19.477 -                return super.process(options, option);
  19.478 -            }
  19.479 -        },
  19.480 -
  19.481 -        // treat warnings as errors
  19.482 -        new Option(WERROR,                                      "opt.Werror"),
  19.483 -
  19.484 -        // use complex inference from context in the position of a method call argument
  19.485 -        new HiddenOption(COMPLEXINFERENCE),
  19.486 -
  19.487 -        // generare source stubs
  19.488 -        // new HiddenOption("-stubs"),
  19.489 -
  19.490 -        // relax some constraints to allow compiling from stubs
  19.491 -        // new HiddenOption("-relax"),
  19.492 -
  19.493 -        // output source after translating away inner classes
  19.494 -        // new Option("-printflat",                             "opt.printflat"),
  19.495 -        // new HiddenOption("-printflat"),
  19.496 -
  19.497 -        // display scope search details
  19.498 -        // new Option("-printsearch",                           "opt.printsearch"),
  19.499 -        // new HiddenOption("-printsearch"),
  19.500 -
  19.501 -        // prompt after each error
  19.502 -        // new Option("-prompt",                                        "opt.prompt"),
  19.503 -        new HiddenOption(PROMPT),
  19.504 -
  19.505 -        // dump stack on error
  19.506 -        new HiddenOption(DOE),
  19.507 -
  19.508 -        // output source after type erasure
  19.509 -        // new Option("-s",                                     "opt.s"),
  19.510 -        new HiddenOption(PRINTSOURCE),
  19.511 -
  19.512 -        // output shrouded class files
  19.513 -        // new Option("-scramble",                              "opt.scramble"),
  19.514 -        // new Option("-scrambleall",                           "opt.scrambleall"),
  19.515 -
  19.516 -        // display warnings for generic unchecked operations
  19.517 -        new HiddenOption(WARNUNCHECKED) {
  19.518 -            @Override
  19.519 -            public boolean process(Options options, String option) {
  19.520 -                options.put("-Xlint:unchecked", option);
  19.521 -                return false;
  19.522 -            }
  19.523 -        },
  19.524 -
  19.525 -        new XOption(XMAXERRS,           "opt.arg.number",       "opt.maxerrs"),
  19.526 -        new XOption(XMAXWARNS,          "opt.arg.number",       "opt.maxwarns"),
  19.527 -        new XOption(XSTDOUT,            "opt.arg.file",         "opt.Xstdout") {
  19.528 -            @Override
  19.529 -            public boolean process(Options options, String option, String arg) {
  19.530 -                try {
  19.531 -                    helper.setOut(new PrintWriter(new FileWriter(arg), true));
  19.532 -                } catch (java.io.IOException e) {
  19.533 -                    helper.error("err.error.writing.file", arg, e);
  19.534 -                    return true;
  19.535 -                }
  19.536 -                return super.process(options, option, arg);
  19.537 -            }
  19.538 -        },
  19.539 -
  19.540 -        new XOption(XPRINT,                                     "opt.print"),
  19.541 -
  19.542 -        new XOption(XPRINTROUNDS,                               "opt.printRounds"),
  19.543 -
  19.544 -        new XOption(XPRINTPROCESSORINFO,                        "opt.printProcessorInfo"),
  19.545 -
  19.546 -        new XOption(XPREFER,                                    "opt.prefer",
  19.547 -                Option.ChoiceKind.ONEOF, "source", "newer"),
  19.548 -
  19.549 -        new XOption(XPKGINFO,                                   "opt.pkginfo",
  19.550 -                Option.ChoiceKind.ONEOF, "always", "legacy", "nonempty"),
  19.551 -
  19.552 -        /* -O is a no-op, accepted for backward compatibility. */
  19.553 -        new HiddenOption(O),
  19.554 -
  19.555 -        /* -Xjcov produces tables to support the code coverage tool jcov. */
  19.556 -        new HiddenOption(XJCOV),
  19.557 -
  19.558 -        /* This is a back door to the compiler's option table.
  19.559 -         * -XDx=y sets the option x to the value y.
  19.560 -         * -XDx sets the option x to the value x.
  19.561 -         */
  19.562 -        new HiddenOption(XD) {
  19.563 -            String s;
  19.564 -            @Override
  19.565 -            public boolean matches(String s) {
  19.566 -                this.s = s;
  19.567 -                return s.startsWith(name.optionName);
  19.568 -            }
  19.569 -            @Override
  19.570 -            public boolean process(Options options, String option) {
  19.571 -                s = s.substring(name.optionName.length());
  19.572 -                int eq = s.indexOf('=');
  19.573 -                String key = (eq < 0) ? s : s.substring(0, eq);
  19.574 -                String value = (eq < 0) ? s : s.substring(eq+1);
  19.575 -                options.put(key, value);
  19.576 -                return false;
  19.577 -            }
  19.578 -        },
  19.579 -
  19.580 -        // This option exists only for the purpose of documenting itself.
  19.581 -        // It's actually implemented by the CommandLine class.
  19.582 -        new Option(AT,                   "opt.arg.file",         "opt.AT") {
  19.583 -            @Override
  19.584 -            String helpSynopsis(Log log) {
  19.585 -                hasSuffix = true;
  19.586 -                return super.helpSynopsis(log);
  19.587 -            }
  19.588 -            @Override
  19.589 -            public boolean process(Options options, String option) {
  19.590 -                throw new AssertionError
  19.591 -                    ("the @ flag should be caught by CommandLine.");
  19.592 -            }
  19.593 -        },
  19.594 -
  19.595 -        /*
  19.596 -         * TODO: With apt, the matches method accepts anything if
  19.597 -         * -XclassAsDecls is used; code elsewhere does the lookup to
  19.598 -         * see if the class name is both legal and found.
  19.599 -         *
  19.600 -         * In apt, the process method adds the candidate class file
  19.601 -         * name to a separate list.
  19.602 -         */
  19.603 -        new HiddenOption(SOURCEFILE) {
  19.604 -            String s;
  19.605 -            @Override
  19.606 -            public boolean matches(String s) {
  19.607 -                this.s = s;
  19.608 -                return s.endsWith(".java")  // Java source file
  19.609 -                    || SourceVersion.isName(s);   // Legal type name
  19.610 -            }
  19.611 -            @Override
  19.612 -            public boolean process(Options options, String option) {
  19.613 -                if (s.endsWith(".java") ) {
  19.614 -                    File f = new File(s);
  19.615 -                    if (!f.exists()) {
  19.616 -                        helper.error("err.file.not.found", f);
  19.617 -                        return true;
  19.618 -                    }
  19.619 -                    if (!f.isFile()) {
  19.620 -                        helper.error("err.file.not.file", f);
  19.621 -                        return true;
  19.622 -                    }
  19.623 -                    helper.addFile(f);
  19.624 -                }
  19.625 -                else
  19.626 -                    helper.addClassName(s);
  19.627 -                return false;
  19.628 -            }
  19.629 -        },
  19.630 -    };
  19.631 -    }
  19.632 -
  19.633 -    public enum PkgInfo {
  19.634 -        ALWAYS, LEGACY, NONEMPTY;
  19.635 -        public static PkgInfo get(Options options) {
  19.636 -            String v = options.get(XPKGINFO);
  19.637 -            return (v == null
  19.638 -                    ? PkgInfo.LEGACY
  19.639 -                    : PkgInfo.valueOf(v.toUpperCase()));
  19.640 -        }
  19.641 -    }
  19.642 -
  19.643 -    private static Map<String,Boolean> getXLintChoices() {
  19.644 -        Map<String,Boolean> choices = new LinkedHashMap<String,Boolean>();
  19.645 -        choices.put("all", false);
  19.646 -        for (Lint.LintCategory c : Lint.LintCategory.values())
  19.647 -            choices.put(c.option, c.hidden);
  19.648 -        for (Lint.LintCategory c : Lint.LintCategory.values())
  19.649 -            choices.put("-" + c.option, c.hidden);
  19.650 -        choices.put("none", false);
  19.651 -        return choices;
  19.652 -    }
  19.653 -
  19.654 -}
    20.1 --- a/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java	Thu Dec 22 19:00:58 2011 -0800
    20.2 +++ b/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java	Fri Dec 23 16:39:22 2011 -0800
    20.3 @@ -63,7 +63,7 @@
    20.4  import com.sun.tools.javac.util.List;
    20.5  import com.sun.tools.javac.util.ListBuffer;
    20.6  
    20.7 -import static com.sun.tools.javac.main.OptionName.*;
    20.8 +import static com.sun.tools.javac.main.Option.*;
    20.9  
   20.10  
   20.11  // NOTE the imports carefully for this compilation unit.
    21.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Dec 22 19:00:58 2011 -0800
    21.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Dec 23 16:39:22 2011 -0800
    21.3 @@ -787,7 +787,7 @@
    21.4              top++;
    21.5              topOp = token;
    21.6              nextToken();
    21.7 -            odStack[top] = (topOp.kind == INSTANCEOF) ? parseType() : term3NoParams();
    21.8 +            odStack[top] = (topOp.kind == INSTANCEOF) ? parseType() : term3();
    21.9              while (top > 0 && prec(topOp.kind) >= prec(token.kind)) {
   21.10                  odStack[top-1] = makeOp(topOp.pos, topOp.kind, odStack[top-1],
   21.11                                          odStack[top]);
   21.12 @@ -931,7 +931,7 @@
   21.13                      mode = EXPR;
   21.14                      t = literal(names.hyphen, pos);
   21.15                  } else {
   21.16 -                    t = term3NoParams();
   21.17 +                    t = term3();
   21.18                      return F.at(pos).Unary(unoptag(tk), t);
   21.19                  }
   21.20              } else return illegal();
   21.21 @@ -947,8 +947,8 @@
   21.22                      break;
   21.23                  } else {
   21.24                      nextToken();
   21.25 -                    mode = EXPR | TYPE;
   21.26 -                    t = term3NoParams();
   21.27 +                    mode = EXPR | TYPE | NOPARAMS;
   21.28 +                    t = term3();
   21.29                      if ((mode & TYPE) != 0 && token.kind == LT) {
   21.30                          // Could be a cast to a parameterized type
   21.31                          JCTree.Tag op = JCTree.Tag.LT;
   21.32 @@ -1011,7 +1011,7 @@
   21.33                  lastmode = mode;
   21.34                  mode = EXPR;
   21.35                  if ((lastmode & EXPR) == 0) {
   21.36 -                    JCExpression t1 = term3NoParams();
   21.37 +                    JCExpression t1 = term3();
   21.38                      return F.at(pos).TypeCast(t, t1);
   21.39                  } else if ((lastmode & TYPE) != 0) {
   21.40                      switch (token.kind) {
   21.41 @@ -1024,7 +1024,7 @@
   21.42                          case NEW: case IDENTIFIER: case ASSERT: case ENUM:
   21.43                      case BYTE: case SHORT: case CHAR: case INT:
   21.44                      case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID:
   21.45 -                        JCExpression t1 = term3NoParams();
   21.46 +                        JCExpression t1 = term3();
   21.47                          return F.at(pos).TypeCast(t, t1);
   21.48                      }
   21.49                  }
   21.50 @@ -1143,49 +1143,35 @@
   21.51                          // typeArgs saved for next loop iteration.
   21.52                          t = toP(F.at(pos).Select(t, ident()));
   21.53                          break;
   21.54 -//                    case LT:
   21.55 -//                        if ((mode & (TYPE | NOPARAMS)) == 0) {
   21.56 -//                            //could be an unbound method reference whose qualifier
   21.57 -//                            //is a generic type i.e. A<S>#m
   21.58 -//                            mode = EXPR | TYPE;
   21.59 -//                            JCTree.Tag op = JCTree.Tag.LT;
   21.60 -//                            int pos1 = token.pos;
   21.61 -//                            nextToken();
   21.62 -//                            mode |= EXPR | TYPE | TYPEARG;
   21.63 -//                            JCExpression t1 = term3();
   21.64 -//                            if ((mode & TYPE) != 0 &&
   21.65 -//                                (token.kind == COMMA || token.kind == GT)) {
   21.66 -//                                mode = TYPE;
   21.67 -//                                ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
   21.68 -//                                args.append(t1);
   21.69 -//                                while (token.kind == COMMA) {
   21.70 -//                                    nextToken();
   21.71 -//                                    args.append(typeArgument());
   21.72 -//                                }
   21.73 -//                                accept(GT);
   21.74 -//                                t = toP(F.at(pos1).TypeApply(t, args.toList()));
   21.75 -//                                checkGenerics();
   21.76 -//                                while (token.kind == DOT) {
   21.77 -//                                    nextToken();
   21.78 -//                                    mode = TYPE;
   21.79 -//                                    t = toP(F.at(token.pos).Select(t, ident()));
   21.80 -//                                    t = typeArgumentsOpt(t);
   21.81 -//                                }
   21.82 -//                                if (token.kind != HASH) {
   21.83 -//                                    //method reference expected here
   21.84 -//                                    t = illegal();
   21.85 -//                                }
   21.86 -//                                mode = EXPR;
   21.87 -//                                break;
   21.88 -//                            } else if ((mode & EXPR) != 0) {
   21.89 -//                                //rollback - it was a binary expression
   21.90 -//                                mode = EXPR;
   21.91 -//                                JCExpression e = term2Rest(t1, TreeInfo.shiftPrec);
   21.92 -//                                t = F.at(pos1).Binary(op, t, e);
   21.93 -//                                t = termRest(term1Rest(term2Rest(t, TreeInfo.orPrec)));
   21.94 -//                            }
   21.95 -//                        }
   21.96 -//                        break loop;
   21.97 +                    case LT:
   21.98 +                        if ((mode & TYPE) == 0 && isUnboundMemberRef()) {
   21.99 +                            //this is an unbound method reference whose qualifier
  21.100 +                            //is a generic type i.e. A<S>#m
  21.101 +                            int pos1 = token.pos;
  21.102 +                            accept(LT);
  21.103 +                            ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
  21.104 +                            args.append(typeArgument());
  21.105 +                            while (token.kind == COMMA) {
  21.106 +                                nextToken();
  21.107 +                                args.append(typeArgument());
  21.108 +                            }
  21.109 +                            accept(GT);
  21.110 +                            t = toP(F.at(pos1).TypeApply(t, args.toList()));
  21.111 +                            checkGenerics();
  21.112 +                            while (token.kind == DOT) {
  21.113 +                                nextToken();
  21.114 +                                mode = TYPE;
  21.115 +                                t = toP(F.at(token.pos).Select(t, ident()));
  21.116 +                                t = typeArgumentsOpt(t);
  21.117 +                            }
  21.118 +                            if (token.kind != HASH) {
  21.119 +                                //method reference expected here
  21.120 +                                t = illegal();
  21.121 +                            }
  21.122 +                            mode = EXPR;
  21.123 +                            return term3Rest(t, typeArgs);
  21.124 +                        }
  21.125 +                        break loop;
  21.126                      default:
  21.127                          break loop;
  21.128                      }
  21.129 @@ -1225,15 +1211,6 @@
  21.130          return term3Rest(t, typeArgs);
  21.131      }
  21.132  
  21.133 -    JCExpression term3NoParams() {
  21.134 -        try {
  21.135 -            mode |= NOPARAMS;
  21.136 -            return term3();
  21.137 -        } finally {
  21.138 -            mode &= ~NOPARAMS;
  21.139 -        }
  21.140 -    }
  21.141 -
  21.142      JCExpression term3Rest(JCExpression t, List<JCExpression> typeArgs) {
  21.143          if (typeArgs != null) illegal();
  21.144          while (true) {
  21.145 @@ -1297,6 +1274,41 @@
  21.146          return toP(t);
  21.147      }
  21.148  
  21.149 +    /**
  21.150 +     * If we see an identifier followed by a '&lt;' it could be an unbound
  21.151 +     * method reference or a binary expression. To disambiguate, look for a
  21.152 +     * matching '&gt;' and see if the subsequent terminal is either '.' or '#'.
  21.153 +     */
  21.154 +    @SuppressWarnings("fallthrough")
  21.155 +    boolean isUnboundMemberRef() {
  21.156 +        int pos = 0, depth = 0;
  21.157 +        for (Token t = S.token(pos) ; ; t = S.token(++pos)) {
  21.158 +            switch (t.kind) {
  21.159 +                case IDENTIFIER: case QUES: case EXTENDS: case SUPER:
  21.160 +                case DOT: case RBRACKET: case LBRACKET: case COMMA:
  21.161 +                case BYTE: case SHORT: case INT: case LONG: case FLOAT:
  21.162 +                case DOUBLE: case BOOLEAN: case CHAR:
  21.163 +                    break;
  21.164 +                case LT:
  21.165 +                    depth++; break;
  21.166 +                case GTGTGT:
  21.167 +                    depth--;
  21.168 +                case GTGT:
  21.169 +                    depth--;
  21.170 +                case GT:
  21.171 +                    depth--;
  21.172 +                    if (depth == 0) {
  21.173 +                        return
  21.174 +                            S.token(pos + 1).kind == TokenKind.DOT ||
  21.175 +                            S.token(pos + 1).kind == TokenKind.HASH;
  21.176 +                    }
  21.177 +                    break;
  21.178 +                default:
  21.179 +                    return false;
  21.180 +            }
  21.181 +        }
  21.182 +    }
  21.183 +
  21.184      JCExpression lambdaExpressionOrStatement(JCVariableDecl firstParam, int pos) {
  21.185          ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
  21.186          params.append(firstParam);
    22.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Thu Dec 22 19:00:58 2011 -0800
    22.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Fri Dec 23 16:39:22 2011 -0800
    22.3 @@ -82,7 +82,7 @@
    22.4  
    22.5  import static javax.tools.StandardLocation.*;
    22.6  import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
    22.7 -import static com.sun.tools.javac.main.OptionName.*;
    22.8 +import static com.sun.tools.javac.main.Option.*;
    22.9  import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
   22.10  
   22.11  /**
   22.12 @@ -1033,12 +1033,10 @@
   22.13              Assert.checkNonNull(options);
   22.14              next.put(Options.optionsKey, options);
   22.15  
   22.16 -            PrintWriter out = context.get(Log.outKey);
   22.17 -            Assert.checkNonNull(out);
   22.18 -            next.put(Log.outKey, out);
   22.19              Locale locale = context.get(Locale.class);
   22.20              if (locale != null)
   22.21                  next.put(Locale.class, locale);
   22.22 +
   22.23              Assert.checkNonNull(messages);
   22.24              next.put(JavacMessages.messagesKey, messages);
   22.25  
   22.26 @@ -1076,6 +1074,9 @@
   22.27              Assert.checkNonNull(tokens);
   22.28              next.put(Tokens.tokensKey, tokens);
   22.29  
   22.30 +            // propogate the log's writers directly, instead of going through context
   22.31 +            Log.instance(next).setWriters(log);
   22.32 +
   22.33              JavaCompiler oldCompiler = JavaCompiler.instance(context);
   22.34              JavaCompiler nextCompiler = JavaCompiler.instance(next);
   22.35              nextCompiler.initRound(oldCompiler);
   22.36 @@ -1472,14 +1473,6 @@
   22.37          return context;
   22.38      }
   22.39  
   22.40 -    /**
   22.41 -     * Internal use method to return the writer being used by the
   22.42 -     * processing environment.
   22.43 -     */
   22.44 -    public PrintWriter getWriter() {
   22.45 -        return context.get(Log.outKey);
   22.46 -    }
   22.47 -
   22.48      public String toString() {
   22.49          return "javac ProcessingEnvironment";
   22.50      }
    23.1 --- a/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java	Thu Dec 22 19:00:58 2011 -0800
    23.2 +++ b/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java	Fri Dec 23 16:39:22 2011 -0800
    23.3 @@ -46,6 +46,7 @@
    23.4  import java.util.HashMap;
    23.5  import java.util.Iterator;
    23.6  import java.util.Map;
    23.7 +import java.util.Set;
    23.8  import javax.tools.JavaFileObject;
    23.9  import javax.tools.JavaFileObject.Kind;
   23.10  
   23.11 @@ -53,9 +54,9 @@
   23.12  import com.sun.tools.javac.code.Source;
   23.13  import com.sun.tools.javac.file.FSInfo;
   23.14  import com.sun.tools.javac.file.Locations;
   23.15 -import com.sun.tools.javac.main.JavacOption;
   23.16 -import com.sun.tools.javac.main.OptionName;
   23.17 -import com.sun.tools.javac.main.RecognizedOptions;
   23.18 +import com.sun.tools.javac.main.Option;
   23.19 +import com.sun.tools.javac.main.OptionHelper;
   23.20 +import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
   23.21  import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
   23.22  
   23.23  /**
   23.24 @@ -101,7 +102,7 @@
   23.25      protected Locations locations;
   23.26  
   23.27      protected Source getSource() {
   23.28 -        String sourceName = options.get(OptionName.SOURCE);
   23.29 +        String sourceName = options.get(Option.SOURCE);
   23.30          Source source = null;
   23.31          if (sourceName != null)
   23.32              source = Source.lookup(sourceName);
   23.33 @@ -145,15 +146,31 @@
   23.34  
   23.35      // <editor-fold defaultstate="collapsed" desc="Option handling">
   23.36      public boolean handleOption(String current, Iterator<String> remaining) {
   23.37 -        for (JavacOption o: javacFileManagerOptions) {
   23.38 +        OptionHelper helper = new GrumpyHelper(log) {
   23.39 +            @Override
   23.40 +            public String get(Option option) {
   23.41 +                return options.get(option.getText());
   23.42 +            }
   23.43 +
   23.44 +            @Override
   23.45 +            public void put(String name, String value) {
   23.46 +                options.put(name, value);
   23.47 +            }
   23.48 +
   23.49 +            @Override
   23.50 +            public void remove(String name) {
   23.51 +                options.remove(name);
   23.52 +            }
   23.53 +        };
   23.54 +        for (Option o: javacFileManagerOptions) {
   23.55              if (o.matches(current))  {
   23.56                  if (o.hasArg()) {
   23.57                      if (remaining.hasNext()) {
   23.58 -                        if (!o.process(options, current, remaining.next()))
   23.59 +                        if (!o.process(helper, current, remaining.next()))
   23.60                              return true;
   23.61                      }
   23.62                  } else {
   23.63 -                    if (!o.process(options, current))
   23.64 +                    if (!o.process(helper, current))
   23.65                          return true;
   23.66                  }
   23.67                  // operand missing, or process returned false
   23.68 @@ -164,12 +181,11 @@
   23.69          return false;
   23.70      }
   23.71      // where
   23.72 -        private static JavacOption[] javacFileManagerOptions =
   23.73 -            RecognizedOptions.getJavacFileManagerOptions(
   23.74 -            new RecognizedOptions.GrumpyHelper(Log.instance(new Context())));
   23.75 +        private static Set<Option> javacFileManagerOptions =
   23.76 +            Option.getJavacFileManagerOptions();
   23.77  
   23.78      public int isSupportedOption(String option) {
   23.79 -        for (JavacOption o : javacFileManagerOptions) {
   23.80 +        for (Option o : javacFileManagerOptions) {
   23.81              if (o.matches(option))
   23.82                  return o.hasArg() ? 1 : 0;
   23.83          }
   23.84 @@ -191,7 +207,7 @@
   23.85      }
   23.86  
   23.87      public String getEncodingName() {
   23.88 -        String encName = options.get(OptionName.ENCODING);
   23.89 +        String encName = options.get(Option.ENCODING);
   23.90          if (encName == null)
   23.91              return getDefaultEncodingName();
   23.92          else
    24.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java	Thu Dec 22 19:00:58 2011 -0800
    24.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java	Fri Dec 23 16:39:22 2011 -0800
    24.3 @@ -25,25 +25,23 @@
    24.4  
    24.5  package com.sun.tools.javac.util;
    24.6  
    24.7 -import com.sun.tools.javac.main.Main;
    24.8  import java.io.*;
    24.9  import java.util.Arrays;
   24.10  import java.util.EnumSet;
   24.11  import java.util.HashSet;
   24.12 -import java.util.Map;
   24.13  import java.util.Queue;
   24.14  import java.util.Set;
   24.15  import javax.tools.DiagnosticListener;
   24.16  import javax.tools.JavaFileObject;
   24.17  
   24.18  import com.sun.tools.javac.api.DiagnosticFormatter;
   24.19 -import com.sun.tools.javac.main.OptionName;
   24.20 +import com.sun.tools.javac.main.Main;
   24.21 +import com.sun.tools.javac.main.Option;
   24.22  import com.sun.tools.javac.parser.EndPosTable;
   24.23 -import com.sun.tools.javac.tree.JCTree;
   24.24  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
   24.25  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
   24.26  
   24.27 -import static com.sun.tools.javac.main.OptionName.*;
   24.28 +import static com.sun.tools.javac.main.Option.*;
   24.29  
   24.30  /** A class for error logs. Reports errors and warnings, and
   24.31   *  keeps track of error numbers and positions.
   24.32 @@ -137,7 +135,6 @@
   24.33  
   24.34      /** Construct a log with given I/O redirections.
   24.35       */
   24.36 -    @Deprecated
   24.37      protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) {
   24.38          super(JCDiagnostic.Factory.instance(context));
   24.39          context.put(logKey, this);
   24.40 @@ -179,8 +176,8 @@
   24.41                  expectDiagKeys = new HashSet<String>(Arrays.asList(ek.split(", *")));
   24.42          }
   24.43  
   24.44 -        private int getIntOption(Options options, OptionName optionName, int defaultValue) {
   24.45 -            String s = options.get(optionName);
   24.46 +        private int getIntOption(Options options, Option option, int defaultValue) {
   24.47 +            String s = options.get(option);
   24.48              try {
   24.49                  if (s != null) {
   24.50                      int n = Integer.parseInt(s);
   24.51 @@ -298,6 +295,12 @@
   24.52          noticeWriter = warnWriter = errWriter = pw;
   24.53      }
   24.54  
   24.55 +    public void setWriters(Log other) {
   24.56 +        this.noticeWriter = other.noticeWriter;
   24.57 +        this.warnWriter = other.warnWriter;
   24.58 +        this.errWriter = other.errWriter;
   24.59 +    }
   24.60 +
   24.61      /** Flush the logs
   24.62       */
   24.63      public void flush() {
    25.1 --- a/src/share/classes/com/sun/tools/javac/util/Options.java	Thu Dec 22 19:00:58 2011 -0800
    25.2 +++ b/src/share/classes/com/sun/tools/javac/util/Options.java	Fri Dec 23 16:39:22 2011 -0800
    25.3 @@ -26,8 +26,8 @@
    25.4  package com.sun.tools.javac.util;
    25.5  
    25.6  import java.util.*;
    25.7 -import com.sun.tools.javac.main.OptionName;
    25.8 -import static com.sun.tools.javac.main.OptionName.*;
    25.9 +import com.sun.tools.javac.main.Option;
   25.10 +import static com.sun.tools.javac.main.Option.*;
   25.11  
   25.12  /** A table of all command-line options.
   25.13   *  If an option has an argument, the option name is mapped to the argument.
   25.14 @@ -71,8 +71,8 @@
   25.15      /**
   25.16       * Get the value for an option.
   25.17       */
   25.18 -    public String get(OptionName name) {
   25.19 -        return values.get(name.optionName);
   25.20 +    public String get(Option option) {
   25.21 +        return values.get(option.text);
   25.22      }
   25.23  
   25.24      /**
   25.25 @@ -101,15 +101,15 @@
   25.26      /**
   25.27       * Check if the value for an option has been set.
   25.28       */
   25.29 -    public boolean isSet(OptionName name) {
   25.30 -        return (values.get(name.optionName) != null);
   25.31 +    public boolean isSet(Option option) {
   25.32 +        return (values.get(option.text) != null);
   25.33      }
   25.34  
   25.35      /**
   25.36       * Check if the value for a choice option has been set to a specific value.
   25.37       */
   25.38 -    public boolean isSet(OptionName name, String value) {
   25.39 -        return (values.get(name.optionName + value) != null);
   25.40 +    public boolean isSet(Option option, String value) {
   25.41 +        return (values.get(option.text + value) != null);
   25.42      }
   25.43  
   25.44      /**
   25.45 @@ -122,23 +122,23 @@
   25.46      /**
   25.47       * Check if the value for an option has not been set.
   25.48       */
   25.49 -    public boolean isUnset(OptionName name) {
   25.50 -        return (values.get(name.optionName) == null);
   25.51 +    public boolean isUnset(Option option) {
   25.52 +        return (values.get(option.text) == null);
   25.53      }
   25.54  
   25.55      /**
   25.56       * Check if the value for a choice option has not been set to a specific value.
   25.57       */
   25.58 -    public boolean isUnset(OptionName name, String value) {
   25.59 -        return (values.get(name.optionName + value) == null);
   25.60 +    public boolean isUnset(Option option, String value) {
   25.61 +        return (values.get(option.text + value) == null);
   25.62      }
   25.63  
   25.64      public void put(String name, String value) {
   25.65          values.put(name, value);
   25.66      }
   25.67  
   25.68 -    public void put(OptionName name, String value) {
   25.69 -        values.put(name.optionName, value);
   25.70 +    public void put(Option option, String value) {
   25.71 +        values.put(option.text, value);
   25.72      }
   25.73  
   25.74      public void putAll(Options options) {
    26.1 --- a/test/tools/javac/4846262/Test.sh	Thu Dec 22 19:00:58 2011 -0800
    26.2 +++ b/test/tools/javac/4846262/Test.sh	Fri Dec 23 16:39:22 2011 -0800
    26.3 @@ -1,7 +1,7 @@
    26.4  #!/bin/sh -f
    26.5  
    26.6  #
    26.7 -# Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
    26.8 +# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
    26.9  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   26.10  #
   26.11  # This code is free software; you can redistribute it and/or modify it
   26.12 @@ -71,7 +71,7 @@
   26.13  diff ${DIFFOPTS} -c "${TESTSRC}${FS}Test.out" Test.out
   26.14  result=$?
   26.15  
   26.16 -if [ $result -eq o ]
   26.17 +if [ $result -eq 0 ]
   26.18  then
   26.19    echo "Passed"
   26.20  else
    27.1 --- a/test/tools/javac/api/T6838467.java	Thu Dec 22 19:00:58 2011 -0800
    27.2 +++ b/test/tools/javac/api/T6838467.java	Fri Dec 23 16:39:22 2011 -0800
    27.3 @@ -32,7 +32,6 @@
    27.4  import java.util.zip.*;
    27.5  import javax.tools.*;
    27.6  import com.sun.tools.javac.file.JavacFileManager;
    27.7 -import com.sun.tools.javac.main.OptionName;
    27.8  import com.sun.tools.javac.util.Context;
    27.9  import com.sun.tools.javac.util.Options;
   27.10  
    28.1 --- a/test/tools/javac/diags/examples/UnsupportedEncoding.java	Thu Dec 22 19:00:58 2011 -0800
    28.2 +++ b/test/tools/javac/diags/examples/UnsupportedEncoding.java	Fri Dec 23 16:39:22 2011 -0800
    28.3 @@ -1,5 +1,5 @@
    28.4  /*
    28.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    28.6 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
    28.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    28.8   *
    28.9   * This code is free software; you can redistribute it and/or modify it
   28.10 @@ -23,5 +23,6 @@
   28.11  
   28.12  // key: compiler.err.unsupported.encoding
   28.13  // options: -encoding UNSUPPORTED -doe
   28.14 +// run: simple
   28.15  
   28.16  class UnsupportedEncoding { }
    29.1 --- a/test/tools/javac/lambda/MethodReferenceParserTest.java	Thu Dec 22 19:00:58 2011 -0800
    29.2 +++ b/test/tools/javac/lambda/MethodReferenceParserTest.java	Fri Dec 23 16:39:22 2011 -0800
    29.3 @@ -24,7 +24,6 @@
    29.4  /*
    29.5   * @test
    29.6   * @bug 7115052
    29.7 - * @ignore 7120266
    29.8   * @summary Add parser support for method references
    29.9   */
   29.10  
   29.11 @@ -45,6 +44,7 @@
   29.12      enum ReferenceKind {
   29.13          METHOD_REF("#Q##Gm"),
   29.14          CONSTRUCTOR_REF("#Q##Gnew"),
   29.15 +        FALSE_REF("min < max"),
   29.16          ERR_SUPER("#Q##Gsuper"),
   29.17          ERR_METH0("#Q##Gm()"),
   29.18          ERR_METH1("#Q##Gm(X)"),
   29.19 @@ -76,6 +76,21 @@
   29.20          }
   29.21      }
   29.22  
   29.23 +    enum ContextKind {
   29.24 +        ASSIGN("SAM s = #E;"),
   29.25 +        METHOD("m(#E, i);");
   29.26 +
   29.27 +        String contextTemplate;
   29.28 +
   29.29 +        ContextKind(String contextTemplate) {
   29.30 +            this.contextTemplate = contextTemplate;
   29.31 +        }
   29.32 +
   29.33 +        String contextString(ExprKind ek, ReferenceKind rk, QualifierKind qk, GenericKind gk, SubExprKind sk) {
   29.34 +            return contextTemplate.replaceAll("#E", ek.expressionString(rk, qk, gk, sk));
   29.35 +        }
   29.36 +    }
   29.37 +
   29.38      enum GenericKind {
   29.39          NONE(""),
   29.40          ONE("<X>"),
   29.41 @@ -97,7 +112,10 @@
   29.42          UBOUND_SIMPLE("A"),
   29.43          UNBOUND_GENERIC1("A<X>"),
   29.44          UNBOUND_GENERIC2("A<X, Y>"),
   29.45 -        UNBOUND_GENERIC3("A<? extends X, ? super Y>");
   29.46 +        UNBOUND_GENERIC3("A<? extends X, ? super Y>"),
   29.47 +        UNBOUND_GENERIC4("A<int[], short[][]>"),
   29.48 +        NESTED_GENERIC1("A<A<X,Y>, A<X,Y>>"),
   29.49 +        NESTED_GENERIC2("A<A<A<X,Y>,A<X,Y>>, A<A<X,Y>,A<X,Y>>>");
   29.50  
   29.51          String qualifier;
   29.52  
   29.53 @@ -153,7 +171,9 @@
   29.54                  for (GenericKind gk : GenericKind.values()) {
   29.55                      for (SubExprKind sk : SubExprKind.values()) {
   29.56                          for (ExprKind ek : ExprKind.values()) {
   29.57 -                            new MethodReferenceParserTest(rk, qk, gk, sk, ek).run(comp, fm);
   29.58 +                            for (ContextKind ck : ContextKind.values()) {
   29.59 +                                new MethodReferenceParserTest(rk, qk, gk, sk, ek, ck).run(comp, fm);
   29.60 +                            }
   29.61                          }
   29.62                      }
   29.63                  }
   29.64 @@ -167,15 +187,17 @@
   29.65      GenericKind gk;
   29.66      SubExprKind sk;
   29.67      ExprKind ek;
   29.68 +    ContextKind ck;
   29.69      JavaSource source;
   29.70      DiagnosticChecker diagChecker;
   29.71  
   29.72 -    MethodReferenceParserTest(ReferenceKind rk, QualifierKind qk, GenericKind gk, SubExprKind sk, ExprKind ek) {
   29.73 +    MethodReferenceParserTest(ReferenceKind rk, QualifierKind qk, GenericKind gk, SubExprKind sk, ExprKind ek, ContextKind ck) {
   29.74          this.rk = rk;
   29.75          this.qk = qk;
   29.76          this.gk = gk;
   29.77          this.sk = sk;
   29.78          this.ek = ek;
   29.79 +        this.ck = ck;
   29.80          this.source = new JavaSource();
   29.81          this.diagChecker = new DiagnosticChecker();
   29.82      }
   29.83 @@ -183,14 +205,16 @@
   29.84      class JavaSource extends SimpleJavaFileObject {
   29.85  
   29.86          String template = "class Test {\n" +
   29.87 -                          "   SAM s = #E;\n" +
   29.88 +                          "   void test() {\n" +
   29.89 +                          "      #C\n" +
   29.90 +                          "   }" +
   29.91                            "}";
   29.92  
   29.93          String source;
   29.94  
   29.95          public JavaSource() {
   29.96              super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
   29.97 -            source = template.replaceAll("#E", ek.expressionString(rk, qk, gk, sk));
   29.98 +            source = template.replaceAll("#C", ck.contextString(ek, rk, qk, gk, sk));
   29.99          }
  29.100  
  29.101          @Override
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/test/tools/javac/processing/options/testPrintProcessorInfo/TestWithXstdout.java	Fri Dec 23 16:39:22 2011 -0800
    30.3 @@ -0,0 +1,91 @@
    30.4 +/*
    30.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
    30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    30.7 + *
    30.8 + * This code is free software; you can redistribute it and/or modify it
    30.9 + * under the terms of the GNU General Public License version 2 only, as
   30.10 + * published by the Free Software Foundation.
   30.11 + *
   30.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   30.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   30.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   30.15 + * version 2 for more details (a copy is included in the LICENSE file that
   30.16 + * accompanied this code).
   30.17 + *
   30.18 + * You should have received a copy of the GNU General Public License version
   30.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   30.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   30.21 + *
   30.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   30.23 + * or visit www.oracle.com if you need additional information or have any
   30.24 + * questions.
   30.25 + */
   30.26 +
   30.27 +/*
   30.28 + * @test
   30.29 + * @bug 6987384
   30.30 + * @summary -XprintProcessorRoundsInfo message printed with different timing than previous
   30.31 + * @library ../../../lib
   30.32 + * @build JavacTestingAbstractProcessor Test TestWithXstdout
   30.33 + * @run main TestWithXstdout
   30.34 + */
   30.35 +
   30.36 +import java.io.*;
   30.37 +import java.nio.charset.*;
   30.38 +import java.nio.file.*;
   30.39 +import java.util.*;
   30.40 +
   30.41 +public class TestWithXstdout {
   30.42 +    public static void main(String... args) throws Exception {
   30.43 +        File testSrc = new File(System.getProperty("test.src"));
   30.44 +        File testClasses = new File(System.getProperty("test.classes"));
   30.45 +        File stdout = new File("stdout.out");
   30.46 +        run_javac("-XDrawDiagnostics",
   30.47 +                "-XprintProcessorInfo",
   30.48 +                "-Werror",
   30.49 +                "-proc:only",
   30.50 +                "-processor",  "Test",
   30.51 +                "-Xstdout", stdout.getPath(),
   30.52 +                "-classpath", testClasses.getPath(),
   30.53 +                new File(testSrc, "Test.java").getPath());
   30.54 +        boolean ok = compare(stdout, new File(testSrc, "Test.out"));
   30.55 +        if (!ok)
   30.56 +            throw new Exception("differences found");
   30.57 +    }
   30.58 +
   30.59 +    static void run_javac(String... args) throws IOException, InterruptedException {
   30.60 +        File javaHome = new File(System.getProperty("java.home"));
   30.61 +        if (javaHome.getName().equals("jre"))
   30.62 +            javaHome = javaHome.getParentFile();
   30.63 +        File javac = new File(new File(javaHome, "bin"), "javac");
   30.64 +
   30.65 +        List<String> opts = new ArrayList<>();
   30.66 +        opts.add(javac.getPath());
   30.67 +
   30.68 +        String toolOpts = System.getProperty("test.tool.vm.opts");
   30.69 +        if (toolOpts != null && !"".equals(toolOpts.trim())) {
   30.70 +            opts.addAll(Arrays.asList(toolOpts.trim().split("[\\s]+")));
   30.71 +        }
   30.72 +        opts.addAll(Arrays.asList(args));
   30.73 +        System.out.println("exec: " + opts);
   30.74 +        ProcessBuilder pb = new ProcessBuilder(opts);
   30.75 +        pb.redirectErrorStream();
   30.76 +        Process p = pb.start();
   30.77 +        try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
   30.78 +            String line;
   30.79 +            while ((line = r.readLine()) != null)
   30.80 +                System.out.println();
   30.81 +        }
   30.82 +        int rc = p.waitFor();
   30.83 +        if (rc != 0)
   30.84 +            System.out.println("javac exited, rc=" + rc);
   30.85 +    }
   30.86 +
   30.87 +    static boolean compare(File a, File b) throws IOException {
   30.88 +        List<String> aLines = Files.readAllLines(a.toPath(), Charset.defaultCharset());
   30.89 +        List<String> bLines = Files.readAllLines(b.toPath(), Charset.defaultCharset());
   30.90 +        System.out.println(a + ": " + aLines.size() + " lines");
   30.91 +        System.out.println(b + ": " + bLines.size() + " lines");
   30.92 +        return aLines.equals(bLines);
   30.93 +    }
   30.94 +}
    31.1 --- a/test/tools/javac/util/T6597678.java	Thu Dec 22 19:00:58 2011 -0800
    31.2 +++ b/test/tools/javac/util/T6597678.java	Fri Dec 23 16:39:22 2011 -0800
    31.3 @@ -41,6 +41,7 @@
    31.4  import com.sun.tools.javac.processing.JavacProcessingEnvironment;
    31.5  import com.sun.tools.javac.util.Context;
    31.6  import com.sun.tools.javac.util.JavacMessages;
    31.7 +import com.sun.tools.javac.util.Log;
    31.8  
    31.9  @SupportedOptions("WriterString")
   31.10  public class T6597678 extends JavacTestingAbstractProcessor {
   31.11 @@ -78,7 +79,10 @@
   31.12      @Override
   31.13      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   31.14          Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
   31.15 -        PrintWriter out = ((JavacProcessingEnvironment) processingEnv).getWriter();
   31.16 +        Log log = Log.instance(context);
   31.17 +        PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE);
   31.18 +        PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING);
   31.19 +        PrintWriter errOut  = log.getWriter(Log.WriterKind.ERROR);
   31.20          Locale locale = context.get(Locale.class);
   31.21          JavacMessages messages = context.get(JavacMessages.messagesKey);
   31.22  
   31.23 @@ -86,13 +90,20 @@
   31.24          if (round == 1) {
   31.25              initialLocale = locale;
   31.26              initialMessages = messages;
   31.27 -            initialWriter = out;
   31.28 +            initialNoteWriter = noteOut;
   31.29 +            initialWarnWriter = warnOut;
   31.30 +            initialErrWriter  = errOut;
   31.31  
   31.32 -            checkEqual("writerString", out.toString().intern(), options.get("WriterString").intern());
   31.33 +            String writerStringOpt = options.get("WriterString").intern();
   31.34 +            checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt);
   31.35 +            checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt);
   31.36 +            checkEqual("errWriterString",  errOut.toString().intern(),  writerStringOpt);
   31.37          } else {
   31.38              checkEqual("locale", locale, initialLocale);
   31.39              checkEqual("messages", messages, initialMessages);
   31.40 -            checkEqual("writer", out, initialWriter);
   31.41 +            checkEqual("noteWriter", noteOut, initialNoteWriter);
   31.42 +            checkEqual("warnWriter", warnOut, initialWarnWriter);
   31.43 +            checkEqual("errWriter",  errOut,  initialErrWriter);
   31.44          }
   31.45  
   31.46          return true;
   31.47 @@ -109,5 +120,7 @@
   31.48      int round = 0;
   31.49      Locale initialLocale;
   31.50      JavacMessages initialMessages;
   31.51 -    PrintWriter initialWriter;
   31.52 +    PrintWriter initialNoteWriter;
   31.53 +    PrintWriter initialWarnWriter;
   31.54 +    PrintWriter initialErrWriter;
   31.55  }

mercurial