src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java
branchniosocketimpl-branch
changeset 57208 7a45c67e73d0
parent 57207 30695f27d7ea
parent 53902 7a6fd71449e7
child 57210 a67ea4f53e56
equal deleted inserted replaced
57207:30695f27d7ea 57208:7a45c67e73d0
     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
       
    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
       
    62         public void process(Helper helper, String arg) {
       
    63             helper.setFileManagerOpt(Option.CLASS_PATH, arg);
       
    64         }
       
    65     },
       
    66 
       
    67     CP("-cp", true) {
       
    68         @Override
       
    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
       
    76         public void process(Helper helper, String arg) {
       
    77             helper.setFileManagerOpt(Option.CLASS_PATH, arg);
       
    78         }
       
    79     },
       
    80 
       
    81     EXTDIRS("-extdirs", true) {
       
    82         @Override
       
    83         public void process(Helper helper, String arg) {
       
    84             helper.setFileManagerOpt(Option.EXTDIRS, arg);
       
    85         }
       
    86     },
       
    87 
       
    88     SOURCEPATH("-sourcepath", true) {
       
    89         @Override
       
    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
       
    97         public void process(Helper helper, String arg) {
       
    98             helper.setFileManagerOpt(Option.SOURCE_PATH, arg);
       
    99         }
       
   100     },
       
   101 
       
   102     SYSCLASSPATH("-sysclasspath", true) {
       
   103         @Override
       
   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
       
   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
       
   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
       
   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
       
   132         public void process(Helper helper, String arg) {
       
   133             helper.setFileManagerOpt(Option.MODULE_PATH, arg);
       
   134         }
       
   135     },
       
   136 
       
   137     P("-p", true) {
       
   138         @Override
       
   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
       
   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
       
   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
       
   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
       
   169         public void process(Helper helper, String arg) {
       
   170             helper.setCompilerOpt(opt, arg);
       
   171         }
       
   172     },
       
   173 
       
   174     SOURCE("-source", true) {
       
   175         @Override
       
   176         public void process(Helper helper, String arg) {
       
   177             helper.setCompilerOpt("--source", arg);
       
   178         }
       
   179     },
       
   180 
       
   181     SOURCE2("--source", true) {
       
   182         @Override
       
   183         public void process(Helper helper, String arg) {
       
   184             helper.setCompilerOpt(opt, arg);
       
   185         }
       
   186     },
       
   187 
       
   188     XMAXERRS("-Xmaxerrs", true) {
       
   189         @Override
       
   190         public void process(Helper helper, String arg) {
       
   191             helper.setCompilerOpt(opt, arg);
       
   192         }
       
   193     },
       
   194 
       
   195     XMAXWARNS("-Xmaxwarns", true) {
       
   196         @Override
       
   197         public void process(Helper helper, String arg) {
       
   198             helper.setCompilerOpt(opt, arg);
       
   199         }
       
   200     },
       
   201 
       
   202     ADD_READS("--add-reads", true) {
       
   203         @Override
       
   204         public void process(Helper helper, String arg) throws InvalidValueException {
       
   205             Option.ADD_READS.process(helper.getOptionHelper(), opt, arg);
       
   206         }
       
   207     },
       
   208 
       
   209     ADD_EXPORTS("--add-exports", true) {
       
   210         @Override
       
   211         public void process(Helper helper, String arg) throws InvalidValueException {
       
   212             Option.ADD_EXPORTS.process(helper.getOptionHelper(), opt, arg);
       
   213         }
       
   214     },
       
   215 
       
   216     PATCH_MODULE("--patch-module", true) {
       
   217         @Override
       
   218         public void process(Helper helper, String arg) throws InvalidValueException {
       
   219             Option.PATCH_MODULE.process(helper.getOptionHelper(), opt, arg);
       
   220         }
       
   221     },
       
   222 
       
   223     ADD_OPENS("--add-opens", true) {
       
   224         @Override
       
   225         public void process(Helper helper, String arg) throws InvalidValueException {
       
   226             Option.ADD_OPENS.process(helper.getOptionHelper(), opt, arg);
       
   227         }
       
   228     },
       
   229 
       
   230     // ----- doclet options -----
       
   231 
       
   232     DOCLET("-doclet", true), // handled in setDocletInvoker
       
   233 
       
   234     DOCLETPATH("-docletpath", true), // handled in setDocletInvoker
       
   235 
       
   236     // ----- selection options -----
       
   237 
       
   238     SUBPACKAGES("-subpackages", true) {
       
   239         @Override
       
   240         public void process(Helper helper, String arg) {
       
   241             helper.addToList(helper.subPackages, arg);
       
   242         }
       
   243     },
       
   244 
       
   245     EXCLUDE("-exclude", true) {
       
   246         @Override
       
   247         public void process(Helper helper, String arg) {
       
   248             helper.addToList(helper.excludedPackages, arg);
       
   249         }
       
   250     },
       
   251 
       
   252     // ----- filtering options -----
       
   253 
       
   254     PACKAGE("-package") {
       
   255         @Override
       
   256         public void process(Helper helper) {
       
   257             helper.setFilter(
       
   258                     Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE);
       
   259         }
       
   260     },
       
   261 
       
   262     PRIVATE("-private") {
       
   263         @Override
       
   264         public void process(Helper helper) {
       
   265             helper.setFilter(ModifierFilter.ALL_ACCESS);
       
   266         }
       
   267     },
       
   268 
       
   269     PROTECTED("-protected") {
       
   270         @Override
       
   271         public void process(Helper helper) {
       
   272             helper.setFilter(Flags.PUBLIC | Flags.PROTECTED);
       
   273         }
       
   274     },
       
   275 
       
   276     PUBLIC("-public") {
       
   277         @Override
       
   278         public void process(Helper helper) {
       
   279             helper.setFilter(Flags.PUBLIC);
       
   280         }
       
   281     },
       
   282 
       
   283     // ----- output control options -----
       
   284 
       
   285     PROMPT("-prompt") {
       
   286         @Override
       
   287         public void process(Helper helper) {
       
   288             helper.compOpts.put("-prompt", "-prompt");
       
   289             helper.promptOnError = true;
       
   290         }
       
   291     },
       
   292 
       
   293     QUIET("-quiet") {
       
   294         @Override
       
   295         public void process(Helper helper) {
       
   296             helper.quiet = true;
       
   297         }
       
   298     },
       
   299 
       
   300     VERBOSE("-verbose") {
       
   301         @Override
       
   302         public void process(Helper helper) {
       
   303             helper.compOpts.put("-verbose", "");
       
   304         }
       
   305     },
       
   306 
       
   307     XWERROR("-Xwerror") {
       
   308         @Override
       
   309         public void process(Helper helper) {
       
   310             helper.rejectWarnings = true;
       
   311 
       
   312         }
       
   313     },
       
   314 
       
   315     // ----- other options -----
       
   316 
       
   317     BREAKITERATOR("-breakiterator") {
       
   318         @Override
       
   319         public void process(Helper helper) {
       
   320             helper.breakiterator = true;
       
   321         }
       
   322     },
       
   323 
       
   324     LOCALE("-locale", true) {
       
   325         @Override
       
   326         public void process(Helper helper, String arg) {
       
   327             helper.docLocale = arg;
       
   328         }
       
   329     },
       
   330 
       
   331     OVERVIEW("-overview", true),
       
   332 
       
   333     XCLASSES("-Xclasses") {
       
   334         @Override
       
   335         public void process(Helper helper) {
       
   336             helper.docClasses = true;
       
   337 
       
   338         }
       
   339     },
       
   340 
       
   341     // ----- help options -----
       
   342 
       
   343     HELP("-help") {
       
   344         @Override
       
   345         public void process(Helper helper) {
       
   346             helper.usage();
       
   347         }
       
   348     },
       
   349 
       
   350     X("-X") {
       
   351         @Override
       
   352         public void process(Helper helper) {
       
   353             helper.Xusage();
       
   354         }
       
   355     };
       
   356 
       
   357     public final String opt;
       
   358     public final boolean hasArg;
       
   359 
       
   360     ToolOption(String opt) {
       
   361         this(opt, false);
       
   362     }
       
   363 
       
   364     ToolOption(String opt, boolean hasArg) {
       
   365         this.opt = opt;
       
   366         this.hasArg = hasArg;
       
   367     }
       
   368 
       
   369     void process(Helper helper, String arg) throws Option.InvalidValueException { }
       
   370 
       
   371     void process(Helper helper) { }
       
   372 
       
   373     static ToolOption get(String name) {
       
   374         for (ToolOption o: values()) {
       
   375             if (name.equals(o.opt))
       
   376                 return o;
       
   377         }
       
   378         return null;
       
   379     }
       
   380 
       
   381     static abstract class Helper {
       
   382         /** List of decoded options. */
       
   383         final ListBuffer<String[]> options = new ListBuffer<>();
       
   384 
       
   385         /** Selected packages, from -subpackages. */
       
   386         final ListBuffer<String> subPackages = new ListBuffer<>();
       
   387 
       
   388         /** Excluded packages, from -exclude. */
       
   389         final ListBuffer<String> excludedPackages = new ListBuffer<>();
       
   390 
       
   391         // File manager options
       
   392         final Map<Option, String> fileManagerOpts = new LinkedHashMap<>();
       
   393 
       
   394         /** javac options, set by various options. */
       
   395         Options compOpts; // = Options.instance(context)
       
   396 
       
   397         /* Encoding for javac, and files written? set by -encoding. */
       
   398         String encoding = null;
       
   399 
       
   400         /** Set by -breakiterator. */
       
   401         boolean breakiterator = false;
       
   402 
       
   403         /** Set by -quiet. */
       
   404         boolean quiet = false;
       
   405 
       
   406         /** Set by -Xclasses. */
       
   407         boolean docClasses = false;
       
   408 
       
   409         /** Set by -Xwerror. */
       
   410         boolean rejectWarnings = false;
       
   411 
       
   412         /** Set by -prompt. */
       
   413         boolean promptOnError;
       
   414 
       
   415         /** Set by -locale. */
       
   416         String docLocale = "";
       
   417 
       
   418         /** Set by -public, private, -protected, -package. */
       
   419         ModifierFilter showAccess = null;
       
   420 
       
   421         abstract void usage();
       
   422         abstract void Xusage();
       
   423 
       
   424         abstract void usageError(String msg, Object... args);
       
   425         abstract OptionHelper getOptionHelper();
       
   426 
       
   427         void addToList(ListBuffer<String> list, String str){
       
   428             StringTokenizer st = new StringTokenizer(str, ":");
       
   429             String current;
       
   430             while(st.hasMoreTokens()){
       
   431                 current = st.nextToken();
       
   432                 list.append(current);
       
   433             }
       
   434         }
       
   435 
       
   436         void setFilter(long filterBits) {
       
   437             if (showAccess != null) {
       
   438                 usageError("main.incompatible.access.flags");
       
   439             }
       
   440             showAccess = new ModifierFilter(filterBits);
       
   441         }
       
   442 
       
   443         void setCompilerOpt(String opt, String arg) {
       
   444             if (compOpts.get(opt) != null) {
       
   445                 usageError("main.option.already.seen", opt);
       
   446             }
       
   447             compOpts.put(opt, arg);
       
   448         }
       
   449 
       
   450         void setFileManagerOpt(Option opt, String arg) {
       
   451             fileManagerOpts.put(opt, arg);
       
   452         }
       
   453     }
       
   454 }