src/share/classes/com/sun/tools/javadoc/ToolOption.java

Thu, 04 Aug 2016 23:36:47 -0700

author
asaha
date
Thu, 04 Aug 2016 23:36:47 -0700
changeset 3270
8a30511b2ea4
parent 1885
d6158f8d7235
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8162511: 8u111 L10n resource file updates
Summary: 8u111 L10n resource file updates
Reviewed-by: coffeys
Contributed-by: li.jiang@oracle.com

     1 /*
     2  * Copyright (c) 2012, 2013, 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  */
    26 package com.sun.tools.javadoc;
    28 import com.sun.tools.javac.code.Flags;
    29 import com.sun.tools.javac.util.ListBuffer;
    30 import com.sun.tools.javac.util.Options;
    31 import java.util.StringTokenizer;
    34 /**
    35  * javadoc tool options.
    36  *
    37  *  <p><b>This is NOT part of any supported API.
    38  *  If you write code that depends on this, you do so at your own risk.
    39  *  This code and its internal interfaces are subject to change or
    40  *  deletion without notice.</b>
    41  */
    42 public enum ToolOption {
    43     // ----- options for underlying compiler -----
    45     BOOTCLASSPATH("-bootclasspath", true) {
    46         @Override
    47         public void process(Helper helper, String arg) {
    48             helper.setCompilerOpt(opt, arg);
    49         }
    50     },
    52     CLASSPATH("-classpath", true) {
    53         @Override
    54         public void process(Helper helper, String arg) {
    55             helper.setCompilerOpt(opt, arg);
    56         }
    57     },
    59     CP("-cp", true) {
    60         @Override
    61         public void process(Helper helper, String arg) {
    62             helper.setCompilerOpt(opt, arg);
    63         }
    64     },
    66     EXTDIRS("-extdirs", true) {
    67         @Override
    68         public void process(Helper helper, String arg) {
    69             helper.setCompilerOpt(opt, arg);
    70         }
    71     },
    73     SOURCEPATH("-sourcepath", true) {
    74         @Override
    75         public void process(Helper helper, String arg) {
    76             helper.setCompilerOpt(opt, arg);
    77         }
    78     },
    80     SYSCLASSPATH("-sysclasspath", true) {
    81         @Override
    82         public void process(Helper helper, String arg) {
    83             helper.setCompilerOpt("-bootclasspath", arg);
    84         }
    85     },
    87     ENCODING("-encoding", true) {
    88         @Override
    89         public void process(Helper helper, String arg) {
    90             helper.encoding = arg;
    91             helper.setCompilerOpt(opt, arg);
    92         }
    93     },
    95     SOURCE("-source", true) {
    96         @Override
    97         public void process(Helper helper, String arg) {
    98             helper.setCompilerOpt(opt, arg);
    99         }
   100     },
   102     XMAXERRS("-Xmaxerrs", true) {
   103         @Override
   104         public void process(Helper helper, String arg) {
   105             helper.setCompilerOpt(opt, arg);
   106         }
   107     },
   109     XMAXWARNS("-Xmaxwarns", true) {
   110         @Override
   111         public void process(Helper helper, String arg) {
   112             helper.setCompilerOpt(opt, arg);
   113         }
   114     },
   116     // ----- doclet options -----
   118     DOCLET("-doclet", true), // handled in setDocletInvoker
   120     DOCLETPATH("-docletpath", true), // handled in setDocletInvoker
   122     // ----- selection options -----
   124     SUBPACKAGES("-subpackages", true) {
   125         @Override
   126         public void process(Helper helper, String arg) {
   127             helper.addToList(helper.subPackages, arg);
   128         }
   129     },
   131     EXCLUDE("-exclude", true) {
   132         @Override
   133         public void process(Helper helper, String arg) {
   134             helper.addToList(helper.excludedPackages, arg);
   135         }
   136     },
   138     // ----- filtering options -----
   140     PACKAGE("-package") {
   141         @Override
   142         public void process(Helper helper) {
   143             helper.setFilter(
   144                     Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE);
   145         }
   146     },
   148     PRIVATE("-private") {
   149         @Override
   150         public void process(Helper helper) {
   151             helper.setFilter(ModifierFilter.ALL_ACCESS);
   152         }
   153     },
   155     PROTECTED("-protected") {
   156         @Override
   157         public void process(Helper helper) {
   158             helper.setFilter(Flags.PUBLIC | Flags.PROTECTED);
   159         }
   160     },
   162     PUBLIC("-public") {
   163         @Override
   164         public void process(Helper helper) {
   165             helper.setFilter(Flags.PUBLIC);
   166         }
   167     },
   169     // ----- output control options -----
   171     PROMPT("-prompt") {
   172         @Override
   173         public void process(Helper helper) {
   174             helper.compOpts.put("-prompt", "-prompt");
   175             helper.promptOnError = true;
   176         }
   177     },
   179     QUIET("-quiet") {
   180         @Override
   181         public void process(Helper helper) {
   182             helper.quiet = true;
   183         }
   184     },
   186     VERBOSE("-verbose") {
   187         @Override
   188         public void process(Helper helper) {
   189             helper.compOpts.put("-verbose", "");
   190         }
   191     },
   193     XWERROR("-Xwerror") {
   194         @Override
   195         public void process(Helper helper) {
   196             helper.rejectWarnings = true;
   198         }
   199     },
   201     // ----- other options -----
   203     BREAKITERATOR("-breakiterator") {
   204         @Override
   205         public void process(Helper helper) {
   206             helper.breakiterator = true;
   207         }
   208     },
   210     LOCALE("-locale", true) {
   211         @Override
   212         public void process(Helper helper, String arg) {
   213             helper.docLocale = arg;
   214         }
   215     },
   217     OVERVIEW("-overview", true),
   219     XCLASSES("-Xclasses") {
   220         @Override
   221         public void process(Helper helper) {
   222             helper.docClasses = true;
   224         }
   225     },
   227     // ----- help options -----
   229     HELP("-help") {
   230         @Override
   231         public void process(Helper helper) {
   232             helper.usage();
   233         }
   234     },
   236     X("-X") {
   237         @Override
   238         public void process(Helper helper) {
   239             helper.Xusage();
   240         }
   241     };
   243     public final String opt;
   244     public final boolean hasArg;
   246     ToolOption(String opt) {
   247         this(opt, false);
   248     }
   250     ToolOption(String opt, boolean hasArg) {
   251         this.opt = opt;
   252         this.hasArg = hasArg;
   253     }
   255     void process(Helper helper, String arg) { }
   257     void process(Helper helper) { }
   259     static ToolOption get(String name) {
   260         for (ToolOption o: values()) {
   261             if (name.equals(o.opt))
   262                 return o;
   263         }
   264         return null;
   265     }
   267     static abstract class Helper {
   268         /** List of decoded options. */
   269         final ListBuffer<String[]> options = new ListBuffer<String[]>();
   271         /** Selected packages, from -subpackages. */
   272         final ListBuffer<String> subPackages = new ListBuffer<String>();
   274         /** Excluded packages, from -exclude. */
   275         final ListBuffer<String> excludedPackages = new ListBuffer<String>();
   277         /** javac options, set by various options. */
   278         Options compOpts; // = Options.instance(context)
   280         /* Encoding for javac, and files written? set by -encoding. */
   281         String encoding = null;
   283         /** Set by -breakiterator. */
   284         boolean breakiterator = false;
   286         /** Set by -quiet. */
   287         boolean quiet = false;
   289         /** Set by -Xclasses. */
   290         boolean docClasses = false;
   292         /** Set by -Xwerror. */
   293         boolean rejectWarnings = false;
   295         /** Set by -prompt. */
   296         boolean promptOnError;
   298         /** Set by -locale. */
   299         String docLocale = "";
   301         /** Set by -public, private, -protected, -package. */
   302         ModifierFilter showAccess = null;
   304         abstract void usage();
   305         abstract void Xusage();
   307         abstract void usageError(String msg, Object... args);
   309         protected void addToList(ListBuffer<String> list, String str){
   310             StringTokenizer st = new StringTokenizer(str, ":");
   311             String current;
   312             while(st.hasMoreTokens()){
   313                 current = st.nextToken();
   314                 list.append(current);
   315             }
   316         }
   318         protected void setFilter(long filterBits) {
   319             if (showAccess != null) {
   320                 usageError("main.incompatible.access.flags");
   321             }
   322             showAccess = new ModifierFilter(filterBits);
   323         }
   325         private void setCompilerOpt(String opt, String arg) {
   326             if (compOpts.get(opt) != null) {
   327                 usageError("main.option.already.seen", opt);
   328             }
   329             compOpts.put(opt, arg);
   330         }
   331     }
   332 }

mercurial