duke@1: /* ohair@798: * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.javac.util; duke@1: jjg@700: import java.util.*; duke@1: import com.sun.tools.javac.main.OptionName; jjg@700: import static com.sun.tools.javac.main.OptionName.*; duke@1: duke@1: /** A table of all command-line options. duke@1: * If an option has an argument, the option name is mapped to the argument. duke@1: * If a set option has no argument, it is mapped to itself. duke@1: * jjg@581: *

This is NOT part of any supported API. jjg@581: * If you write code that depends on this, you do so at your own risk. duke@1: * This code and its internal interfaces are subject to change or duke@1: * deletion without notice. duke@1: */ duke@1: public class Options { duke@1: private static final long serialVersionUID = 0; duke@1: duke@1: /** The context key for the options. */ duke@1: public static final Context.Key optionsKey = duke@1: new Context.Key(); duke@1: duke@1: private LinkedHashMap values; duke@1: duke@1: /** Get the Options instance for this context. */ duke@1: public static Options instance(Context context) { duke@1: Options instance = context.get(optionsKey); duke@1: if (instance == null) duke@1: instance = new Options(context); duke@1: return instance; duke@1: } duke@1: duke@1: protected Options(Context context) { duke@1: // DEBUGGING -- Use LinkedHashMap for reproducability duke@1: values = new LinkedHashMap(); duke@1: context.put(optionsKey, this); duke@1: } duke@1: jjg@700: /** jjg@700: * Get the value for an undocumented option. jjg@700: */ duke@1: public String get(String name) { duke@1: return values.get(name); duke@1: } duke@1: jjg@700: /** jjg@700: * Get the value for an option. jjg@700: */ duke@1: public String get(OptionName name) { duke@1: return values.get(name.optionName); duke@1: } duke@1: jjg@700: /** jjg@700: * Check if the value for an undocumented option has been set. jjg@700: */ jjg@700: public boolean isSet(String name) { jjg@700: return (values.get(name) != null); jjg@700: } jjg@700: jjg@700: /** jjg@700: * Check if the value for an option has been set. jjg@700: */ jjg@700: public boolean isSet(OptionName name) { jjg@700: return (values.get(name.optionName) != null); jjg@700: } jjg@700: jjg@700: /** jjg@700: * Check if the value for a choice option has been set to a specific value. jjg@700: */ jjg@700: public boolean isSet(OptionName name, String value) { jjg@700: return (values.get(name.optionName + value) != null); jjg@700: } jjg@700: jjg@700: /** jjg@700: * Check if the value for an undocumented option has not been set. jjg@700: */ jjg@700: public boolean isUnset(String name) { jjg@700: return (values.get(name) == null); jjg@700: } jjg@700: jjg@700: /** jjg@700: * Check if the value for an option has not been set. jjg@700: */ jjg@700: public boolean isUnset(OptionName name) { jjg@700: return (values.get(name.optionName) == null); jjg@700: } jjg@700: jjg@700: /** jjg@700: * Check if the value for a choice option has not been set to a specific value. jjg@700: */ jjg@700: public boolean isUnset(OptionName name, String value) { jjg@700: return (values.get(name.optionName + value) == null); jjg@700: } jjg@700: duke@1: public void put(String name, String value) { duke@1: values.put(name, value); duke@1: } duke@1: duke@1: public void put(OptionName name, String value) { duke@1: values.put(name.optionName, value); duke@1: } duke@1: duke@1: public void putAll(Options options) { duke@1: values.putAll(options.values); duke@1: } duke@1: duke@1: public void remove(String name) { duke@1: values.remove(name); duke@1: } duke@1: duke@1: public Set keySet() { duke@1: return values.keySet(); duke@1: } duke@1: duke@1: public int size() { duke@1: return values.size(); duke@1: } duke@1: duke@1: /** Check for a lint suboption. */ duke@1: public boolean lint(String s) { duke@1: // return true if either the specific option is enabled, or duke@1: // they are all enabled without the specific one being duke@1: // disabled duke@1: return jjg@700: isSet(XLINT_CUSTOM, s) || jjg@700: (isSet(XLINT) || isSet(XLINT_CUSTOM, "all")) && jjg@700: isUnset(XLINT_CUSTOM, "-" + s); duke@1: } duke@1: }