1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javadoc/ToolOption.java Thu Nov 15 14:41:31 2012 -0800 1.3 @@ -0,0 +1,325 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, 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 + EXTDIRS("-extdirs", 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 + SOURCEPATH("-sourcepath", 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 + SYSCLASSPATH("-sysclasspath", true) { 1.77 + @Override 1.78 + public void process(Helper helper, String arg) { 1.79 + helper.setCompilerOpt("-bootclasspath", arg); 1.80 + } 1.81 + }, 1.82 + 1.83 + ENCODING("-encoding", true) { 1.84 + @Override 1.85 + public void process(Helper helper, String arg) { 1.86 + helper.encoding = arg; 1.87 + helper.setCompilerOpt(opt, arg); 1.88 + } 1.89 + }, 1.90 + 1.91 + SOURCE("-source", true) { 1.92 + @Override 1.93 + public void process(Helper helper, String arg) { 1.94 + helper.setCompilerOpt(opt, arg); 1.95 + } 1.96 + }, 1.97 + 1.98 + XMAXERRS("-Xmaxerrs", 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 + XMAXWARNS("-Xmaxwarns", 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 + // ----- doclet options ----- 1.113 + 1.114 + DOCLET("-doclet", true), // handled in setDocletInvoker 1.115 + 1.116 + DOCLETPATH("-docletpath", true), // handled in setDocletInvoker 1.117 + 1.118 + // ----- selection options ----- 1.119 + 1.120 + SUBPACKAGES("-subpackages", true) { 1.121 + @Override 1.122 + public void process(Helper helper, String arg) { 1.123 + helper.addToList(helper.subPackages, arg); 1.124 + } 1.125 + }, 1.126 + 1.127 + EXCLUDE("-exclude", true) { 1.128 + @Override 1.129 + public void process(Helper helper, String arg) { 1.130 + helper.addToList(helper.excludedPackages, arg); 1.131 + } 1.132 + }, 1.133 + 1.134 + // ----- filtering options ----- 1.135 + 1.136 + PACKAGE("-package") { 1.137 + @Override 1.138 + public void process(Helper helper) { 1.139 + helper.setFilter( 1.140 + Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE); 1.141 + } 1.142 + }, 1.143 + 1.144 + PRIVATE("-private") { 1.145 + @Override 1.146 + public void process(Helper helper) { 1.147 + helper.setFilter(ModifierFilter.ALL_ACCESS); 1.148 + } 1.149 + }, 1.150 + 1.151 + PROTECTED("-protected") { 1.152 + @Override 1.153 + public void process(Helper helper) { 1.154 + helper.setFilter(Flags.PUBLIC | Flags.PROTECTED); 1.155 + } 1.156 + }, 1.157 + 1.158 + PUBLIC("-public") { 1.159 + @Override 1.160 + public void process(Helper helper) { 1.161 + helper.setFilter(Flags.PUBLIC); 1.162 + } 1.163 + }, 1.164 + 1.165 + // ----- output control options ----- 1.166 + 1.167 + PROMPT("-prompt") { 1.168 + @Override 1.169 + public void process(Helper helper) { 1.170 + helper.compOpts.put("-prompt", "-prompt"); 1.171 + helper.promptOnError = true; 1.172 + } 1.173 + }, 1.174 + 1.175 + QUIET("-quiet") { 1.176 + @Override 1.177 + public void process(Helper helper) { 1.178 + helper.quiet = true; 1.179 + } 1.180 + }, 1.181 + 1.182 + VERBOSE("-verbose") { 1.183 + @Override 1.184 + public void process(Helper helper) { 1.185 + helper.compOpts.put("-verbose", ""); 1.186 + } 1.187 + }, 1.188 + 1.189 + XWERROR("-Xwerror") { 1.190 + @Override 1.191 + public void process(Helper helper) { 1.192 + helper.rejectWarnings = true; 1.193 + 1.194 + } 1.195 + }, 1.196 + 1.197 + // ----- other options ----- 1.198 + 1.199 + BREAKITERATOR("-breakiterator") { 1.200 + @Override 1.201 + public void process(Helper helper) { 1.202 + helper.breakiterator = true; 1.203 + } 1.204 + }, 1.205 + 1.206 + LOCALE("-locale", true) { 1.207 + @Override 1.208 + public void process(Helper helper, String arg) { 1.209 + helper.docLocale = arg; 1.210 + } 1.211 + }, 1.212 + 1.213 + OVERVIEW("-overview", true), 1.214 + 1.215 + XCLASSES("-Xclasses") { 1.216 + @Override 1.217 + public void process(Helper helper) { 1.218 + helper.docClasses = true; 1.219 + 1.220 + } 1.221 + }, 1.222 + 1.223 + // ----- help options ----- 1.224 + 1.225 + HELP("-help") { 1.226 + @Override 1.227 + public void process(Helper helper) { 1.228 + helper.usage(); 1.229 + } 1.230 + }, 1.231 + 1.232 + X("-X") { 1.233 + @Override 1.234 + public void process(Helper helper) { 1.235 + helper.Xusage(); 1.236 + } 1.237 + }; 1.238 + 1.239 + public final String opt; 1.240 + public final boolean hasArg; 1.241 + 1.242 + ToolOption(String opt) { 1.243 + this(opt, false); 1.244 + } 1.245 + 1.246 + ToolOption(String opt, boolean hasArg) { 1.247 + this.opt = opt; 1.248 + this.hasArg = hasArg; 1.249 + } 1.250 + 1.251 + void process(Helper helper, String arg) { } 1.252 + 1.253 + void process(Helper helper) { } 1.254 + 1.255 + static ToolOption get(String name) { 1.256 + for (ToolOption o: values()) { 1.257 + if (name.equals(o.opt)) 1.258 + return o; 1.259 + } 1.260 + return null; 1.261 + } 1.262 + 1.263 + static abstract class Helper { 1.264 + /** List of decoded options. */ 1.265 + final ListBuffer<String[]> options = new ListBuffer<String[]>(); 1.266 + 1.267 + /** Selected packages, from -subpackages. */ 1.268 + final ListBuffer<String> subPackages = new ListBuffer<String>(); 1.269 + 1.270 + /** Excluded packages, from -exclude. */ 1.271 + final ListBuffer<String> excludedPackages = new ListBuffer<String>(); 1.272 + 1.273 + /** javac options, set by various options. */ 1.274 + Options compOpts; // = Options.instance(context) 1.275 + 1.276 + /* Encoding for javac, and files written? set by -encoding. */ 1.277 + String encoding = null; 1.278 + 1.279 + /** Set by -breakiterator. */ 1.280 + boolean breakiterator = false; 1.281 + 1.282 + /** Set by -quiet. */ 1.283 + boolean quiet = false; 1.284 + 1.285 + /** Set by -Xclasses. */ 1.286 + boolean docClasses = false; 1.287 + 1.288 + /** Set by -Xwerror. */ 1.289 + boolean rejectWarnings = false; 1.290 + 1.291 + /** Set by -prompt. */ 1.292 + boolean promptOnError; 1.293 + 1.294 + /** Set by -locale. */ 1.295 + String docLocale = ""; 1.296 + 1.297 + /** Set by -public, private, -protected, -package. */ 1.298 + ModifierFilter showAccess = null; 1.299 + 1.300 + abstract void usage(); 1.301 + abstract void Xusage(); 1.302 + 1.303 + abstract void usageError(String msg, Object... args); 1.304 + 1.305 + protected void addToList(ListBuffer<String> list, String str){ 1.306 + StringTokenizer st = new StringTokenizer(str, ":"); 1.307 + String current; 1.308 + while(st.hasMoreTokens()){ 1.309 + current = st.nextToken(); 1.310 + list.append(current); 1.311 + } 1.312 + } 1.313 + 1.314 + protected void setFilter(long filterBits) { 1.315 + if (showAccess != null) { 1.316 + usageError("main.incompatible.access.flags"); 1.317 + } 1.318 + showAccess = new ModifierFilter(filterBits); 1.319 + } 1.320 + 1.321 + private void setCompilerOpt(String opt, String arg) { 1.322 + if (compOpts.get(opt) != null) { 1.323 + usageError("main.option.already.seen", opt); 1.324 + } 1.325 + compOpts.put(opt, arg); 1.326 + } 1.327 + } 1.328 +}