1 /* 2 * Copyright (c) 2012, 2018, 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.main; 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.main.Option.InvalidValueException; 35 import com.sun.tools.javac.main.OptionHelper; 36 import com.sun.tools.javac.util.ListBuffer; 37 import com.sun.tools.javac.util.Options; 38 39 40 /** 41 * javadoc tool options. 42 * 43 * <p><b>This is NOT part of any supported API. 44 * If you write code that depends on this, you do so at your own risk. 45 * This code and its internal interfaces are subject to change or 46 * deletion without notice.</b> 47 */ 48 @Deprecated(since="9", forRemoval=true) 49 @SuppressWarnings("removal") 50 public enum ToolOption { 51 // ----- options for underlying compiler ----- 52 53 BOOTCLASSPATH("-bootclasspath", true) { 54 @Override process(Helper helper, String arg)55 public void process(Helper helper, String arg) { 56 helper.setFileManagerOpt(Option.BOOT_CLASS_PATH, arg); 57 } 58 }, 59 60 CLASSPATH("-classpath", true) { 61 @Override process(Helper helper, String arg)62 public void process(Helper helper, String arg) { 63 helper.setFileManagerOpt(Option.CLASS_PATH, arg); 64 } 65 }, 66 67 CP("-cp", true) { 68 @Override process(Helper helper, String arg)69 public void process(Helper helper, String arg) { 70 helper.setFileManagerOpt(Option.CLASS_PATH, arg); 71 } 72 }, 73 74 CLASS_PATH("--class-path", true) { 75 @Override process(Helper helper, String arg)76 public void process(Helper helper, String arg) { 77 helper.setFileManagerOpt(Option.CLASS_PATH, arg); 78 } 79 }, 80 81 EXTDIRS("-extdirs", true) { 82 @Override process(Helper helper, String arg)83 public void process(Helper helper, String arg) { 84 helper.setFileManagerOpt(Option.EXTDIRS, arg); 85 } 86 }, 87 88 SOURCEPATH("-sourcepath", true) { 89 @Override process(Helper helper, String arg)90 public void process(Helper helper, String arg) { 91 helper.setFileManagerOpt(Option.SOURCE_PATH, arg); 92 } 93 }, 94 95 SOURCE_PATH("--source-path", true) { 96 @Override process(Helper helper, String arg)97 public void process(Helper helper, String arg) { 98 helper.setFileManagerOpt(Option.SOURCE_PATH, arg); 99 } 100 }, 101 102 SYSCLASSPATH("-sysclasspath", true) { 103 @Override process(Helper helper, String arg)104 public void process(Helper helper, String arg) { 105 helper.setFileManagerOpt(Option.BOOT_CLASS_PATH, arg); 106 } 107 }, 108 109 MODULE_SOURCE_PATH("--module-source-path", true) { 110 @Override process(Helper helper, String arg)111 public void process(Helper helper, String arg) { 112 helper.setFileManagerOpt(Option.MODULE_SOURCE_PATH, arg); 113 } 114 }, 115 116 UPGRADE_MODULE_PATH("--upgrade-module-path", true) { 117 @Override process(Helper helper, String arg)118 public void process(Helper helper, String arg) { 119 helper.setFileManagerOpt(Option.UPGRADE_MODULE_PATH, arg); 120 } 121 }, 122 123 SYSTEM_("--system", true) { 124 @Override process(Helper helper, String arg)125 public void process(Helper helper, String arg) { 126 helper.setFileManagerOpt(Option.SYSTEM, arg); 127 } 128 }, 129 130 MODULE_PATH("--module-path", true) { 131 @Override process(Helper helper, String arg)132 public void process(Helper helper, String arg) { 133 helper.setFileManagerOpt(Option.MODULE_PATH, arg); 134 } 135 }, 136 137 P("-p", true) { 138 @Override process(Helper helper, String arg)139 public void process(Helper helper, String arg) { 140 helper.setFileManagerOpt(Option.MODULE_PATH, arg); 141 } 142 }, 143 144 ADD_MODULES("--add-modules", true) { 145 @Override process(Helper helper, String arg)146 public void process(Helper helper, String arg) throws InvalidValueException { 147 Option.ADD_MODULES.process(helper.getOptionHelper(), opt, arg); 148 } 149 }, 150 151 LIMIT_MODULES("--limit-modules", true) { 152 @Override process(Helper helper, String arg)153 public void process(Helper helper, String arg) throws InvalidValueException { 154 Option.LIMIT_MODULES.process(helper.getOptionHelper(), opt, arg); 155 } 156 }, 157 158 ENCODING("-encoding", true) { 159 @Override process(Helper helper, String arg)160 public void process(Helper helper, String arg) { 161 helper.encoding = arg; 162 helper.setCompilerOpt(opt, arg); 163 helper.setFileManagerOpt(Option.ENCODING, arg); 164 } 165 }, 166 167 RELEASE("--release", true) { 168 @Override process(Helper helper, String arg)169 public void process(Helper helper, String arg) { 170 helper.setCompilerOpt(opt, arg); 171 } 172 }, 173 174 SOURCE("-source", true) { 175 @Override process(Helper helper, String arg)176 public void process(Helper helper, String arg) { 177 helper.setCompilerOpt(opt, arg); 178 } 179 }, 180 181 XMAXERRS("-Xmaxerrs", true) { 182 @Override process(Helper helper, String arg)183 public void process(Helper helper, String arg) { 184 helper.setCompilerOpt(opt, arg); 185 } 186 }, 187 188 XMAXWARNS("-Xmaxwarns", true) { 189 @Override process(Helper helper, String arg)190 public void process(Helper helper, String arg) { 191 helper.setCompilerOpt(opt, arg); 192 } 193 }, 194 195 ADD_READS("--add-reads", true) { 196 @Override process(Helper helper, String arg)197 public void process(Helper helper, String arg) throws InvalidValueException { 198 Option.ADD_READS.process(helper.getOptionHelper(), opt, arg); 199 } 200 }, 201 202 ADD_EXPORTS("--add-exports", true) { 203 @Override process(Helper helper, String arg)204 public void process(Helper helper, String arg) throws InvalidValueException { 205 Option.ADD_EXPORTS.process(helper.getOptionHelper(), opt, arg); 206 } 207 }, 208 209 PATCH_MODULE("--patch-module", true) { 210 @Override process(Helper helper, String arg)211 public void process(Helper helper, String arg) throws InvalidValueException { 212 Option.PATCH_MODULE.process(helper.getOptionHelper(), opt, arg); 213 } 214 }, 215 216 ADD_OPENS("--add-opens", true) { 217 @Override process(Helper helper, String arg)218 public void process(Helper helper, String arg) throws InvalidValueException { 219 Option.ADD_OPENS.process(helper.getOptionHelper(), opt, arg); 220 } 221 }, 222 223 // ----- doclet options ----- 224 225 DOCLET("-doclet", true), // handled in setDocletInvoker 226 227 DOCLETPATH("-docletpath", true), // handled in setDocletInvoker 228 229 // ----- selection options ----- 230 231 SUBPACKAGES("-subpackages", true) { 232 @Override process(Helper helper, String arg)233 public void process(Helper helper, String arg) { 234 helper.addToList(helper.subPackages, arg); 235 } 236 }, 237 238 EXCLUDE("-exclude", true) { 239 @Override process(Helper helper, String arg)240 public void process(Helper helper, String arg) { 241 helper.addToList(helper.excludedPackages, arg); 242 } 243 }, 244 245 // ----- filtering options ----- 246 247 PACKAGE("-package") { 248 @Override process(Helper helper)249 public void process(Helper helper) { 250 helper.setFilter( 251 Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE); 252 } 253 }, 254 255 PRIVATE("-private") { 256 @Override process(Helper helper)257 public void process(Helper helper) { 258 helper.setFilter(ModifierFilter.ALL_ACCESS); 259 } 260 }, 261 262 PROTECTED("-protected") { 263 @Override process(Helper helper)264 public void process(Helper helper) { 265 helper.setFilter(Flags.PUBLIC | Flags.PROTECTED); 266 } 267 }, 268 269 PUBLIC("-public") { 270 @Override process(Helper helper)271 public void process(Helper helper) { 272 helper.setFilter(Flags.PUBLIC); 273 } 274 }, 275 276 // ----- output control options ----- 277 278 PROMPT("-prompt") { 279 @Override process(Helper helper)280 public void process(Helper helper) { 281 helper.compOpts.put("-prompt", "-prompt"); 282 helper.promptOnError = true; 283 } 284 }, 285 286 QUIET("-quiet") { 287 @Override process(Helper helper)288 public void process(Helper helper) { 289 helper.quiet = true; 290 } 291 }, 292 293 VERBOSE("-verbose") { 294 @Override process(Helper helper)295 public void process(Helper helper) { 296 helper.compOpts.put("-verbose", ""); 297 } 298 }, 299 300 XWERROR("-Xwerror") { 301 @Override process(Helper helper)302 public void process(Helper helper) { 303 helper.rejectWarnings = true; 304 305 } 306 }, 307 308 // ----- other options ----- 309 310 BREAKITERATOR("-breakiterator") { 311 @Override process(Helper helper)312 public void process(Helper helper) { 313 helper.breakiterator = true; 314 } 315 }, 316 317 LOCALE("-locale", true) { 318 @Override process(Helper helper, String arg)319 public void process(Helper helper, String arg) { 320 helper.docLocale = arg; 321 } 322 }, 323 324 OVERVIEW("-overview", true), 325 326 XCLASSES("-Xclasses") { 327 @Override process(Helper helper)328 public void process(Helper helper) { 329 helper.docClasses = true; 330 331 } 332 }, 333 334 // ----- help options ----- 335 336 HELP("-help") { 337 @Override process(Helper helper)338 public void process(Helper helper) { 339 helper.usage(); 340 } 341 }, 342 343 X("-X") { 344 @Override process(Helper helper)345 public void process(Helper helper) { 346 helper.Xusage(); 347 } 348 }; 349 350 public final String opt; 351 public final boolean hasArg; 352 ToolOption(String opt)353 ToolOption(String opt) { 354 this(opt, false); 355 } 356 ToolOption(String opt, boolean hasArg)357 ToolOption(String opt, boolean hasArg) { 358 this.opt = opt; 359 this.hasArg = hasArg; 360 } 361 process(Helper helper, String arg)362 void process(Helper helper, String arg) throws Option.InvalidValueException { } 363 process(Helper helper)364 void process(Helper helper) { } 365 get(String name)366 static ToolOption get(String name) { 367 for (ToolOption o: values()) { 368 if (name.equals(o.opt)) 369 return o; 370 } 371 return null; 372 } 373 374 static abstract class Helper { 375 /** List of decoded options. */ 376 final ListBuffer<String[]> options = new ListBuffer<>(); 377 378 /** Selected packages, from -subpackages. */ 379 final ListBuffer<String> subPackages = new ListBuffer<>(); 380 381 /** Excluded packages, from -exclude. */ 382 final ListBuffer<String> excludedPackages = new ListBuffer<>(); 383 384 // File manager options 385 final Map<Option, String> fileManagerOpts = new LinkedHashMap<>(); 386 387 /** javac options, set by various options. */ 388 Options compOpts; // = Options.instance(context) 389 390 /* Encoding for javac, and files written? set by -encoding. */ 391 String encoding = null; 392 393 /** Set by -breakiterator. */ 394 boolean breakiterator = false; 395 396 /** Set by -quiet. */ 397 boolean quiet = false; 398 399 /** Set by -Xclasses. */ 400 boolean docClasses = false; 401 402 /** Set by -Xwerror. */ 403 boolean rejectWarnings = false; 404 405 /** Set by -prompt. */ 406 boolean promptOnError; 407 408 /** Set by -locale. */ 409 String docLocale = ""; 410 411 /** Set by -public, private, -protected, -package. */ 412 ModifierFilter showAccess = null; 413 usage()414 abstract void usage(); Xusage()415 abstract void Xusage(); 416 usageError(String msg, Object... args)417 abstract void usageError(String msg, Object... args); getOptionHelper()418 abstract OptionHelper getOptionHelper(); 419 addToList(ListBuffer<String> list, String str)420 void addToList(ListBuffer<String> list, String str){ 421 StringTokenizer st = new StringTokenizer(str, ":"); 422 String current; 423 while(st.hasMoreTokens()){ 424 current = st.nextToken(); 425 list.append(current); 426 } 427 } 428 setFilter(long filterBits)429 void setFilter(long filterBits) { 430 if (showAccess != null) { 431 usageError("main.incompatible.access.flags"); 432 } 433 showAccess = new ModifierFilter(filterBits); 434 } 435 setCompilerOpt(String opt, String arg)436 void setCompilerOpt(String opt, String arg) { 437 if (compOpts.get(opt) != null) { 438 usageError("main.option.already.seen", opt); 439 } 440 compOpts.put(opt, arg); 441 } 442 setFileManagerOpt(Option opt, String arg)443 void setFileManagerOpt(Option opt, String arg) { 444 fileManagerOpts.put(opt, arg); 445 } 446 } 447 } 448