1 /* 2 * Copyright (c) 2012, 2016, 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.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 @Deprecated 47 public enum ToolOption { 48 // ----- options for underlying compiler ----- 49 50 BOOTCLASSPATH("-bootclasspath", true) { 51 @Override 52 public void process(Helper helper, String arg) { 53 helper.setFileManagerOpt(Option.BOOTCLASSPATH, arg); 54 } 55 }, 56 57 CLASSPATH("-classpath", true) { 58 @Override 59 public void process(Helper helper, String arg) { 60 helper.setFileManagerOpt(Option.CLASSPATH, arg); 61 } 62 }, 63 64 CP("-cp", true) { 65 @Override 66 public void process(Helper helper, String arg) { 67 helper.setFileManagerOpt(Option.CP, arg); 68 } 69 }, 70 71 EXTDIRS("-extdirs", true) { 72 @Override 73 public void process(Helper helper, String arg) { 74 helper.setFileManagerOpt(Option.EXTDIRS, arg); 75 } 76 }, 77 78 SOURCEPATH("-sourcepath", true) { 79 @Override 80 public void process(Helper helper, String arg) { 81 helper.setFileManagerOpt(Option.SOURCEPATH, arg); 82 } 83 }, 84 85 SYSCLASSPATH("-sysclasspath", true) { 86 @Override 87 public void process(Helper helper, String arg) { 88 helper.setFileManagerOpt(Option.BOOTCLASSPATH, arg); 89 } 90 }, 91 92 MODULESOURCEPATH("-modulesourcepath", true) { 93 @Override 94 public void process(Helper helper, String arg) { 95 helper.setFileManagerOpt(Option.MODULESOURCEPATH, arg); 96 } 97 }, 98 99 UPGRADEMODULEPATH("-upgrademodulepath", true) { 100 @Override 101 public void process(Helper helper, String arg) { 102 helper.setFileManagerOpt(Option.UPGRADEMODULEPATH, arg); 103 } 104 }, 105 106 SYSTEM("-system", true) { 107 @Override 108 public void process(Helper helper, String arg) { 109 helper.setFileManagerOpt(Option.SYSTEM, arg); 110 } 111 }, 112 113 MODULEPATH("-modulepath", true) { 114 @Override 115 public void process(Helper helper, String arg) { 116 helper.setFileManagerOpt(Option.MODULEPATH, arg); 117 } 118 }, 119 120 ADDMODS("-addmods", true) { 121 @Override 122 public void process(Helper helper, String arg) { 123 helper.setCompilerOpt(opt, arg); 124 } 125 }, 126 127 LIMITMODS("-limitmods", true) { 128 @Override 129 public void process(Helper helper, String arg) { 130 helper.setCompilerOpt(opt, arg); 131 } 132 }, 133 134 ENCODING("-encoding", true) { 135 @Override 136 public void process(Helper helper, String arg) { 137 helper.encoding = arg; 138 helper.setCompilerOpt(opt, arg); 139 } 140 }, 141 142 RELEASE("-release", true) { 143 @Override 144 public void process(Helper helper, String arg) { 145 helper.setCompilerOpt(opt, arg); 146 } 147 }, 148 149 SOURCE("-source", true) { 150 @Override 151 public void process(Helper helper, String arg) { 152 helper.setCompilerOpt(opt, arg); 153 } 154 }, 155 156 XMAXERRS("-Xmaxerrs", true) { 157 @Override 158 public void process(Helper helper, String arg) { 159 helper.setCompilerOpt(opt, arg); 160 } 161 }, 162 163 XMAXWARNS("-Xmaxwarns", true) { 164 @Override 165 public void process(Helper helper, String arg) { 166 helper.setCompilerOpt(opt, arg); 167 } 168 }, 169 170 // ----- doclet options ----- 171 172 DOCLET("-doclet", true), // handled in setDocletInvoker 173 174 DOCLETPATH("-docletpath", true), // handled in setDocletInvoker 175 176 // ----- selection options ----- 177 178 SUBPACKAGES("-subpackages", true) { 179 @Override 180 public void process(Helper helper, String arg) { 181 helper.addToList(helper.subPackages, arg); 182 } 183 }, 184 185 EXCLUDE("-exclude", true) { 186 @Override 187 public void process(Helper helper, String arg) { 188 helper.addToList(helper.excludedPackages, arg); 189 } 190 }, 191 192 // ----- filtering options ----- 193 194 PACKAGE("-package") { 195 @Override 196 public void process(Helper helper) { 197 helper.setFilter( 198 Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE); 199 } 200 }, 201 202 PRIVATE("-private") { 203 @Override 204 public void process(Helper helper) { 205 helper.setFilter(ModifierFilter.ALL_ACCESS); 206 } 207 }, 208 209 PROTECTED("-protected") { 210 @Override 211 public void process(Helper helper) { 212 helper.setFilter(Flags.PUBLIC | Flags.PROTECTED); 213 } 214 }, 215 216 PUBLIC("-public") { 217 @Override 218 public void process(Helper helper) { 219 helper.setFilter(Flags.PUBLIC); 220 } 221 }, 222 223 // ----- output control options ----- 224 225 PROMPT("-prompt") { 226 @Override 227 public void process(Helper helper) { 228 helper.compOpts.put("-prompt", "-prompt"); 229 helper.promptOnError = true; 230 } 231 }, 232 233 QUIET("-quiet") { 234 @Override 235 public void process(Helper helper) { 236 helper.quiet = true; 237 } 238 }, 239 240 VERBOSE("-verbose") { 241 @Override 242 public void process(Helper helper) { 243 helper.compOpts.put("-verbose", ""); 244 } 245 }, 246 247 XWERROR("-Xwerror") { 248 @Override 249 public void process(Helper helper) { 250 helper.rejectWarnings = true; 251 252 } 253 }, 254 255 // ----- other options ----- 256 257 BREAKITERATOR("-breakiterator") { 258 @Override 259 public void process(Helper helper) { 260 helper.breakiterator = true; 261 } 262 }, 263 264 LOCALE("-locale", true) { 265 @Override 266 public void process(Helper helper, String arg) { 267 helper.docLocale = arg; 268 } 269 }, 270 271 OVERVIEW("-overview", true), 272 273 XCLASSES("-Xclasses") { 274 @Override 275 public void process(Helper helper) { 276 helper.docClasses = true; 277 278 } 279 }, 280 281 // ----- help options ----- 282 283 HELP("-help") { 284 @Override 285 public void process(Helper helper) { 286 helper.usage(); 287 } 288 }, 289 290 X("-X") { 291 @Override 292 public void process(Helper helper) { 293 helper.Xusage(); 294 } 295 }; 296 297 public final String opt; 298 public final boolean hasArg; 299 300 ToolOption(String opt) { 301 this(opt, false); 302 } 303 304 ToolOption(String opt, boolean hasArg) { 305 this.opt = opt; 306 this.hasArg = hasArg; 307 } 308 309 void process(Helper helper, String arg) { } 310 311 void process(Helper helper) { } 312 313 static ToolOption get(String name) { 314 for (ToolOption o: values()) { 315 if (name.equals(o.opt)) 316 return o; 317 } 318 return null; 319 } 320 321 static abstract class Helper { 322 /** List of decoded options. */ 323 final ListBuffer<String[]> options = new ListBuffer<>(); 324 325 /** Selected packages, from -subpackages. */ 326 final ListBuffer<String> subPackages = new ListBuffer<>(); 327 328 /** Excluded packages, from -exclude. */ 329 final ListBuffer<String> excludedPackages = new ListBuffer<>(); 330 331 // File manager options 332 final Map<Option, String> fileManagerOpts = new LinkedHashMap<>(); 333 334 /** javac options, set by various options. */ 335 Options compOpts; // = Options.instance(context) 336 337 /* Encoding for javac, and files written? set by -encoding. */ 338 String encoding = null; 339 340 /** Set by -breakiterator. */ 341 boolean breakiterator = false; 342 343 /** Set by -quiet. */ 344 boolean quiet = false; 345 346 /** Set by -Xclasses. */ 347 boolean docClasses = false; 348 349 /** Set by -Xwerror. */ 350 boolean rejectWarnings = false; 351 352 /** Set by -prompt. */ 353 boolean promptOnError; 354 355 /** Set by -locale. */ 356 String docLocale = ""; 357 358 /** Set by -public, private, -protected, -package. */ 359 ModifierFilter showAccess = null; 360 361 abstract void usage(); 362 abstract void Xusage(); 363 364 abstract void usageError(String msg, Object... args); 365 366 void addToList(ListBuffer<String> list, String str){ 367 StringTokenizer st = new StringTokenizer(str, ":"); 368 String current; 369 while(st.hasMoreTokens()){ 370 current = st.nextToken(); 371 list.append(current); 372 } 373 } 374 375 void setFilter(long filterBits) { 376 if (showAccess != null) { 377 usageError("main.incompatible.access.flags"); 378 } 379 showAccess = new ModifierFilter(filterBits); 380 } 381 382 void setCompilerOpt(String opt, String arg) { 383 if (compOpts.get(opt) != null) { 384 usageError("main.option.already.seen", opt); 385 } 386 compOpts.put(opt, arg); 387 } 388 389 void setFileManagerOpt(Option opt, String arg) { 390 fileManagerOpts.put(opt, arg); 391 } 392 } 393 }