1 /*
2 * Copyright (c) 2012, 2014, 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 java.util.LinkedHashMap;
29 import java.util.Map;
30 import java.util.StringTokenizer;
31
32 import com.sun.tools.javac.code.Flags;
33 import com.sun.tools.javac.main.Option;
34 import com.sun.tools.javac.util.ListBuffer;
35 import com.sun.tools.javac.util.Options;
36
37
38 /**
39 * javadoc tool options.
40 *
41 * <p><b>This is NOT part of any supported API.
42 * If you write code that depends on this, you do so at your own risk.
43 * This code and its internal interfaces are subject to change or
44 * deletion without notice.</b>
45 */
46 public enum ToolOption {
47 // ----- options for underlying compiler -----
48
49 BOOTCLASSPATH("-bootclasspath", true) {
50 @Override
51 public void process(Helper helper, String arg) {
52 helper.setFileManagerOpt(Option.BOOTCLASSPATH, arg);
53 }
54 },
55
56 CLASSPATH("-classpath", true) {
57 @Override
134
135 SUBPACKAGES("-subpackages", true) {
136 @Override
137 public void process(Helper helper, String arg) {
138 helper.addToList(helper.subPackages, arg);
139 }
140 },
141
142 EXCLUDE("-exclude", true) {
143 @Override
144 public void process(Helper helper, String arg) {
145 helper.addToList(helper.excludedPackages, arg);
146 }
147 },
148
149 // ----- filtering options -----
150
151 PACKAGE("-package") {
152 @Override
153 public void process(Helper helper) {
154 helper.setFilter(
155 Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE);
156 }
157 },
158
159 PRIVATE("-private") {
160 @Override
161 public void process(Helper helper) {
162 helper.setFilter(ModifierFilter.ALL_ACCESS);
163 }
164 },
165
166 PROTECTED("-protected") {
167 @Override
168 public void process(Helper helper) {
169 helper.setFilter(Flags.PUBLIC | Flags.PROTECTED);
170 }
171 },
172
173 PUBLIC("-public") {
174 @Override
175 public void process(Helper helper) {
176 helper.setFilter(Flags.PUBLIC);
177 }
178 },
179
180 // ----- output control options -----
181
182 PROMPT("-prompt") {
183 @Override
184 public void process(Helper helper) {
185 helper.compOpts.put("-prompt", "-prompt");
186 helper.promptOnError = true;
187 }
188 },
189
190 QUIET("-quiet") {
191 @Override
192 public void process(Helper helper) {
193 helper.quiet = true;
194 }
195 },
196
208
209 }
210 },
211
212 // ----- other options -----
213
214 BREAKITERATOR("-breakiterator") {
215 @Override
216 public void process(Helper helper) {
217 helper.breakiterator = true;
218 }
219 },
220
221 LOCALE("-locale", true) {
222 @Override
223 public void process(Helper helper, String arg) {
224 helper.docLocale = arg;
225 }
226 },
227
228 OVERVIEW("-overview", true),
229
230 XCLASSES("-Xclasses") {
231 @Override
232 public void process(Helper helper) {
233 helper.docClasses = true;
234
235 }
236 },
237
238 // ----- help options -----
239
240 HELP("-help") {
241 @Override
242 public void process(Helper helper) {
243 helper.usage();
244 }
245 },
246
247 X("-X") {
248 @Override
260
261 ToolOption(String opt, boolean hasArg) {
262 this.opt = opt;
263 this.hasArg = hasArg;
264 }
265
266 void process(Helper helper, String arg) { }
267
268 void process(Helper helper) { }
269
270 static ToolOption get(String name) {
271 for (ToolOption o: values()) {
272 if (name.equals(o.opt))
273 return o;
274 }
275 return null;
276 }
277
278 static abstract class Helper {
279 /** List of decoded options. */
280 final ListBuffer<String[]> options = new ListBuffer<>();
281
282 /** Selected packages, from -subpackages. */
283 final ListBuffer<String> subPackages = new ListBuffer<>();
284
285 /** Excluded packages, from -exclude. */
286 final ListBuffer<String> excludedPackages = new ListBuffer<>();
287
288 // File manager options
289 final Map<Option, String> fileManagerOpts = new LinkedHashMap<>();
290
291 /** javac options, set by various options. */
292 Options compOpts; // = Options.instance(context)
293
294 /* Encoding for javac, and files written? set by -encoding. */
295 String encoding = null;
296
297 /** Set by -breakiterator. */
298 boolean breakiterator = false;
299
300 /** Set by -quiet. */
301 boolean quiet = false;
302
303 /** Set by -Xclasses. */
304 boolean docClasses = false;
305
306 /** Set by -Xwerror. */
307 boolean rejectWarnings = false;
308
309 /** Set by -prompt. */
310 boolean promptOnError;
311
312 /** Set by -locale. */
313 String docLocale = "";
314
315 /** Set by -public, private, -protected, -package. */
316 ModifierFilter showAccess = null;
317
318 abstract void usage();
319 abstract void Xusage();
320
321 abstract void usageError(String msg, Object... args);
322
323 void addToList(ListBuffer<String> list, String str){
324 StringTokenizer st = new StringTokenizer(str, ":");
325 String current;
326 while(st.hasMoreTokens()){
327 current = st.nextToken();
328 list.append(current);
329 }
330 }
331
332 void setFilter(long filterBits) {
333 if (showAccess != null) {
334 usageError("main.incompatible.access.flags");
335 }
336 showAccess = new ModifierFilter(filterBits);
337 }
338
339 void setCompilerOpt(String opt, String arg) {
340 if (compOpts.get(opt) != null) {
341 usageError("main.option.already.seen", opt);
342 }
343 compOpts.put(opt, arg);
344 }
345
346 void setFileManagerOpt(Option opt, String arg) {
347 fileManagerOpts.put(opt, arg);
348 }
349 }
350 }
|
1 /*
2 * Copyright (c) 2012, 2015, 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 jdk.javadoc.internal.tool;
27
28 import java.util.ArrayList;
29 import java.util.LinkedHashMap;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.StringTokenizer;
33
34 import com.sun.tools.javac.main.Option;
35 import com.sun.tools.javac.util.Options;
36
37 /**
38 * javadoc tool options.
39 *
40 * <p><b>This is NOT part of any supported API.
41 * If you write code that depends on this, you do so at your own risk.
42 * This code and its internal interfaces are subject to change or
43 * deletion without notice.</b>
44 */
45 public enum ToolOption {
46 // ----- options for underlying compiler -----
47
48 BOOTCLASSPATH("-bootclasspath", true) {
49 @Override
50 public void process(Helper helper, String arg) {
51 helper.setFileManagerOpt(Option.BOOTCLASSPATH, arg);
52 }
53 },
54
55 CLASSPATH("-classpath", true) {
56 @Override
133
134 SUBPACKAGES("-subpackages", true) {
135 @Override
136 public void process(Helper helper, String arg) {
137 helper.addToList(helper.subPackages, arg);
138 }
139 },
140
141 EXCLUDE("-exclude", true) {
142 @Override
143 public void process(Helper helper, String arg) {
144 helper.addToList(helper.excludedPackages, arg);
145 }
146 },
147
148 // ----- filtering options -----
149
150 PACKAGE("-package") {
151 @Override
152 public void process(Helper helper) {
153 helper.setFilter("package");
154 }
155 },
156
157 PRIVATE("-private") {
158 @Override
159 public void process(Helper helper) {
160 helper.setFilter("private");
161 }
162 },
163
164 PROTECTED("-protected") {
165 @Override
166 public void process(Helper helper) {
167 helper.setFilter("protected");
168 }
169 },
170
171 PUBLIC("-public") {
172 @Override
173 public void process(Helper helper) {
174 helper.setFilter("public");
175 }
176 },
177
178 // ----- output control options -----
179
180 PROMPT("-prompt") {
181 @Override
182 public void process(Helper helper) {
183 helper.compOpts.put("-prompt", "-prompt");
184 helper.promptOnError = true;
185 }
186 },
187
188 QUIET("-quiet") {
189 @Override
190 public void process(Helper helper) {
191 helper.quiet = true;
192 }
193 },
194
206
207 }
208 },
209
210 // ----- other options -----
211
212 BREAKITERATOR("-breakiterator") {
213 @Override
214 public void process(Helper helper) {
215 helper.breakiterator = true;
216 }
217 },
218
219 LOCALE("-locale", true) {
220 @Override
221 public void process(Helper helper, String arg) {
222 helper.docLocale = arg;
223 }
224 },
225
226 // the doclet consumes this
227 OVERVIEW("-overview", true) {
228 @Override
229 public void process(Helper helper, String arg) {
230 helper.setOverviewpath(arg);
231 }
232 },
233
234 XCLASSES("-Xclasses") {
235 @Override
236 public void process(Helper helper) {
237 helper.docClasses = true;
238
239 }
240 },
241
242 // ----- help options -----
243
244 HELP("-help") {
245 @Override
246 public void process(Helper helper) {
247 helper.usage();
248 }
249 },
250
251 X("-X") {
252 @Override
264
265 ToolOption(String opt, boolean hasArg) {
266 this.opt = opt;
267 this.hasArg = hasArg;
268 }
269
270 void process(Helper helper, String arg) { }
271
272 void process(Helper helper) { }
273
274 static ToolOption get(String name) {
275 for (ToolOption o: values()) {
276 if (name.equals(o.opt))
277 return o;
278 }
279 return null;
280 }
281
282 static abstract class Helper {
283 /** List of decoded options. */
284 final List<List<String>> options = new ArrayList<>();
285
286 /** Selected packages, from -subpackages. */
287 final List<String> subPackages = new ArrayList<>();
288
289 /** Excluded packages, from -exclude. */
290 final List<String> excludedPackages = new ArrayList<>();
291
292 // File manager options
293 final Map<Option, String> fileManagerOpts = new LinkedHashMap<>();
294
295 /** javac options, set by various options. */
296 Options compOpts; // = Options.instance(context)
297
298 /* Encoding for javac, and files written? set by -encoding. */
299 String encoding = null;
300
301 /** Set by -breakiterator. */
302 boolean breakiterator = false;
303
304 /** Set by -quiet. */
305 boolean quiet = false;
306
307 /** Set by -Xclasses. */
308 boolean docClasses = false;
309
310 /** Set by -Xwerror. */
311 boolean rejectWarnings = false;
312
313 /** Set by -prompt. */
314 boolean promptOnError;
315
316 /** Set by -locale. */
317 String docLocale = "";
318
319 /** Set by -public, private, -protected, -package. */
320 String showAccess = null;
321 String overviewpath;
322
323 abstract void usage();
324 abstract void Xusage();
325
326 abstract void usageError(String msg, Object... args);
327
328 void addToList(List<String> list, String str){
329 StringTokenizer st = new StringTokenizer(str, ":");
330 String current;
331 while(st.hasMoreTokens()){
332 current = st.nextToken();
333 list.add(current);
334 }
335 }
336
337 void setFilter(String showAccess) {
338 if (showAccess != null) {
339 if (!"public".equals(showAccess)
340 && !"protected".equals(showAccess)
341 && !"private".equals(showAccess)
342 && !"package".equals(showAccess)) {
343 usageError("main.incompatible.access.flags");
344 }
345 this.showAccess = showAccess;
346 }
347 }
348
349 void setCompilerOpt(String opt, String arg) {
350 if (compOpts.get(opt) != null) {
351 usageError("main.option.already.seen", opt);
352 }
353 compOpts.put(opt, arg);
354 }
355
356 void setFileManagerOpt(Option opt, String arg) {
357 fileManagerOpts.put(opt, arg);
358 }
359
360 private void setOverviewpath(String arg) {
361 this.overviewpath = arg;
362 }
363 }
364 }
|