author | jjg |
Thu, 20 Oct 2016 13:44:51 -0700 | |
changeset 41637 | 7b24b4c32ee6 |
parent 40772 | de87954b8f20 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
25874
diff
changeset
|
2 |
* Copyright (c) 2001, 2016, 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 |
||
6721 | 28 |
import java.util.*; |
40772
de87954b8f20
8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents:
40308
diff
changeset
|
29 |
|
11314 | 30 |
import com.sun.tools.javac.main.Option; |
31 |
import static com.sun.tools.javac.main.Option.*; |
|
10 | 32 |
|
33 |
/** A table of all command-line options. |
|
34 |
* If an option has an argument, the option name is mapped to the argument. |
|
35 |
* If a set option has no argument, it is mapped to itself. |
|
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. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
38 |
* If you write code that depends on this, you do so at your own risk. |
10 | 39 |
* This code and its internal interfaces are subject to change or |
40 |
* deletion without notice.</b> |
|
41 |
*/ |
|
42 |
public class Options { |
|
43 |
private static final long serialVersionUID = 0; |
|
44 |
||
45 |
/** The context key for the options. */ |
|
22163 | 46 |
public static final Context.Key<Options> optionsKey = new Context.Key<>(); |
10 | 47 |
|
48 |
private LinkedHashMap<String,String> values; |
|
49 |
||
50 |
/** Get the Options instance for this context. */ |
|
51 |
public static Options instance(Context context) { |
|
52 |
Options instance = context.get(optionsKey); |
|
53 |
if (instance == null) |
|
54 |
instance = new Options(context); |
|
55 |
return instance; |
|
56 |
} |
|
57 |
||
58 |
protected Options(Context context) { |
|
59 |
// DEBUGGING -- Use LinkedHashMap for reproducability |
|
22163 | 60 |
values = new LinkedHashMap<>(); |
10 | 61 |
context.put(optionsKey, this); |
62 |
} |
|
63 |
||
6721 | 64 |
/** |
65 |
* Get the value for an undocumented option. |
|
66 |
*/ |
|
10 | 67 |
public String get(String name) { |
68 |
return values.get(name); |
|
69 |
} |
|
70 |
||
6721 | 71 |
/** |
72 |
* Get the value for an option. |
|
73 |
*/ |
|
11314 | 74 |
public String get(Option option) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
25874
diff
changeset
|
75 |
return values.get(option.primaryName); |
10 | 76 |
} |
77 |
||
6721 | 78 |
/** |
8837 | 79 |
* Get the boolean value for an option, patterned after Boolean.getBoolean, |
80 |
* essentially will return true, iff the value exists and is set to "true". |
|
81 |
*/ |
|
82 |
public boolean getBoolean(String name) { |
|
83 |
return getBoolean(name, false); |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
* Get the boolean with a default value if the option is not set. |
|
88 |
*/ |
|
89 |
public boolean getBoolean(String name, boolean defaultValue) { |
|
90 |
String value = get(name); |
|
91 |
return (value == null) ? defaultValue : Boolean.parseBoolean(value); |
|
92 |
} |
|
93 |
||
94 |
/** |
|
6721 | 95 |
* Check if the value for an undocumented option has been set. |
96 |
*/ |
|
97 |
public boolean isSet(String name) { |
|
98 |
return (values.get(name) != null); |
|
99 |
} |
|
100 |
||
101 |
/** |
|
102 |
* Check if the value for an option has been set. |
|
103 |
*/ |
|
11314 | 104 |
public boolean isSet(Option option) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
25874
diff
changeset
|
105 |
return (values.get(option.primaryName) != null); |
6721 | 106 |
} |
107 |
||
108 |
/** |
|
109 |
* Check if the value for a choice option has been set to a specific value. |
|
110 |
*/ |
|
11314 | 111 |
public boolean isSet(Option option, String value) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
25874
diff
changeset
|
112 |
return (values.get(option.primaryName + value) != null); |
6721 | 113 |
} |
114 |
||
41637 | 115 |
/** Check if the value for a lint option has been explicitly set, either with -Xlint:opt |
116 |
* or if all lint options have enabled and this one not disabled with -Xlint:-opt. |
|
117 |
*/ |
|
118 |
public boolean isLintSet(String s) { |
|
119 |
// return true if either the specific option is enabled, or |
|
120 |
// they are all enabled without the specific one being |
|
121 |
// disabled |
|
122 |
return |
|
123 |
isSet(XLINT_CUSTOM, s) || |
|
124 |
(isSet(XLINT) || isSet(XLINT_CUSTOM, "all")) && isUnset(XLINT_CUSTOM, "-" + s); |
|
125 |
} |
|
126 |
||
6721 | 127 |
/** |
128 |
* Check if the value for an undocumented option has not been set. |
|
129 |
*/ |
|
130 |
public boolean isUnset(String name) { |
|
131 |
return (values.get(name) == null); |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* Check if the value for an option has not been set. |
|
136 |
*/ |
|
11314 | 137 |
public boolean isUnset(Option option) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
25874
diff
changeset
|
138 |
return (values.get(option.primaryName) == null); |
6721 | 139 |
} |
140 |
||
141 |
/** |
|
142 |
* Check if the value for a choice option has not been set to a specific value. |
|
143 |
*/ |
|
11314 | 144 |
public boolean isUnset(Option option, String value) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
25874
diff
changeset
|
145 |
return (values.get(option.primaryName + value) == null); |
6721 | 146 |
} |
147 |
||
10 | 148 |
public void put(String name, String value) { |
149 |
values.put(name, value); |
|
150 |
} |
|
151 |
||
11314 | 152 |
public void put(Option option, String value) { |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
25874
diff
changeset
|
153 |
values.put(option.primaryName, value); |
10 | 154 |
} |
155 |
||
156 |
public void putAll(Options options) { |
|
157 |
values.putAll(options.values); |
|
158 |
} |
|
159 |
||
160 |
public void remove(String name) { |
|
161 |
values.remove(name); |
|
162 |
} |
|
163 |
||
164 |
public Set<String> keySet() { |
|
165 |
return values.keySet(); |
|
166 |
} |
|
167 |
||
168 |
public int size() { |
|
169 |
return values.size(); |
|
170 |
} |
|
171 |
||
11052 | 172 |
// light-weight notification mechanism |
173 |
||
174 |
private List<Runnable> listeners = List.nil(); |
|
175 |
||
176 |
public void addListener(Runnable listener) { |
|
177 |
listeners = listeners.prepend(listener); |
|
178 |
} |
|
179 |
||
180 |
public void notifyListeners() { |
|
181 |
for (Runnable r: listeners) |
|
182 |
r.run(); |
|
183 |
} |
|
10 | 184 |
} |