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

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/main/OptionHelper.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,117 @@
     1.4 +/*
     1.5 + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. 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.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.javac.main;
    1.30 +
    1.31 +import com.sun.tools.javac.util.Log;
    1.32 +import com.sun.tools.javac.util.Log.PrefixKind;
    1.33 +import java.io.File;
    1.34 +
    1.35 +/**
    1.36 + * Helper object to be used by {@link Option#process}, providing access to
    1.37 + * the compilation environment.
    1.38 + *
    1.39 + * <p><b>This is NOT part of any supported API.
    1.40 + * If you write code that depends on this, you do so at your own
    1.41 + * risk.  This code and its internal interfaces are subject to change
    1.42 + * or deletion without notice.</b></p>
    1.43 + */
    1.44 +
    1.45 +public abstract class OptionHelper {
    1.46 +
    1.47 +    /** Get the current value of an option. */
    1.48 +    public abstract String get(Option option);
    1.49 +
    1.50 +    /** Set the value of an option. */
    1.51 +    public abstract void put(String name, String value);
    1.52 +
    1.53 +    /** Remove any prior value for an option. */
    1.54 +    public abstract void remove(String name);
    1.55 +
    1.56 +    /** Get access to the Log for the compilation. */
    1.57 +    public abstract Log getLog();
    1.58 +
    1.59 +    /** Get the name of the tool, such as "javac", to be used in info like -help. */
    1.60 +    public abstract String getOwnName();
    1.61 +
    1.62 +    /** Report an error. */
    1.63 +    abstract void error(String key, Object... args);
    1.64 +
    1.65 +    /** Record a file to be compiled. */
    1.66 +    abstract void addFile(File f);
    1.67 +
    1.68 +    /** Record the name of a class for annotation processing. */
    1.69 +    abstract void addClassName(String s);
    1.70 +
    1.71 +    /** An implementation of OptionHelper that mostly throws exceptions. */
    1.72 +    public static class GrumpyHelper extends OptionHelper {
    1.73 +        private final Log log;
    1.74 +
    1.75 +        public GrumpyHelper(Log log) {
    1.76 +            this.log = log;
    1.77 +        }
    1.78 +
    1.79 +        @Override
    1.80 +        public Log getLog() {
    1.81 +            return log;
    1.82 +        }
    1.83 +
    1.84 +        @Override
    1.85 +        public String getOwnName() {
    1.86 +            throw new IllegalStateException();
    1.87 +        }
    1.88 +
    1.89 +        @Override
    1.90 +        public String get(Option option) {
    1.91 +            throw new IllegalArgumentException();
    1.92 +        }
    1.93 +
    1.94 +        @Override
    1.95 +        public void put(String name, String value) {
    1.96 +            throw new IllegalArgumentException();
    1.97 +        }
    1.98 +
    1.99 +        @Override
   1.100 +        public void remove(String name) {
   1.101 +            throw new IllegalArgumentException();
   1.102 +        }
   1.103 +
   1.104 +        @Override
   1.105 +        void error(String key, Object... args) {
   1.106 +            throw new IllegalArgumentException(log.localize(PrefixKind.JAVAC, key, args));
   1.107 +        }
   1.108 +
   1.109 +        @Override
   1.110 +        public void addFile(File f) {
   1.111 +            throw new IllegalArgumentException(f.getPath());
   1.112 +        }
   1.113 +
   1.114 +        @Override
   1.115 +        public void addClassName(String s) {
   1.116 +            throw new IllegalArgumentException(s);
   1.117 +        }
   1.118 +    }
   1.119 +
   1.120 +}

mercurial