14543
|
1 |
/*
|
|
2 |
* Copyright (c) 2012, 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 |
EXTDIRS("-extdirs", true) {
|
|
60 |
@Override
|
|
61 |
public void process(Helper helper, String arg) {
|
|
62 |
helper.setCompilerOpt(opt, arg);
|
|
63 |
}
|
|
64 |
},
|
|
65 |
|
|
66 |
SOURCEPATH("-sourcepath", true) {
|
|
67 |
@Override
|
|
68 |
public void process(Helper helper, String arg) {
|
|
69 |
helper.setCompilerOpt(opt, arg);
|
|
70 |
}
|
|
71 |
},
|
|
72 |
|
|
73 |
SYSCLASSPATH("-sysclasspath", true) {
|
|
74 |
@Override
|
|
75 |
public void process(Helper helper, String arg) {
|
|
76 |
helper.setCompilerOpt("-bootclasspath", arg);
|
|
77 |
}
|
|
78 |
},
|
|
79 |
|
|
80 |
ENCODING("-encoding", true) {
|
|
81 |
@Override
|
|
82 |
public void process(Helper helper, String arg) {
|
|
83 |
helper.encoding = arg;
|
|
84 |
helper.setCompilerOpt(opt, arg);
|
|
85 |
}
|
|
86 |
},
|
|
87 |
|
|
88 |
SOURCE("-source", true) {
|
|
89 |
@Override
|
|
90 |
public void process(Helper helper, String arg) {
|
|
91 |
helper.setCompilerOpt(opt, arg);
|
|
92 |
}
|
|
93 |
},
|
|
94 |
|
|
95 |
XMAXERRS("-Xmaxerrs", true) {
|
|
96 |
@Override
|
|
97 |
public void process(Helper helper, String arg) {
|
|
98 |
helper.setCompilerOpt(opt, arg);
|
|
99 |
}
|
|
100 |
},
|
|
101 |
|
|
102 |
XMAXWARNS("-Xmaxwarns", true) {
|
|
103 |
@Override
|
|
104 |
public void process(Helper helper, String arg) {
|
|
105 |
helper.setCompilerOpt(opt, arg);
|
|
106 |
}
|
|
107 |
},
|
|
108 |
|
|
109 |
// ----- doclet options -----
|
|
110 |
|
|
111 |
DOCLET("-doclet", true), // handled in setDocletInvoker
|
|
112 |
|
|
113 |
DOCLETPATH("-docletpath", true), // handled in setDocletInvoker
|
|
114 |
|
|
115 |
// ----- selection options -----
|
|
116 |
|
|
117 |
SUBPACKAGES("-subpackages", true) {
|
|
118 |
@Override
|
|
119 |
public void process(Helper helper, String arg) {
|
|
120 |
helper.addToList(helper.subPackages, arg);
|
|
121 |
}
|
|
122 |
},
|
|
123 |
|
|
124 |
EXCLUDE("-exclude", true) {
|
|
125 |
@Override
|
|
126 |
public void process(Helper helper, String arg) {
|
|
127 |
helper.addToList(helper.excludedPackages, arg);
|
|
128 |
}
|
|
129 |
},
|
|
130 |
|
|
131 |
// ----- filtering options -----
|
|
132 |
|
|
133 |
PACKAGE("-package") {
|
|
134 |
@Override
|
|
135 |
public void process(Helper helper) {
|
|
136 |
helper.setFilter(
|
|
137 |
Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE);
|
|
138 |
}
|
|
139 |
},
|
|
140 |
|
|
141 |
PRIVATE("-private") {
|
|
142 |
@Override
|
|
143 |
public void process(Helper helper) {
|
|
144 |
helper.setFilter(ModifierFilter.ALL_ACCESS);
|
|
145 |
}
|
|
146 |
},
|
|
147 |
|
|
148 |
PROTECTED("-protected") {
|
|
149 |
@Override
|
|
150 |
public void process(Helper helper) {
|
|
151 |
helper.setFilter(Flags.PUBLIC | Flags.PROTECTED);
|
|
152 |
}
|
|
153 |
},
|
|
154 |
|
|
155 |
PUBLIC("-public") {
|
|
156 |
@Override
|
|
157 |
public void process(Helper helper) {
|
|
158 |
helper.setFilter(Flags.PUBLIC);
|
|
159 |
}
|
|
160 |
},
|
|
161 |
|
|
162 |
// ----- output control options -----
|
|
163 |
|
|
164 |
PROMPT("-prompt") {
|
|
165 |
@Override
|
|
166 |
public void process(Helper helper) {
|
|
167 |
helper.compOpts.put("-prompt", "-prompt");
|
|
168 |
helper.promptOnError = true;
|
|
169 |
}
|
|
170 |
},
|
|
171 |
|
|
172 |
QUIET("-quiet") {
|
|
173 |
@Override
|
|
174 |
public void process(Helper helper) {
|
|
175 |
helper.quiet = true;
|
|
176 |
}
|
|
177 |
},
|
|
178 |
|
|
179 |
VERBOSE("-verbose") {
|
|
180 |
@Override
|
|
181 |
public void process(Helper helper) {
|
|
182 |
helper.compOpts.put("-verbose", "");
|
|
183 |
}
|
|
184 |
},
|
|
185 |
|
|
186 |
XWERROR("-Xwerror") {
|
|
187 |
@Override
|
|
188 |
public void process(Helper helper) {
|
|
189 |
helper.rejectWarnings = true;
|
|
190 |
|
|
191 |
}
|
|
192 |
},
|
|
193 |
|
|
194 |
// ----- other options -----
|
|
195 |
|
|
196 |
BREAKITERATOR("-breakiterator") {
|
|
197 |
@Override
|
|
198 |
public void process(Helper helper) {
|
|
199 |
helper.breakiterator = true;
|
|
200 |
}
|
|
201 |
},
|
|
202 |
|
|
203 |
LOCALE("-locale", true) {
|
|
204 |
@Override
|
|
205 |
public void process(Helper helper, String arg) {
|
|
206 |
helper.docLocale = arg;
|
|
207 |
}
|
|
208 |
},
|
|
209 |
|
|
210 |
OVERVIEW("-overview", true),
|
|
211 |
|
|
212 |
XCLASSES("-Xclasses") {
|
|
213 |
@Override
|
|
214 |
public void process(Helper helper) {
|
|
215 |
helper.docClasses = true;
|
|
216 |
|
|
217 |
}
|
|
218 |
},
|
|
219 |
|
|
220 |
// ----- help options -----
|
|
221 |
|
|
222 |
HELP("-help") {
|
|
223 |
@Override
|
|
224 |
public void process(Helper helper) {
|
|
225 |
helper.usage();
|
|
226 |
}
|
|
227 |
},
|
|
228 |
|
|
229 |
X("-X") {
|
|
230 |
@Override
|
|
231 |
public void process(Helper helper) {
|
|
232 |
helper.Xusage();
|
|
233 |
}
|
|
234 |
};
|
|
235 |
|
|
236 |
public final String opt;
|
|
237 |
public final boolean hasArg;
|
|
238 |
|
|
239 |
ToolOption(String opt) {
|
|
240 |
this(opt, false);
|
|
241 |
}
|
|
242 |
|
|
243 |
ToolOption(String opt, boolean hasArg) {
|
|
244 |
this.opt = opt;
|
|
245 |
this.hasArg = hasArg;
|
|
246 |
}
|
|
247 |
|
|
248 |
void process(Helper helper, String arg) { }
|
|
249 |
|
|
250 |
void process(Helper helper) { }
|
|
251 |
|
|
252 |
static ToolOption get(String name) {
|
|
253 |
for (ToolOption o: values()) {
|
|
254 |
if (name.equals(o.opt))
|
|
255 |
return o;
|
|
256 |
}
|
|
257 |
return null;
|
|
258 |
}
|
|
259 |
|
|
260 |
static abstract class Helper {
|
|
261 |
/** List of decoded options. */
|
|
262 |
final ListBuffer<String[]> options = new ListBuffer<String[]>();
|
|
263 |
|
|
264 |
/** Selected packages, from -subpackages. */
|
|
265 |
final ListBuffer<String> subPackages = new ListBuffer<String>();
|
|
266 |
|
|
267 |
/** Excluded packages, from -exclude. */
|
|
268 |
final ListBuffer<String> excludedPackages = new ListBuffer<String>();
|
|
269 |
|
|
270 |
/** javac options, set by various options. */
|
|
271 |
Options compOpts; // = Options.instance(context)
|
|
272 |
|
|
273 |
/* Encoding for javac, and files written? set by -encoding. */
|
|
274 |
String encoding = null;
|
|
275 |
|
|
276 |
/** Set by -breakiterator. */
|
|
277 |
boolean breakiterator = false;
|
|
278 |
|
|
279 |
/** Set by -quiet. */
|
|
280 |
boolean quiet = false;
|
|
281 |
|
|
282 |
/** Set by -Xclasses. */
|
|
283 |
boolean docClasses = false;
|
|
284 |
|
|
285 |
/** Set by -Xwerror. */
|
|
286 |
boolean rejectWarnings = false;
|
|
287 |
|
|
288 |
/** Set by -prompt. */
|
|
289 |
boolean promptOnError;
|
|
290 |
|
|
291 |
/** Set by -locale. */
|
|
292 |
String docLocale = "";
|
|
293 |
|
|
294 |
/** Set by -public, private, -protected, -package. */
|
|
295 |
ModifierFilter showAccess = null;
|
|
296 |
|
|
297 |
abstract void usage();
|
|
298 |
abstract void Xusage();
|
|
299 |
|
|
300 |
abstract void usageError(String msg, Object... args);
|
|
301 |
|
|
302 |
protected void addToList(ListBuffer<String> list, String str){
|
|
303 |
StringTokenizer st = new StringTokenizer(str, ":");
|
|
304 |
String current;
|
|
305 |
while(st.hasMoreTokens()){
|
|
306 |
current = st.nextToken();
|
|
307 |
list.append(current);
|
|
308 |
}
|
|
309 |
}
|
|
310 |
|
|
311 |
protected void setFilter(long filterBits) {
|
|
312 |
if (showAccess != null) {
|
|
313 |
usageError("main.incompatible.access.flags");
|
|
314 |
}
|
|
315 |
showAccess = new ModifierFilter(filterBits);
|
|
316 |
}
|
|
317 |
|
|
318 |
private void setCompilerOpt(String opt, String arg) {
|
|
319 |
if (compOpts.get(opt) != null) {
|
|
320 |
usageError("main.option.already.seen", opt);
|
|
321 |
}
|
|
322 |
compOpts.put(opt, arg);
|
|
323 |
}
|
|
324 |
}
|
|
325 |
}
|