1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javadoc/ToolOption.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,332 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.javadoc; 1.30 + 1.31 +import com.sun.tools.javac.code.Flags; 1.32 +import com.sun.tools.javac.util.ListBuffer; 1.33 +import com.sun.tools.javac.util.Options; 1.34 +import java.util.StringTokenizer; 1.35 + 1.36 + 1.37 +/** 1.38 + * javadoc tool options. 1.39 + * 1.40 + * <p><b>This is NOT part of any supported API. 1.41 + * If you write code that depends on this, you do so at your own risk. 1.42 + * This code and its internal interfaces are subject to change or 1.43 + * deletion without notice.</b> 1.44 + */ 1.45 +public enum ToolOption { 1.46 + // ----- options for underlying compiler ----- 1.47 + 1.48 + BOOTCLASSPATH("-bootclasspath", true) { 1.49 + @Override 1.50 + public void process(Helper helper, String arg) { 1.51 + helper.setCompilerOpt(opt, arg); 1.52 + } 1.53 + }, 1.54 + 1.55 + CLASSPATH("-classpath", true) { 1.56 + @Override 1.57 + public void process(Helper helper, String arg) { 1.58 + helper.setCompilerOpt(opt, arg); 1.59 + } 1.60 + }, 1.61 + 1.62 + CP("-cp", true) { 1.63 + @Override 1.64 + public void process(Helper helper, String arg) { 1.65 + helper.setCompilerOpt(opt, arg); 1.66 + } 1.67 + }, 1.68 + 1.69 + EXTDIRS("-extdirs", true) { 1.70 + @Override 1.71 + public void process(Helper helper, String arg) { 1.72 + helper.setCompilerOpt(opt, arg); 1.73 + } 1.74 + }, 1.75 + 1.76 + SOURCEPATH("-sourcepath", true) { 1.77 + @Override 1.78 + public void process(Helper helper, String arg) { 1.79 + helper.setCompilerOpt(opt, arg); 1.80 + } 1.81 + }, 1.82 + 1.83 + SYSCLASSPATH("-sysclasspath", true) { 1.84 + @Override 1.85 + public void process(Helper helper, String arg) { 1.86 + helper.setCompilerOpt("-bootclasspath", arg); 1.87 + } 1.88 + }, 1.89 + 1.90 + ENCODING("-encoding", true) { 1.91 + @Override 1.92 + public void process(Helper helper, String arg) { 1.93 + helper.encoding = arg; 1.94 + helper.setCompilerOpt(opt, arg); 1.95 + } 1.96 + }, 1.97 + 1.98 + SOURCE("-source", true) { 1.99 + @Override 1.100 + public void process(Helper helper, String arg) { 1.101 + helper.setCompilerOpt(opt, arg); 1.102 + } 1.103 + }, 1.104 + 1.105 + XMAXERRS("-Xmaxerrs", true) { 1.106 + @Override 1.107 + public void process(Helper helper, String arg) { 1.108 + helper.setCompilerOpt(opt, arg); 1.109 + } 1.110 + }, 1.111 + 1.112 + XMAXWARNS("-Xmaxwarns", true) { 1.113 + @Override 1.114 + public void process(Helper helper, String arg) { 1.115 + helper.setCompilerOpt(opt, arg); 1.116 + } 1.117 + }, 1.118 + 1.119 + // ----- doclet options ----- 1.120 + 1.121 + DOCLET("-doclet", true), // handled in setDocletInvoker 1.122 + 1.123 + DOCLETPATH("-docletpath", true), // handled in setDocletInvoker 1.124 + 1.125 + // ----- selection options ----- 1.126 + 1.127 + SUBPACKAGES("-subpackages", true) { 1.128 + @Override 1.129 + public void process(Helper helper, String arg) { 1.130 + helper.addToList(helper.subPackages, arg); 1.131 + } 1.132 + }, 1.133 + 1.134 + EXCLUDE("-exclude", true) { 1.135 + @Override 1.136 + public void process(Helper helper, String arg) { 1.137 + helper.addToList(helper.excludedPackages, arg); 1.138 + } 1.139 + }, 1.140 + 1.141 + // ----- filtering options ----- 1.142 + 1.143 + PACKAGE("-package") { 1.144 + @Override 1.145 + public void process(Helper helper) { 1.146 + helper.setFilter( 1.147 + Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE); 1.148 + } 1.149 + }, 1.150 + 1.151 + PRIVATE("-private") { 1.152 + @Override 1.153 + public void process(Helper helper) { 1.154 + helper.setFilter(ModifierFilter.ALL_ACCESS); 1.155 + } 1.156 + }, 1.157 + 1.158 + PROTECTED("-protected") { 1.159 + @Override 1.160 + public void process(Helper helper) { 1.161 + helper.setFilter(Flags.PUBLIC | Flags.PROTECTED); 1.162 + } 1.163 + }, 1.164 + 1.165 + PUBLIC("-public") { 1.166 + @Override 1.167 + public void process(Helper helper) { 1.168 + helper.setFilter(Flags.PUBLIC); 1.169 + } 1.170 + }, 1.171 + 1.172 + // ----- output control options ----- 1.173 + 1.174 + PROMPT("-prompt") { 1.175 + @Override 1.176 + public void process(Helper helper) { 1.177 + helper.compOpts.put("-prompt", "-prompt"); 1.178 + helper.promptOnError = true; 1.179 + } 1.180 + }, 1.181 + 1.182 + QUIET("-quiet") { 1.183 + @Override 1.184 + public void process(Helper helper) { 1.185 + helper.quiet = true; 1.186 + } 1.187 + }, 1.188 + 1.189 + VERBOSE("-verbose") { 1.190 + @Override 1.191 + public void process(Helper helper) { 1.192 + helper.compOpts.put("-verbose", ""); 1.193 + } 1.194 + }, 1.195 + 1.196 + XWERROR("-Xwerror") { 1.197 + @Override 1.198 + public void process(Helper helper) { 1.199 + helper.rejectWarnings = true; 1.200 + 1.201 + } 1.202 + }, 1.203 + 1.204 + // ----- other options ----- 1.205 + 1.206 + BREAKITERATOR("-breakiterator") { 1.207 + @Override 1.208 + public void process(Helper helper) { 1.209 + helper.breakiterator = true; 1.210 + } 1.211 + }, 1.212 + 1.213 + LOCALE("-locale", true) { 1.214 + @Override 1.215 + public void process(Helper helper, String arg) { 1.216 + helper.docLocale = arg; 1.217 + } 1.218 + }, 1.219 + 1.220 + OVERVIEW("-overview", true), 1.221 + 1.222 + XCLASSES("-Xclasses") { 1.223 + @Override 1.224 + public void process(Helper helper) { 1.225 + helper.docClasses = true; 1.226 + 1.227 + } 1.228 + }, 1.229 + 1.230 + // ----- help options ----- 1.231 + 1.232 + HELP("-help") { 1.233 + @Override 1.234 + public void process(Helper helper) { 1.235 + helper.usage(); 1.236 + } 1.237 + }, 1.238 + 1.239 + X("-X") { 1.240 + @Override 1.241 + public void process(Helper helper) { 1.242 + helper.Xusage(); 1.243 + } 1.244 + }; 1.245 + 1.246 + public final String opt; 1.247 + public final boolean hasArg; 1.248 + 1.249 + ToolOption(String opt) { 1.250 + this(opt, false); 1.251 + } 1.252 + 1.253 + ToolOption(String opt, boolean hasArg) { 1.254 + this.opt = opt; 1.255 + this.hasArg = hasArg; 1.256 + } 1.257 + 1.258 + void process(Helper helper, String arg) { } 1.259 + 1.260 + void process(Helper helper) { } 1.261 + 1.262 + static ToolOption get(String name) { 1.263 + for (ToolOption o: values()) { 1.264 + if (name.equals(o.opt)) 1.265 + return o; 1.266 + } 1.267 + return null; 1.268 + } 1.269 + 1.270 + static abstract class Helper { 1.271 + /** List of decoded options. */ 1.272 + final ListBuffer<String[]> options = new ListBuffer<String[]>(); 1.273 + 1.274 + /** Selected packages, from -subpackages. */ 1.275 + final ListBuffer<String> subPackages = new ListBuffer<String>(); 1.276 + 1.277 + /** Excluded packages, from -exclude. */ 1.278 + final ListBuffer<String> excludedPackages = new ListBuffer<String>(); 1.279 + 1.280 + /** javac options, set by various options. */ 1.281 + Options compOpts; // = Options.instance(context) 1.282 + 1.283 + /* Encoding for javac, and files written? set by -encoding. */ 1.284 + String encoding = null; 1.285 + 1.286 + /** Set by -breakiterator. */ 1.287 + boolean breakiterator = false; 1.288 + 1.289 + /** Set by -quiet. */ 1.290 + boolean quiet = false; 1.291 + 1.292 + /** Set by -Xclasses. */ 1.293 + boolean docClasses = false; 1.294 + 1.295 + /** Set by -Xwerror. */ 1.296 + boolean rejectWarnings = false; 1.297 + 1.298 + /** Set by -prompt. */ 1.299 + boolean promptOnError; 1.300 + 1.301 + /** Set by -locale. */ 1.302 + String docLocale = ""; 1.303 + 1.304 + /** Set by -public, private, -protected, -package. */ 1.305 + ModifierFilter showAccess = null; 1.306 + 1.307 + abstract void usage(); 1.308 + abstract void Xusage(); 1.309 + 1.310 + abstract void usageError(String msg, Object... args); 1.311 + 1.312 + protected void addToList(ListBuffer<String> list, String str){ 1.313 + StringTokenizer st = new StringTokenizer(str, ":"); 1.314 + String current; 1.315 + while(st.hasMoreTokens()){ 1.316 + current = st.nextToken(); 1.317 + list.append(current); 1.318 + } 1.319 + } 1.320 + 1.321 + protected void setFilter(long filterBits) { 1.322 + if (showAccess != null) { 1.323 + usageError("main.incompatible.access.flags"); 1.324 + } 1.325 + showAccess = new ModifierFilter(filterBits); 1.326 + } 1.327 + 1.328 + private void setCompilerOpt(String opt, String arg) { 1.329 + if (compOpts.get(opt) != null) { 1.330 + usageError("main.option.already.seen", opt); 1.331 + } 1.332 + compOpts.put(opt, arg); 1.333 + } 1.334 + } 1.335 +}