|
1 /* |
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
|
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 |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
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 * |
|
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. |
|
24 */ |
|
25 |
|
26 package com.sun.tools.javadoc; |
|
27 |
|
28 import com.sun.tools.javac.code.Flags; |
|
29 import com.sun.tools.javac.util.ListBuffer; |
|
30 import com.sun.tools.javac.util.Options; |
|
31 import java.util.StringTokenizer; |
|
32 |
|
33 |
|
34 /** |
|
35 * javadoc tool options. |
|
36 * |
|
37 * <p><b>This is NOT part of any supported API. |
|
38 * If you write code that depends on this, you do so at your own risk. |
|
39 * This code and its internal interfaces are subject to change or |
|
40 * deletion without notice.</b> |
|
41 */ |
|
42 public enum ToolOption { |
|
43 // ----- options for underlying compiler ----- |
|
44 |
|
45 BOOTCLASSPATH("-bootclasspath", true) { |
|
46 @Override |
|
47 public void process(Helper helper, String arg) { |
|
48 helper.setCompilerOpt(opt, arg); |
|
49 } |
|
50 }, |
|
51 |
|
52 CLASSPATH("-classpath", true) { |
|
53 @Override |
|
54 public void process(Helper helper, String arg) { |
|
55 helper.setCompilerOpt(opt, arg); |
|
56 } |
|
57 }, |
|
58 |
|
59 CP("-cp", true) { |
|
60 @Override |
|
61 public void process(Helper helper, String arg) { |
|
62 helper.setCompilerOpt(opt, arg); |
|
63 } |
|
64 }, |
|
65 |
|
66 EXTDIRS("-extdirs", true) { |
|
67 @Override |
|
68 public void process(Helper helper, String arg) { |
|
69 helper.setCompilerOpt(opt, arg); |
|
70 } |
|
71 }, |
|
72 |
|
73 SOURCEPATH("-sourcepath", true) { |
|
74 @Override |
|
75 public void process(Helper helper, String arg) { |
|
76 helper.setCompilerOpt(opt, arg); |
|
77 } |
|
78 }, |
|
79 |
|
80 SYSCLASSPATH("-sysclasspath", true) { |
|
81 @Override |
|
82 public void process(Helper helper, String arg) { |
|
83 helper.setCompilerOpt("-bootclasspath", arg); |
|
84 } |
|
85 }, |
|
86 |
|
87 ENCODING("-encoding", true) { |
|
88 @Override |
|
89 public void process(Helper helper, String arg) { |
|
90 helper.encoding = arg; |
|
91 helper.setCompilerOpt(opt, arg); |
|
92 } |
|
93 }, |
|
94 |
|
95 SOURCE("-source", true) { |
|
96 @Override |
|
97 public void process(Helper helper, String arg) { |
|
98 helper.setCompilerOpt(opt, arg); |
|
99 } |
|
100 }, |
|
101 |
|
102 XMAXERRS("-Xmaxerrs", true) { |
|
103 @Override |
|
104 public void process(Helper helper, String arg) { |
|
105 helper.setCompilerOpt(opt, arg); |
|
106 } |
|
107 }, |
|
108 |
|
109 XMAXWARNS("-Xmaxwarns", true) { |
|
110 @Override |
|
111 public void process(Helper helper, String arg) { |
|
112 helper.setCompilerOpt(opt, arg); |
|
113 } |
|
114 }, |
|
115 |
|
116 // ----- doclet options ----- |
|
117 |
|
118 DOCLET("-doclet", true), // handled in setDocletInvoker |
|
119 |
|
120 DOCLETPATH("-docletpath", true), // handled in setDocletInvoker |
|
121 |
|
122 // ----- selection options ----- |
|
123 |
|
124 SUBPACKAGES("-subpackages", true) { |
|
125 @Override |
|
126 public void process(Helper helper, String arg) { |
|
127 helper.addToList(helper.subPackages, arg); |
|
128 } |
|
129 }, |
|
130 |
|
131 EXCLUDE("-exclude", true) { |
|
132 @Override |
|
133 public void process(Helper helper, String arg) { |
|
134 helper.addToList(helper.excludedPackages, arg); |
|
135 } |
|
136 }, |
|
137 |
|
138 // ----- filtering options ----- |
|
139 |
|
140 PACKAGE("-package") { |
|
141 @Override |
|
142 public void process(Helper helper) { |
|
143 helper.setFilter( |
|
144 Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE); |
|
145 } |
|
146 }, |
|
147 |
|
148 PRIVATE("-private") { |
|
149 @Override |
|
150 public void process(Helper helper) { |
|
151 helper.setFilter(ModifierFilter.ALL_ACCESS); |
|
152 } |
|
153 }, |
|
154 |
|
155 PROTECTED("-protected") { |
|
156 @Override |
|
157 public void process(Helper helper) { |
|
158 helper.setFilter(Flags.PUBLIC | Flags.PROTECTED); |
|
159 } |
|
160 }, |
|
161 |
|
162 PUBLIC("-public") { |
|
163 @Override |
|
164 public void process(Helper helper) { |
|
165 helper.setFilter(Flags.PUBLIC); |
|
166 } |
|
167 }, |
|
168 |
|
169 // ----- output control options ----- |
|
170 |
|
171 PROMPT("-prompt") { |
|
172 @Override |
|
173 public void process(Helper helper) { |
|
174 helper.compOpts.put("-prompt", "-prompt"); |
|
175 helper.promptOnError = true; |
|
176 } |
|
177 }, |
|
178 |
|
179 QUIET("-quiet") { |
|
180 @Override |
|
181 public void process(Helper helper) { |
|
182 helper.quiet = true; |
|
183 } |
|
184 }, |
|
185 |
|
186 VERBOSE("-verbose") { |
|
187 @Override |
|
188 public void process(Helper helper) { |
|
189 helper.compOpts.put("-verbose", ""); |
|
190 } |
|
191 }, |
|
192 |
|
193 XWERROR("-Xwerror") { |
|
194 @Override |
|
195 public void process(Helper helper) { |
|
196 helper.rejectWarnings = true; |
|
197 |
|
198 } |
|
199 }, |
|
200 |
|
201 // ----- other options ----- |
|
202 |
|
203 BREAKITERATOR("-breakiterator") { |
|
204 @Override |
|
205 public void process(Helper helper) { |
|
206 helper.breakiterator = true; |
|
207 } |
|
208 }, |
|
209 |
|
210 LOCALE("-locale", true) { |
|
211 @Override |
|
212 public void process(Helper helper, String arg) { |
|
213 helper.docLocale = arg; |
|
214 } |
|
215 }, |
|
216 |
|
217 OVERVIEW("-overview", true), |
|
218 |
|
219 XCLASSES("-Xclasses") { |
|
220 @Override |
|
221 public void process(Helper helper) { |
|
222 helper.docClasses = true; |
|
223 |
|
224 } |
|
225 }, |
|
226 |
|
227 // ----- help options ----- |
|
228 |
|
229 HELP("-help") { |
|
230 @Override |
|
231 public void process(Helper helper) { |
|
232 helper.usage(); |
|
233 } |
|
234 }, |
|
235 |
|
236 X("-X") { |
|
237 @Override |
|
238 public void process(Helper helper) { |
|
239 helper.Xusage(); |
|
240 } |
|
241 }; |
|
242 |
|
243 public final String opt; |
|
244 public final boolean hasArg; |
|
245 |
|
246 ToolOption(String opt) { |
|
247 this(opt, false); |
|
248 } |
|
249 |
|
250 ToolOption(String opt, boolean hasArg) { |
|
251 this.opt = opt; |
|
252 this.hasArg = hasArg; |
|
253 } |
|
254 |
|
255 void process(Helper helper, String arg) { } |
|
256 |
|
257 void process(Helper helper) { } |
|
258 |
|
259 static ToolOption get(String name) { |
|
260 for (ToolOption o: values()) { |
|
261 if (name.equals(o.opt)) |
|
262 return o; |
|
263 } |
|
264 return null; |
|
265 } |
|
266 |
|
267 static abstract class Helper { |
|
268 /** List of decoded options. */ |
|
269 final ListBuffer<String[]> options = new ListBuffer<String[]>(); |
|
270 |
|
271 /** Selected packages, from -subpackages. */ |
|
272 final ListBuffer<String> subPackages = new ListBuffer<String>(); |
|
273 |
|
274 /** Excluded packages, from -exclude. */ |
|
275 final ListBuffer<String> excludedPackages = new ListBuffer<String>(); |
|
276 |
|
277 /** javac options, set by various options. */ |
|
278 Options compOpts; // = Options.instance(context) |
|
279 |
|
280 /* Encoding for javac, and files written? set by -encoding. */ |
|
281 String encoding = null; |
|
282 |
|
283 /** Set by -breakiterator. */ |
|
284 boolean breakiterator = false; |
|
285 |
|
286 /** Set by -quiet. */ |
|
287 boolean quiet = false; |
|
288 |
|
289 /** Set by -Xclasses. */ |
|
290 boolean docClasses = false; |
|
291 |
|
292 /** Set by -Xwerror. */ |
|
293 boolean rejectWarnings = false; |
|
294 |
|
295 /** Set by -prompt. */ |
|
296 boolean promptOnError; |
|
297 |
|
298 /** Set by -locale. */ |
|
299 String docLocale = ""; |
|
300 |
|
301 /** Set by -public, private, -protected, -package. */ |
|
302 ModifierFilter showAccess = null; |
|
303 |
|
304 abstract void usage(); |
|
305 abstract void Xusage(); |
|
306 |
|
307 abstract void usageError(String msg, Object... args); |
|
308 |
|
309 protected void addToList(ListBuffer<String> list, String str){ |
|
310 StringTokenizer st = new StringTokenizer(str, ":"); |
|
311 String current; |
|
312 while(st.hasMoreTokens()){ |
|
313 current = st.nextToken(); |
|
314 list.append(current); |
|
315 } |
|
316 } |
|
317 |
|
318 protected void setFilter(long filterBits) { |
|
319 if (showAccess != null) { |
|
320 usageError("main.incompatible.access.flags"); |
|
321 } |
|
322 showAccess = new ModifierFilter(filterBits); |
|
323 } |
|
324 |
|
325 private void setCompilerOpt(String opt, String arg) { |
|
326 if (compOpts.get(opt) != null) { |
|
327 usageError("main.option.already.seen", opt); |
|
328 } |
|
329 compOpts.put(opt, arg); |
|
330 } |
|
331 } |
|
332 } |