langtools/src/share/classes/com/sun/tools/javac/main/JavacOption.java
author jjg
Thu, 10 Jun 2010 16:08:01 -0700
changeset 5847 1908176fd6e3
parent 5520 86e4b9a9da40
child 11053 48713f779b1d
permissions -rw-r--r--
6944312: Potential rebranding issues in openjdk/langtools repository sources Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4412
diff changeset
     2
 * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4412
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4412
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4412
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4412
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4412
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.main;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
    28
import java.io.PrintWriter;
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
    29
import java.util.LinkedHashMap;
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
    30
import java.util.Map;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.util.Log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.Options;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * TODO: describe com.sun.tools.javac.main.JavacOption
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    37
 * <p><b>This is NOT part of any supported API.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * If you write code that depends on this, you do so at your own
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * risk.  This code and its internal interfaces are subject to change
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * or deletion without notice.</b></p>
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
public interface JavacOption {
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    OptionKind getKind();
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    46
    /** Does this option take a (separate) operand?
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    47
     *  @return true if this option takes a separate operand
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    48
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    boolean hasArg();
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    /** Does argument string match option pattern?
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    52
     *  @param arg   the command line argument string
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    53
     *  @return true if {@code arg} matches this option
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    boolean matches(String arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    57
    /** Process an option with an argument.
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    58
     *  @param options the accumulated set of analyzed options
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    59
     *  @param option  the option to be processed
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    60
     *  @param arg     the arg for the option to be processed
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    61
     *  @return true if an error was detected
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    boolean process(Options options, String option, String arg);
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    65
    /** Process the option with no argument.
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    66
     *  @param options the accumulated set of analyzed options
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    67
     *  @param option  the option to be processed
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    68
     *  @return true if an error was detected
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    boolean process(Options options, String option);
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    OptionName getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    enum OptionKind {
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        NORMAL,
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        EXTENDED,
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        HIDDEN,
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    80
    enum ChoiceKind {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    81
        ONEOF,
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    82
        ANYOF
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    83
    }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
    84
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /** This class represents an option recognized by the main program
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    static class Option implements JavacOption {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        /** Option string.
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        OptionName name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        /** Documentation key for arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        String argsNameKey;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        /** Documentation key for description.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        String descrKey;
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        /** Suffix option (-foo=bar or -foo:bar)
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        boolean hasSuffix;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   105
        /** The kind of choices for this option, if any.
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   106
         */
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   107
        ChoiceKind choiceKind;
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   108
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   109
        /** The choices for this option, if any, and whether or not the choices
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   110
         *  are hidden
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   111
         */
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   112
        Map<String,Boolean> choices;
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   113
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        Option(OptionName name, String argsNameKey, String descrKey) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            this.argsNameKey = argsNameKey;
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
            this.descrKey = descrKey;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
            char lastChar = name.optionName.charAt(name.optionName.length()-1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            hasSuffix = lastChar == ':' || lastChar == '=';
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        }
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   121
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        Option(OptionName name, String descrKey) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
            this(name, null, descrKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   126
        Option(OptionName name, String descrKey, ChoiceKind choiceKind, String... choices) {
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   127
            this(name, descrKey, choiceKind, createChoices(choices));
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   128
        }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   129
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   130
        private static Map<String,Boolean> createChoices(String... choices) {
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   131
            Map<String,Boolean> map = new LinkedHashMap<String,Boolean>();
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   132
            for (String c: choices)
4412
0cc84d38259d 6900511: javac command line help broken
jjg
parents: 3661
diff changeset
   133
                map.put(c, false);
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   134
            return map;
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   135
        }
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   136
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   137
        Option(OptionName name, String descrKey, ChoiceKind choiceKind,
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   138
                Map<String,Boolean> choices) {
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   139
            this(name, null, descrKey);
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   140
            if (choiceKind == null || choices == null)
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   141
                throw new NullPointerException();
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   142
            this.choiceKind = choiceKind;
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   143
            this.choices = choices;
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   144
        }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   145
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   146
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
            return name.optionName;
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        public boolean hasArg() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
            return argsNameKey != null && !hasSuffix;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   155
        public boolean matches(String option) {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   156
            if (!hasSuffix)
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   157
                return option.equals(name.optionName);
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   158
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   159
            if (!option.startsWith(name.optionName))
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   160
                return false;
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   161
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   162
            if (choices != null) {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   163
                String arg = option.substring(name.optionName.length());
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   164
                if (choiceKind == ChoiceKind.ONEOF)
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   165
                    return choices.keySet().contains(arg);
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   166
                else {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   167
                    for (String a: arg.split(",+")) {
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   168
                        if (!choices.keySet().contains(a))
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   169
                            return false;
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   170
                    }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   171
                }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   172
            }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   173
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   174
            return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        /** Print a line of documentation describing this option, if standard.
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   178
         * @param out the stream to which to write the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        void help(PrintWriter out) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            String s = "  " + helpSynopsis();
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            out.print(s);
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   183
            for (int j = Math.min(s.length(), 28); j < 29; j++) out.print(" ");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
            Log.printLines(out, Main.getLocalizedString(descrKey));
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        }
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   186
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        String helpSynopsis() {
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   188
            StringBuilder sb = new StringBuilder();
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   189
            sb.append(name);
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   190
            if (argsNameKey == null) {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   191
                if (choices != null) {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   192
                    String sep = "{";
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   193
                    for (Map.Entry<String,Boolean> e: choices.entrySet()) {
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   194
                        if (!e.getValue()) {
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   195
                            sb.append(sep);
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   196
                            sb.append(e.getKey());
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   197
                            sep = ",";
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   198
                        }
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   199
                    }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   200
                    sb.append("}");
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   201
                }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   202
            } else {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   203
                if (!hasSuffix)
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   204
                    sb.append(" ");
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   205
                sb.append(Main.getLocalizedString(argsNameKey));
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   206
            }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   207
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   208
            return sb.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        /** Print a line of documentation describing this option, if non-standard.
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   212
         *  @param out the stream to which to write the documentation
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        void xhelp(PrintWriter out) {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        /** Process the option (with arg). Return true if error detected.
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        public boolean process(Options options, String option, String arg) {
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   219
            if (options != null) {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   220
                if (choices != null) {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   221
                    if (choiceKind == ChoiceKind.ONEOF) {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   222
                        // some clients like to see just one of option+choice set
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   223
                        for (String s: choices.keySet())
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   224
                            options.remove(option + s);
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   225
                        String opt = option + arg;
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   226
                        options.put(opt, opt);
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   227
                        // some clients like to see option (without trailing ":")
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   228
                        // set to arg
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   229
                        String nm = option.substring(0, option.length() - 1);
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   230
                        options.put(nm, arg);
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   231
                    } else {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   232
                        // set option+word for each word in arg
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   233
                        for (String a: arg.split(",+")) {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   234
                            String opt = option + a;
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   235
                            options.put(opt, opt);
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   236
                        }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   237
                    }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   238
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                options.put(option, arg);
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   240
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        /** Process the option (without arg). Return true if error detected.
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        public boolean process(Options options, String option) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            if (hasSuffix)
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                return process(options, name.optionName, option.substring(name.optionName.length()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
                return process(options, option, option);
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        public OptionKind getKind() { return OptionKind.NORMAL; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        public OptionName getName() { return name; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    /** A nonstandard or extended (-X) option
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    static class XOption extends Option {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        XOption(OptionName name, String argsNameKey, String descrKey) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            super(name, argsNameKey, descrKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
        XOption(OptionName name, String descrKey) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
            this(name, null, descrKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        }
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   267
        XOption(OptionName name, String descrKey, ChoiceKind kind, String... choices) {
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   268
            super(name, descrKey, kind, choices);
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   269
        }
3661
104c425e96aa 6873845: refine access to symbol file
jjg
parents: 735
diff changeset
   270
        XOption(OptionName name, String descrKey, ChoiceKind kind, Map<String,Boolean> choices) {
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   271
            super(name, descrKey, kind, choices);
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   272
        }
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   273
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        void help(PrintWriter out) {}
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   275
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        void xhelp(PrintWriter out) { super.help(out); }
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   277
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        public OptionKind getKind() { return OptionKind.EXTENDED; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    /** A hidden (implementor) option
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    static class HiddenOption extends Option {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        HiddenOption(OptionName name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
            super(name, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        HiddenOption(OptionName name, String argsNameKey) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
            super(name, argsNameKey, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        }
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   290
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        void help(PrintWriter out) {}
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   292
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        void xhelp(PrintWriter out) {}
168
25697c18650b 6307187: clean up code for -Xlint:options
jjg
parents: 10
diff changeset
   294
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        public OptionKind getKind() { return OptionKind.HIDDEN; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
}