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

changeset 1
9a66ca7c79fa
child 11
b66d15dfd001
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,615 @@
     1.4 +/*
     1.5 + * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Sun designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Sun in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 + * have any questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.javac.main;
    1.30 +
    1.31 +import com.sun.tools.javac.code.Source;
    1.32 +import com.sun.tools.javac.code.Type;
    1.33 +import com.sun.tools.javac.jvm.Target;
    1.34 +import com.sun.tools.javac.main.JavacOption.HiddenOption;
    1.35 +import com.sun.tools.javac.main.JavacOption.Option;
    1.36 +import com.sun.tools.javac.main.JavacOption.XOption;
    1.37 +import com.sun.tools.javac.util.List;
    1.38 +import com.sun.tools.javac.util.ListBuffer;
    1.39 +import com.sun.tools.javac.util.Log;
    1.40 +import com.sun.tools.javac.util.Options;
    1.41 +import com.sun.tools.javac.processing.JavacProcessingEnvironment;
    1.42 +import java.io.File;
    1.43 +import java.io.FileWriter;
    1.44 +import java.io.PrintWriter;
    1.45 +import java.util.EnumSet;
    1.46 +import java.util.Set;
    1.47 +import java.util.StringTokenizer;
    1.48 +import javax.lang.model.SourceVersion;
    1.49 +
    1.50 +import static com.sun.tools.javac.main.OptionName.*;
    1.51 +
    1.52 +/**
    1.53 + * TODO: describe com.sun.tools.javac.main.RecognizedOptions
    1.54 + *
    1.55 + * <p><b>This is NOT part of any API supported by Sun Microsystems.
    1.56 + * If you write code that depends on this, you do so at your own
    1.57 + * risk.  This code and its internal interfaces are subject to change
    1.58 + * or deletion without notice.</b></p>
    1.59 + */
    1.60 +public class RecognizedOptions {
    1.61 +
    1.62 +    private RecognizedOptions() {}
    1.63 +
    1.64 +    public interface OptionHelper {
    1.65 +
    1.66 +        void setOut(PrintWriter out);
    1.67 +
    1.68 +        void error(String key, Object... args);
    1.69 +
    1.70 +        void printVersion();
    1.71 +
    1.72 +        void printFullVersion();
    1.73 +
    1.74 +        void printHelp();
    1.75 +
    1.76 +        void printXhelp();
    1.77 +
    1.78 +        void addFile(File f);
    1.79 +
    1.80 +        void addClassName(String s);
    1.81 +
    1.82 +    }
    1.83 +
    1.84 +    public static class GrumpyHelper implements OptionHelper {
    1.85 +
    1.86 +        public void setOut(PrintWriter out) {
    1.87 +            throw new IllegalArgumentException();
    1.88 +        }
    1.89 +
    1.90 +        public void error(String key, Object... args) {
    1.91 +            throw new IllegalArgumentException(Main.getLocalizedString(key, args));
    1.92 +        }
    1.93 +
    1.94 +        public void printVersion() {
    1.95 +            throw new IllegalArgumentException();
    1.96 +        }
    1.97 +
    1.98 +        public void printFullVersion() {
    1.99 +            throw new IllegalArgumentException();
   1.100 +        }
   1.101 +
   1.102 +        public void printHelp() {
   1.103 +            throw new IllegalArgumentException();
   1.104 +        }
   1.105 +
   1.106 +        public void printXhelp() {
   1.107 +            throw new IllegalArgumentException();
   1.108 +        }
   1.109 +
   1.110 +        public void addFile(File f) {
   1.111 +            throw new IllegalArgumentException(f.getPath());
   1.112 +        }
   1.113 +
   1.114 +        public void addClassName(String s) {
   1.115 +            throw new IllegalArgumentException(s);
   1.116 +        }
   1.117 +
   1.118 +    }
   1.119 +
   1.120 +    static Set<OptionName> javacOptions = EnumSet.of(
   1.121 +        G,
   1.122 +        G_NONE,
   1.123 +        G_CUSTOM,
   1.124 +        XLINT,
   1.125 +        XLINT_CUSTOM,
   1.126 +        NOWARN,
   1.127 +        VERBOSE,
   1.128 +        DEPRECATION,
   1.129 +        CLASSPATH,
   1.130 +        CP,
   1.131 +        SOURCEPATH,
   1.132 +        BOOTCLASSPATH,
   1.133 +        XBOOTCLASSPATH_PREPEND,
   1.134 +        XBOOTCLASSPATH_APPEND,
   1.135 +        XBOOTCLASSPATH,
   1.136 +        EXTDIRS,
   1.137 +        DJAVA_EXT_DIRS,
   1.138 +        ENDORSEDDIRS,
   1.139 +        DJAVA_ENDORSED_DIRS,
   1.140 +        PROC_CUSTOM,
   1.141 +        PROCESSOR,
   1.142 +        PROCESSORPATH,
   1.143 +        D,
   1.144 +        S,
   1.145 +        IMPLICIT,
   1.146 +        ENCODING,
   1.147 +        SOURCE,
   1.148 +        TARGET,
   1.149 +        VERSION,
   1.150 +        FULLVERSION,
   1.151 +        HELP,
   1.152 +        A,
   1.153 +        X,
   1.154 +        J,
   1.155 +        MOREINFO,
   1.156 +        WERROR,
   1.157 +        // COMPLEXINFERENCE,
   1.158 +        PROMPT,
   1.159 +        DOE,
   1.160 +        PRINTSOURCE,
   1.161 +        WARNUNCHECKED,
   1.162 +        XMAXERRS,
   1.163 +        XMAXWARNS,
   1.164 +        XSTDOUT,
   1.165 +        XPRINT,
   1.166 +        XPRINTROUNDS,
   1.167 +        XPRINTPROCESSORINFO,
   1.168 +        XPREFER,
   1.169 +        O,
   1.170 +        XJCOV,
   1.171 +        XD,
   1.172 +        SOURCEFILE);
   1.173 +
   1.174 +    static Set<OptionName> javacFileManagerOptions = EnumSet.of(
   1.175 +        CLASSPATH,
   1.176 +        CP,
   1.177 +        SOURCEPATH,
   1.178 +        BOOTCLASSPATH,
   1.179 +        XBOOTCLASSPATH_PREPEND,
   1.180 +        XBOOTCLASSPATH_APPEND,
   1.181 +        XBOOTCLASSPATH,
   1.182 +        EXTDIRS,
   1.183 +        DJAVA_EXT_DIRS,
   1.184 +        ENDORSEDDIRS,
   1.185 +        DJAVA_ENDORSED_DIRS,
   1.186 +        PROCESSORPATH,
   1.187 +        D,
   1.188 +        S,
   1.189 +        ENCODING,
   1.190 +        SOURCE);
   1.191 +
   1.192 +    static Set<OptionName> javacToolOptions = EnumSet.of(
   1.193 +        G,
   1.194 +        G_NONE,
   1.195 +        G_CUSTOM,
   1.196 +        XLINT,
   1.197 +        XLINT_CUSTOM,
   1.198 +        NOWARN,
   1.199 +        VERBOSE,
   1.200 +        DEPRECATION,
   1.201 +        PROC_CUSTOM,
   1.202 +        PROCESSOR,
   1.203 +        IMPLICIT,
   1.204 +        SOURCE,
   1.205 +        TARGET,
   1.206 +        // VERSION,
   1.207 +        // FULLVERSION,
   1.208 +        // HELP,
   1.209 +        A,
   1.210 +        // X,
   1.211 +        // J,
   1.212 +        MOREINFO,
   1.213 +        WERROR,
   1.214 +        // COMPLEXINFERENCE,
   1.215 +        PROMPT,
   1.216 +        DOE,
   1.217 +        PRINTSOURCE,
   1.218 +        WARNUNCHECKED,
   1.219 +        XMAXERRS,
   1.220 +        XMAXWARNS,
   1.221 +        // XSTDOUT,
   1.222 +        XPRINT,
   1.223 +        XPRINTROUNDS,
   1.224 +        XPRINTPROCESSORINFO,
   1.225 +        XPREFER,
   1.226 +        O,
   1.227 +        XJCOV,
   1.228 +        XD);
   1.229 +
   1.230 +    static Option[] getJavaCompilerOptions(OptionHelper helper) {
   1.231 +        return getOptions(helper, javacOptions);
   1.232 +    }
   1.233 +
   1.234 +    public static Option[] getJavacFileManagerOptions(OptionHelper helper) {
   1.235 +        return getOptions(helper, javacFileManagerOptions);
   1.236 +    }
   1.237 +
   1.238 +    public static Option[] getJavacToolOptions(OptionHelper helper) {
   1.239 +        return getOptions(helper, javacToolOptions);
   1.240 +    }
   1.241 +
   1.242 +    static Option[] getOptions(OptionHelper helper, Set<OptionName> desired) {
   1.243 +        ListBuffer<Option> options = new ListBuffer<Option>();
   1.244 +        for (Option option : getAll(helper))
   1.245 +            if (desired.contains(option.getName()))
   1.246 +                options.append(option);
   1.247 +        return options.toArray(new Option[options.length()]);
   1.248 +    }
   1.249 +
   1.250 +    /**
   1.251 +     * @param out the writer to use for diagnostic output
   1.252 +     */
   1.253 +    public static Option[] getAll(final OptionHelper helper) {
   1.254 +        return new Option[]{
   1.255 +        new Option(G,                                           "opt.g"),
   1.256 +        new Option(G_NONE,                                      "opt.g.none") {
   1.257 +            public boolean process(Options options, String option) {
   1.258 +                options.put("-g:", "none");
   1.259 +                return false;
   1.260 +            }
   1.261 +        },
   1.262 +
   1.263 +        new Option(G_CUSTOM,                                    "opt.g.lines.vars.source") {
   1.264 +            public boolean matches(String s) {
   1.265 +                return s.startsWith("-g:");
   1.266 +            }
   1.267 +            public boolean process(Options options, String option) {
   1.268 +                String suboptions = option.substring(3);
   1.269 +                options.put("-g:", suboptions);
   1.270 +                // enter all the -g suboptions as "-g:suboption"
   1.271 +                for (StringTokenizer t = new StringTokenizer(suboptions, ","); t.hasMoreTokens(); ) {
   1.272 +                    String tok = t.nextToken();
   1.273 +                    String opt = "-g:" + tok;
   1.274 +                    options.put(opt, opt);
   1.275 +                }
   1.276 +                return false;
   1.277 +            }
   1.278 +        },
   1.279 +
   1.280 +        new XOption(XLINT,                                      "opt.Xlint"),
   1.281 +        new XOption(XLINT_CUSTOM,                               "opt.Xlint.suboptlist") {
   1.282 +            public boolean matches(String s) {
   1.283 +                return s.startsWith("-Xlint:");
   1.284 +            }
   1.285 +            public boolean process(Options options, String option) {
   1.286 +                String suboptions = option.substring(7);
   1.287 +                options.put("-Xlint:", suboptions);
   1.288 +                // enter all the -Xlint suboptions as "-Xlint:suboption"
   1.289 +                for (StringTokenizer t = new StringTokenizer(suboptions, ","); t.hasMoreTokens(); ) {
   1.290 +                    String tok = t.nextToken();
   1.291 +                    String opt = "-Xlint:" + tok;
   1.292 +                    options.put(opt, opt);
   1.293 +                }
   1.294 +                return false;
   1.295 +            }
   1.296 +        },
   1.297 +
   1.298 +        // -nowarn is retained for command-line backward compatibility
   1.299 +        new Option(NOWARN,                                      "opt.nowarn") {
   1.300 +                public boolean process(Options options, String option) {
   1.301 +                    options.put("-Xlint:none", option);
   1.302 +                    return false;
   1.303 +                }
   1.304 +            },
   1.305 +
   1.306 +        new Option(VERBOSE,                                     "opt.verbose"),
   1.307 +
   1.308 +        // -deprecation is retained for command-line backward compatibility
   1.309 +        new Option(DEPRECATION,                                 "opt.deprecation") {
   1.310 +                public boolean process(Options options, String option) {
   1.311 +                    options.put("-Xlint:deprecation", option);
   1.312 +                    return false;
   1.313 +                }
   1.314 +            },
   1.315 +
   1.316 +        new Option(CLASSPATH,              "opt.arg.path",      "opt.classpath"),
   1.317 +        new Option(CP,                     "opt.arg.path",      "opt.classpath") {
   1.318 +            public boolean process(Options options, String option, String arg) {
   1.319 +                return super.process(options, "-classpath", arg);
   1.320 +            }
   1.321 +        },
   1.322 +        new Option(SOURCEPATH,             "opt.arg.path",      "opt.sourcepath"),
   1.323 +        new Option(BOOTCLASSPATH,          "opt.arg.path",      "opt.bootclasspath") {
   1.324 +            public boolean process(Options options, String option, String arg) {
   1.325 +                options.remove("-Xbootclasspath/p:");
   1.326 +                options.remove("-Xbootclasspath/a:");
   1.327 +                return super.process(options, option, arg);
   1.328 +            }
   1.329 +        },
   1.330 +        new XOption(XBOOTCLASSPATH_PREPEND,"opt.arg.path", "opt.Xbootclasspath.p"),
   1.331 +        new XOption(XBOOTCLASSPATH_APPEND, "opt.arg.path", "opt.Xbootclasspath.a"),
   1.332 +        new XOption(XBOOTCLASSPATH,        "opt.arg.path", "opt.bootclasspath") {
   1.333 +            public boolean process(Options options, String option, String arg) {
   1.334 +                options.remove("-Xbootclasspath/p:");
   1.335 +                options.remove("-Xbootclasspath/a:");
   1.336 +                return super.process(options, "-bootclasspath", arg);
   1.337 +            }
   1.338 +        },
   1.339 +        new Option(EXTDIRS,                "opt.arg.dirs",      "opt.extdirs"),
   1.340 +        new XOption(DJAVA_EXT_DIRS,        "opt.arg.dirs",      "opt.extdirs") {
   1.341 +            public boolean process(Options options, String option, String arg) {
   1.342 +                return super.process(options, "-extdirs", arg);
   1.343 +            }
   1.344 +        },
   1.345 +        new Option(ENDORSEDDIRS,            "opt.arg.dirs",     "opt.endorseddirs"),
   1.346 +        new XOption(DJAVA_ENDORSED_DIRS,    "opt.arg.dirs",     "opt.endorseddirs") {
   1.347 +            public boolean process(Options options, String option, String arg) {
   1.348 +                return super.process(options, "-endorseddirs", arg);
   1.349 +            }
   1.350 +        },
   1.351 +        new Option(PROC_CUSTOM,                                 "opt.proc.none.only") {
   1.352 +            public boolean matches(String s) {
   1.353 +                return s.equals("-proc:none") || s.equals("-proc:only");
   1.354 +            }
   1.355 +
   1.356 +            public boolean process(Options options, String option) {
   1.357 +                if (option.equals("-proc:none")) {
   1.358 +                    options.remove("-proc:only");
   1.359 +                } else {
   1.360 +                    options.remove("-proc:none");
   1.361 +                }
   1.362 +                options.put(option, option);
   1.363 +                return false;
   1.364 +            }
   1.365 +        },
   1.366 +        new Option(PROCESSOR,           "opt.arg.class.list",   "opt.processor"),
   1.367 +        new Option(PROCESSORPATH,       "opt.arg.path",         "opt.processorpath"),
   1.368 +        new Option(D,                   "opt.arg.directory",    "opt.d"),
   1.369 +        new Option(S,                   "opt.arg.directory",    "opt.sourceDest"),
   1.370 +        new Option(IMPLICIT,                                    "opt.implicit") {
   1.371 +            public boolean matches(String s) {
   1.372 +                return s.equals("-implicit:none") || s.equals("-implicit:class");
   1.373 +            }
   1.374 +            public boolean process(Options options, String option, String operand) {
   1.375 +                int sep = option.indexOf(":");
   1.376 +                options.put(option.substring(0, sep), option.substring(sep+1));
   1.377 +                options.put(option,option);
   1.378 +                return false;
   1.379 +            }
   1.380 +        },
   1.381 +        new Option(ENCODING,            "opt.arg.encoding",     "opt.encoding"),
   1.382 +        new Option(SOURCE,              "opt.arg.release",      "opt.source") {
   1.383 +            public boolean process(Options options, String option, String operand) {
   1.384 +                Source source = Source.lookup(operand);
   1.385 +                if (source == null) {
   1.386 +                    helper.error("err.invalid.source", operand);
   1.387 +                    return true;
   1.388 +                }
   1.389 +                return super.process(options, option, operand);
   1.390 +            }
   1.391 +        },
   1.392 +        new Option(TARGET,              "opt.arg.release",      "opt.target") {
   1.393 +            public boolean process(Options options, String option, String operand) {
   1.394 +                Target target = Target.lookup(operand);
   1.395 +                if (target == null) {
   1.396 +                    helper.error("err.invalid.target", operand);
   1.397 +                    return true;
   1.398 +                }
   1.399 +                return super.process(options, option, operand);
   1.400 +            }
   1.401 +        },
   1.402 +        new Option(VERSION,                                     "opt.version") {
   1.403 +            public boolean process(Options options, String option) {
   1.404 +                helper.printVersion();
   1.405 +                return super.process(options, option);
   1.406 +            }
   1.407 +        },
   1.408 +        new HiddenOption(FULLVERSION) {
   1.409 +            public boolean process(Options options, String option) {
   1.410 +                helper.printFullVersion();
   1.411 +                return super.process(options, option);
   1.412 +            }
   1.413 +        },
   1.414 +        new Option(HELP,                                        "opt.help") {
   1.415 +            public boolean process(Options options, String option) {
   1.416 +                helper.printHelp();
   1.417 +                return super.process(options, option);
   1.418 +            }
   1.419 +        },
   1.420 +        new Option(A,                "opt.arg.key.equals.value","opt.A") {
   1.421 +                String helpSynopsis() {
   1.422 +                    hasSuffix = true;
   1.423 +                    return super.helpSynopsis();
   1.424 +                }
   1.425 +
   1.426 +                public boolean matches(String arg) {
   1.427 +                    return arg.startsWith("-A");
   1.428 +                }
   1.429 +
   1.430 +                public boolean hasArg() {
   1.431 +                    return false;
   1.432 +                }
   1.433 +                // Mapping for processor options created in
   1.434 +                // JavacProcessingEnvironment
   1.435 +                public boolean process(Options options, String option) {
   1.436 +                    int argLength = option.length();
   1.437 +                    if (argLength == 2) {
   1.438 +                        helper.error("err.empty.A.argument");
   1.439 +                        return true;
   1.440 +                    }
   1.441 +                    int sepIndex = option.indexOf('=');
   1.442 +                    String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength) );
   1.443 +                    if (!JavacProcessingEnvironment.isValidOptionName(key)) {
   1.444 +                        helper.error("err.invalid.A.key", option);
   1.445 +                        return true;
   1.446 +                    }
   1.447 +                    return process(options, option, option);
   1.448 +                }
   1.449 +        },
   1.450 +        new Option(X,                                           "opt.X") {
   1.451 +            public boolean process(Options options, String option) {
   1.452 +                helper.printXhelp();
   1.453 +                return super.process(options, option);
   1.454 +            }
   1.455 +        },
   1.456 +
   1.457 +        // This option exists only for the purpose of documenting itself.
   1.458 +        // It's actually implemented by the launcher.
   1.459 +        new Option(J,                   "opt.arg.flag",         "opt.J") {
   1.460 +            String helpSynopsis() {
   1.461 +                hasSuffix = true;
   1.462 +                return super.helpSynopsis();
   1.463 +            }
   1.464 +            public boolean process(Options options, String option) {
   1.465 +                throw new AssertionError
   1.466 +                    ("the -J flag should be caught by the launcher.");
   1.467 +            }
   1.468 +        },
   1.469 +
   1.470 +        // stop after parsing and attributing.
   1.471 +        // new HiddenOption("-attrparseonly"),
   1.472 +
   1.473 +        // new Option("-moreinfo",                                      "opt.moreinfo") {
   1.474 +        new HiddenOption(MOREINFO) {
   1.475 +            public boolean process(Options options, String option) {
   1.476 +                Type.moreInfo = true;
   1.477 +                return super.process(options, option);
   1.478 +            }
   1.479 +        },
   1.480 +
   1.481 +        // treat warnings as errors
   1.482 +        new HiddenOption(WERROR),
   1.483 +
   1.484 +        // use complex inference from context in the position of a method call argument
   1.485 +        new HiddenOption(COMPLEXINFERENCE),
   1.486 +
   1.487 +        // generare source stubs
   1.488 +        // new HiddenOption("-stubs"),
   1.489 +
   1.490 +        // relax some constraints to allow compiling from stubs
   1.491 +        // new HiddenOption("-relax"),
   1.492 +
   1.493 +        // output source after translating away inner classes
   1.494 +        // new Option("-printflat",                             "opt.printflat"),
   1.495 +        // new HiddenOption("-printflat"),
   1.496 +
   1.497 +        // display scope search details
   1.498 +        // new Option("-printsearch",                           "opt.printsearch"),
   1.499 +        // new HiddenOption("-printsearch"),
   1.500 +
   1.501 +        // prompt after each error
   1.502 +        // new Option("-prompt",                                        "opt.prompt"),
   1.503 +        new HiddenOption(PROMPT),
   1.504 +
   1.505 +        // dump stack on error
   1.506 +        new HiddenOption(DOE),
   1.507 +
   1.508 +        // output source after type erasure
   1.509 +        // new Option("-s",                                     "opt.s"),
   1.510 +        new HiddenOption(PRINTSOURCE),
   1.511 +
   1.512 +        // output shrouded class files
   1.513 +        // new Option("-scramble",                              "opt.scramble"),
   1.514 +        // new Option("-scrambleall",                           "opt.scrambleall"),
   1.515 +
   1.516 +        // display warnings for generic unchecked operations
   1.517 +        new HiddenOption(WARNUNCHECKED) {
   1.518 +            public boolean process(Options options, String option) {
   1.519 +                options.put("-Xlint:unchecked", option);
   1.520 +                return false;
   1.521 +            }
   1.522 +        },
   1.523 +
   1.524 +        new XOption(XMAXERRS,           "opt.arg.number",       "opt.maxerrs"),
   1.525 +        new XOption(XMAXWARNS,          "opt.arg.number",       "opt.maxwarns"),
   1.526 +        new XOption(XSTDOUT,            "opt.arg.file",         "opt.Xstdout") {
   1.527 +            public boolean process(Options options, String option, String arg) {
   1.528 +                try {
   1.529 +                    helper.setOut(new PrintWriter(new FileWriter(arg), true));
   1.530 +                } catch (java.io.IOException e) {
   1.531 +                    helper.error("err.error.writing.file", arg, e);
   1.532 +                    return true;
   1.533 +                }
   1.534 +                return super.process(options, option, arg);
   1.535 +            }
   1.536 +        },
   1.537 +
   1.538 +        new XOption(XPRINT,                                     "opt.print"),
   1.539 +
   1.540 +        new XOption(XPRINTROUNDS,                               "opt.printRounds"),
   1.541 +
   1.542 +        new XOption(XPRINTPROCESSORINFO,                        "opt.printProcessorInfo"),
   1.543 +
   1.544 +        new XOption(XPREFER,                                     "opt.prefer") {
   1.545 +            public boolean matches(String s) {
   1.546 +                return s.equals("-Xprefer:source") || s.equals("-Xprefer:newer");
   1.547 +            }
   1.548 +            public boolean process(Options options, String option, String operand) {
   1.549 +                int sep = option.indexOf(":");
   1.550 +                options.put(option.substring(0, sep), option.substring(sep+1));
   1.551 +                options.put(option,option);
   1.552 +                return false;
   1.553 +            }
   1.554 +        },
   1.555 +
   1.556 +        /* -O is a no-op, accepted for backward compatibility. */
   1.557 +        new HiddenOption(O),
   1.558 +
   1.559 +        /* -Xjcov produces tables to support the code coverage tool jcov. */
   1.560 +        new HiddenOption(XJCOV),
   1.561 +
   1.562 +        /* This is a back door to the compiler's option table.
   1.563 +         * -XDx=y sets the option x to the value y.
   1.564 +         * -XDx sets the option x to the value x.
   1.565 +         */
   1.566 +        new HiddenOption(XD) {
   1.567 +            String s;
   1.568 +            public boolean matches(String s) {
   1.569 +                this.s = s;
   1.570 +                return s.startsWith(name.optionName);
   1.571 +            }
   1.572 +            public boolean process(Options options, String option) {
   1.573 +                s = s.substring(name.optionName.length());
   1.574 +                int eq = s.indexOf('=');
   1.575 +                String key = (eq < 0) ? s : s.substring(0, eq);
   1.576 +                String value = (eq < 0) ? s : s.substring(eq+1);
   1.577 +                options.put(key, value);
   1.578 +                return false;
   1.579 +            }
   1.580 +        },
   1.581 +
   1.582 +        /*
   1.583 +         * TODO: With apt, the matches method accepts anything if
   1.584 +         * -XclassAsDecls is used; code elsewhere does the lookup to
   1.585 +         * see if the class name is both legal and found.
   1.586 +         *
   1.587 +         * In apt, the process method adds the candiate class file
   1.588 +         * name to a separate list.
   1.589 +         */
   1.590 +        new HiddenOption(SOURCEFILE) {
   1.591 +            String s;
   1.592 +            public boolean matches(String s) {
   1.593 +                this.s = s;
   1.594 +                return s.endsWith(".java")  // Java source file
   1.595 +                    || SourceVersion.isName(s);   // Legal type name
   1.596 +            }
   1.597 +            public boolean process(Options options, String option) {
   1.598 +                if (s.endsWith(".java") ) {
   1.599 +                    File f = new File(s);
   1.600 +                    if (!f.exists()) {
   1.601 +                        helper.error("err.file.not.found", f);
   1.602 +                        return true;
   1.603 +                    }
   1.604 +                    if (!f.isFile()) {
   1.605 +                        helper.error("err.file.not.file", f);
   1.606 +                        return true;
   1.607 +                    }
   1.608 +                    helper.addFile(f);
   1.609 +                }
   1.610 +                else
   1.611 +                    helper.addClassName(s);
   1.612 +                return false;
   1.613 +            }
   1.614 +        },
   1.615 +    };
   1.616 +    }
   1.617 +
   1.618 +}

mercurial