src/share/classes/com/sun/tools/javac/util/Options.java

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 554
9d9f26857129
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 2001-2006 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    26 package com.sun.tools.javac.util;
    28 import com.sun.tools.javac.main.OptionName;
    29 import java.util.*;
    31 /** A table of all command-line options.
    32  *  If an option has an argument, the option name is mapped to the argument.
    33  *  If a set option has no argument, it is mapped to itself.
    34  *
    35  *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
    36  *  you write code that depends on this, you do so at your own risk.
    37  *  This code and its internal interfaces are subject to change or
    38  *  deletion without notice.</b>
    39  */
    40 public class Options {
    41     private static final long serialVersionUID = 0;
    43     /** The context key for the options. */
    44     public static final Context.Key<Options> optionsKey =
    45         new Context.Key<Options>();
    47     private LinkedHashMap<String,String> values;
    49     /** Get the Options instance for this context. */
    50     public static Options instance(Context context) {
    51         Options instance = context.get(optionsKey);
    52         if (instance == null)
    53             instance = new Options(context);
    54         return instance;
    55     }
    57     protected Options(Context context) {
    58 // DEBUGGING -- Use LinkedHashMap for reproducability
    59         values = new LinkedHashMap<String,String>();
    60         context.put(optionsKey, this);
    61     }
    63     public String get(String name) {
    64         return values.get(name);
    65     }
    67     public String get(OptionName name) {
    68         return values.get(name.optionName);
    69     }
    71     public void put(String name, String value) {
    72         values.put(name, value);
    73     }
    75     public void put(OptionName name, String value) {
    76         values.put(name.optionName, value);
    77     }
    79     public void putAll(Options options) {
    80         values.putAll(options.values);
    81     }
    83     public void remove(String name) {
    84         values.remove(name);
    85     }
    87     public Set<String> keySet() {
    88         return values.keySet();
    89     }
    91     public int size() {
    92         return values.size();
    93     }
    95     static final String LINT = "-Xlint";
    97     /** Check for a lint suboption. */
    98     public boolean lint(String s) {
    99         // return true if either the specific option is enabled, or
   100         // they are all enabled without the specific one being
   101         // disabled
   102         return
   103             get(LINT + ":" + s)!=null ||
   104             (get(LINT)!=null || get(LINT + ":all")!=null) &&
   105                 get(LINT+":-"+s)==null;
   106     }
   107 }

mercurial