author | jjg |
Thu, 10 Jun 2010 16:08:01 -0700 | |
changeset 5847 | 1908176fd6e3 |
parent 5520 | 86e4b9a9da40 |
child 6721 | d92073844278 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2001, 2006, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.util; |
|
27 |
||
28 |
import com.sun.tools.javac.main.OptionName; |
|
29 |
import java.util.*; |
|
30 |
||
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 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
35 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
36 |
* If you write code that depends on this, you do so at your own risk. |
10 | 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; |
|
42 |
||
43 |
/** The context key for the options. */ |
|
44 |
public static final Context.Key<Options> optionsKey = |
|
45 |
new Context.Key<Options>(); |
|
46 |
||
47 |
private LinkedHashMap<String,String> values; |
|
48 |
||
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 |
} |
|
56 |
||
57 |
protected Options(Context context) { |
|
58 |
// DEBUGGING -- Use LinkedHashMap for reproducability |
|
59 |
values = new LinkedHashMap<String,String>(); |
|
60 |
context.put(optionsKey, this); |
|
61 |
} |
|
62 |
||
63 |
public String get(String name) { |
|
64 |
return values.get(name); |
|
65 |
} |
|
66 |
||
67 |
public String get(OptionName name) { |
|
68 |
return values.get(name.optionName); |
|
69 |
} |
|
70 |
||
71 |
public void put(String name, String value) { |
|
72 |
values.put(name, value); |
|
73 |
} |
|
74 |
||
75 |
public void put(OptionName name, String value) { |
|
76 |
values.put(name.optionName, value); |
|
77 |
} |
|
78 |
||
79 |
public void putAll(Options options) { |
|
80 |
values.putAll(options.values); |
|
81 |
} |
|
82 |
||
83 |
public void remove(String name) { |
|
84 |
values.remove(name); |
|
85 |
} |
|
86 |
||
87 |
public Set<String> keySet() { |
|
88 |
return values.keySet(); |
|
89 |
} |
|
90 |
||
91 |
public int size() { |
|
92 |
return values.size(); |
|
93 |
} |
|
94 |
||
95 |
static final String LINT = "-Xlint"; |
|
96 |
||
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 |
} |