001 /*
002 * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package com.sun.tools.javac.util;
027
028 import com.sun.tools.javac.main.OptionName;
029 import java.util.*;
030
031 /** A table of all command-line options.
032 * If an option has an argument, the option name is mapped to the argument.
033 * If a set option has no argument, it is mapped to itself.
034 *
035 * <p><b>This is NOT part of any API supported by Sun Microsystems. If
036 * you write code that depends on this, you do so at your own risk.
037 * This code and its internal interfaces are subject to change or
038 * deletion without notice.</b>
039 */
040 public class Options {
041 private static final long serialVersionUID = 0;
042
043 /** The context key for the options. */
044 public static final Context.Key<Options> optionsKey =
045 new Context.Key<Options>();
046
047 private LinkedHashMap<String,String> values;
048
049 /** Get the Options instance for this context. */
050 public static Options instance(Context context) {
051 Options instance = context.get(optionsKey);
052 if (instance == null)
053 instance = new Options(context);
054 return instance;
055 }
056
057 protected Options(Context context) {
058 // DEBUGGING -- Use LinkedHashMap for reproducability
059 values = new LinkedHashMap<String,String>();
060 context.put(optionsKey, this);
061 }
062
063 public String get(String name) {
064 return values.get(name);
065 }
066
067 public String get(OptionName name) {
068 return values.get(name.optionName);
069 }
070
071 public void put(String name, String value) {
072 values.put(name, value);
073 }
074
075 public void put(OptionName name, String value) {
076 values.put(name.optionName, value);
077 }
078
079 public void putAll(Options options) {
080 values.putAll(options.values);
081 }
082
083 public void remove(String name) {
084 values.remove(name);
085 }
086
087 public Set<String> keySet() {
088 return values.keySet();
089 }
090
091 public int size() {
092 return values.size();
093 }
094
095 static final String LINT = "-Xlint";
096
097 /** Check for a lint suboption. */
098 public boolean lint(String s) {
099 // 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 }