23 * have any questions. |
23 * have any questions. |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.javac.main; |
26 package com.sun.tools.javac.main; |
27 |
27 |
|
28 import java.io.PrintWriter; |
|
29 import java.util.LinkedHashMap; |
|
30 import java.util.Map; |
28 import com.sun.tools.javac.util.Log; |
31 import com.sun.tools.javac.util.Log; |
29 import com.sun.tools.javac.util.Options; |
32 import com.sun.tools.javac.util.Options; |
30 import java.io.PrintWriter; |
|
31 import java.util.Arrays; |
|
32 import java.util.Collection; |
|
33 |
33 |
34 /** |
34 /** |
35 * TODO: describe com.sun.tools.javac.main.JavacOption |
35 * TODO: describe com.sun.tools.javac.main.JavacOption |
36 * |
36 * |
37 * <p><b>This is NOT part of any API supported by Sun Microsystems. |
37 * <p><b>This is NOT part of any API supported by Sun Microsystems. |
104 |
104 |
105 /** The kind of choices for this option, if any. |
105 /** The kind of choices for this option, if any. |
106 */ |
106 */ |
107 ChoiceKind choiceKind; |
107 ChoiceKind choiceKind; |
108 |
108 |
109 /** The choices for this option, if any. |
109 /** The choices for this option, if any, and whether or not the choices |
110 */ |
110 * are hidden |
111 Collection<String> choices; |
111 */ |
|
112 Map<String,Boolean> choices; |
112 |
113 |
113 Option(OptionName name, String argsNameKey, String descrKey) { |
114 Option(OptionName name, String argsNameKey, String descrKey) { |
114 this.name = name; |
115 this.name = name; |
115 this.argsNameKey = argsNameKey; |
116 this.argsNameKey = argsNameKey; |
116 this.descrKey = descrKey; |
117 this.descrKey = descrKey; |
121 Option(OptionName name, String descrKey) { |
122 Option(OptionName name, String descrKey) { |
122 this(name, null, descrKey); |
123 this(name, null, descrKey); |
123 } |
124 } |
124 |
125 |
125 Option(OptionName name, String descrKey, ChoiceKind choiceKind, String... choices) { |
126 Option(OptionName name, String descrKey, ChoiceKind choiceKind, String... choices) { |
126 this(name, descrKey, choiceKind, Arrays.asList(choices)); |
127 this(name, descrKey, choiceKind, createChoices(choices)); |
127 } |
128 } |
128 |
129 |
129 Option(OptionName name, String descrKey, ChoiceKind choiceKind, Collection<String> choices) { |
130 private static Map<String,Boolean> createChoices(String... choices) { |
|
131 Map<String,Boolean> map = new LinkedHashMap<String,Boolean>(); |
|
132 for (String c: choices) |
|
133 map.put(c, true); |
|
134 return map; |
|
135 } |
|
136 |
|
137 Option(OptionName name, String descrKey, ChoiceKind choiceKind, |
|
138 Map<String,Boolean> choices) { |
130 this(name, null, descrKey); |
139 this(name, null, descrKey); |
131 if (choiceKind == null || choices == null) |
140 if (choiceKind == null || choices == null) |
132 throw new NullPointerException(); |
141 throw new NullPointerException(); |
133 this.choiceKind = choiceKind; |
142 this.choiceKind = choiceKind; |
134 this.choices = choices; |
143 this.choices = choices; |
151 return false; |
160 return false; |
152 |
161 |
153 if (choices != null) { |
162 if (choices != null) { |
154 String arg = option.substring(name.optionName.length()); |
163 String arg = option.substring(name.optionName.length()); |
155 if (choiceKind == ChoiceKind.ONEOF) |
164 if (choiceKind == ChoiceKind.ONEOF) |
156 return choices.contains(arg); |
165 return choices.keySet().contains(arg); |
157 else { |
166 else { |
158 for (String a: arg.split(",+")) { |
167 for (String a: arg.split(",+")) { |
159 if (!choices.contains(a)) |
168 if (!choices.keySet().contains(a)) |
160 return false; |
169 return false; |
161 } |
170 } |
162 } |
171 } |
163 } |
172 } |
164 |
173 |
207 public boolean process(Options options, String option, String arg) { |
218 public boolean process(Options options, String option, String arg) { |
208 if (options != null) { |
219 if (options != null) { |
209 if (choices != null) { |
220 if (choices != null) { |
210 if (choiceKind == ChoiceKind.ONEOF) { |
221 if (choiceKind == ChoiceKind.ONEOF) { |
211 // some clients like to see just one of option+choice set |
222 // some clients like to see just one of option+choice set |
212 for (String c: choices) |
223 for (String s: choices.keySet()) |
213 options.remove(option + c); |
224 options.remove(option + s); |
214 String opt = option + arg; |
225 String opt = option + arg; |
215 options.put(opt, opt); |
226 options.put(opt, opt); |
216 // some clients like to see option (without trailing ":") |
227 // some clients like to see option (without trailing ":") |
217 // set to arg |
228 // set to arg |
218 String nm = option.substring(0, option.length() - 1); |
229 String nm = option.substring(0, option.length() - 1); |
254 this(name, null, descrKey); |
265 this(name, null, descrKey); |
255 } |
266 } |
256 XOption(OptionName name, String descrKey, ChoiceKind kind, String... choices) { |
267 XOption(OptionName name, String descrKey, ChoiceKind kind, String... choices) { |
257 super(name, descrKey, kind, choices); |
268 super(name, descrKey, kind, choices); |
258 } |
269 } |
259 XOption(OptionName name, String descrKey, ChoiceKind kind, Collection<String> choices) { |
270 XOption(OptionName name, String descrKey, ChoiceKind kind, Map<String,Boolean> choices) { |
260 super(name, descrKey, kind, choices); |
271 super(name, descrKey, kind, choices); |
261 } |
272 } |
262 @Override |
273 @Override |
263 void help(PrintWriter out) {} |
274 void help(PrintWriter out) {} |
264 @Override |
275 @Override |