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

Tue, 14 May 2013 15:04:06 -0700

author
jjg
date
Tue, 14 May 2013 15:04:06 -0700
changeset 1755
ddb4a2bfcd82
parent 1411
467f4f754368
child 1885
d6158f8d7235
permissions
-rw-r--r--

8013852: update reference impl for type-annotations
Reviewed-by: jjg
Contributed-by: wdietl@gmail.com, steve.sides@oracle.com, joel.franck@oracle.com, alex.buckley@oracle.com

     1 /*
     2  * Copyright (c) 2012, 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     EXTDIRS("-extdirs", true) {
    60         @Override
    61         public void process(Helper helper, String arg) {
    62             helper.setCompilerOpt(opt, arg);
    63         }
    64     },
    66     SOURCEPATH("-sourcepath", true) {
    67         @Override
    68         public void process(Helper helper, String arg) {
    69             helper.setCompilerOpt(opt, arg);
    70         }
    71     },
    73     SYSCLASSPATH("-sysclasspath", true) {
    74         @Override
    75         public void process(Helper helper, String arg) {
    76             helper.setCompilerOpt("-bootclasspath", arg);
    77         }
    78     },
    80     ENCODING("-encoding", true) {
    81         @Override
    82         public void process(Helper helper, String arg) {
    83             helper.encoding = arg;
    84             helper.setCompilerOpt(opt, arg);
    85         }
    86     },
    88     SOURCE("-source", true) {
    89         @Override
    90         public void process(Helper helper, String arg) {
    91             helper.setCompilerOpt(opt, arg);
    92         }
    93     },
    95     XMAXERRS("-Xmaxerrs", true) {
    96         @Override
    97         public void process(Helper helper, String arg) {
    98             helper.setCompilerOpt(opt, arg);
    99         }
   100     },
   102     XMAXWARNS("-Xmaxwarns", true) {
   103         @Override
   104         public void process(Helper helper, String arg) {
   105             helper.setCompilerOpt(opt, arg);
   106         }
   107     },
   109     // ----- doclet options -----
   111     DOCLET("-doclet", true), // handled in setDocletInvoker
   113     DOCLETPATH("-docletpath", true), // handled in setDocletInvoker
   115     // ----- selection options -----
   117     SUBPACKAGES("-subpackages", true) {
   118         @Override
   119         public void process(Helper helper, String arg) {
   120             helper.addToList(helper.subPackages, arg);
   121         }
   122     },
   124     EXCLUDE("-exclude", true) {
   125         @Override
   126         public void process(Helper helper, String arg) {
   127             helper.addToList(helper.excludedPackages, arg);
   128         }
   129     },
   131     // ----- filtering options -----
   133     PACKAGE("-package") {
   134         @Override
   135         public void process(Helper helper) {
   136             helper.setFilter(
   137                     Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE);
   138         }
   139     },
   141     PRIVATE("-private") {
   142         @Override
   143         public void process(Helper helper) {
   144             helper.setFilter(ModifierFilter.ALL_ACCESS);
   145         }
   146     },
   148     PROTECTED("-protected") {
   149         @Override
   150         public void process(Helper helper) {
   151             helper.setFilter(Flags.PUBLIC | Flags.PROTECTED);
   152         }
   153     },
   155     PUBLIC("-public") {
   156         @Override
   157         public void process(Helper helper) {
   158             helper.setFilter(Flags.PUBLIC);
   159         }
   160     },
   162     // ----- output control options -----
   164     PROMPT("-prompt") {
   165         @Override
   166         public void process(Helper helper) {
   167             helper.compOpts.put("-prompt", "-prompt");
   168             helper.promptOnError = true;
   169         }
   170     },
   172     QUIET("-quiet") {
   173         @Override
   174         public void process(Helper helper) {
   175             helper.quiet = true;
   176         }
   177     },
   179     VERBOSE("-verbose") {
   180         @Override
   181         public void process(Helper helper) {
   182             helper.compOpts.put("-verbose", "");
   183         }
   184     },
   186     XWERROR("-Xwerror") {
   187         @Override
   188         public void process(Helper helper) {
   189             helper.rejectWarnings = true;
   191         }
   192     },
   194     // ----- other options -----
   196     BREAKITERATOR("-breakiterator") {
   197         @Override
   198         public void process(Helper helper) {
   199             helper.breakiterator = true;
   200         }
   201     },
   203     LOCALE("-locale", true) {
   204         @Override
   205         public void process(Helper helper, String arg) {
   206             helper.docLocale = arg;
   207         }
   208     },
   210     OVERVIEW("-overview", true),
   212     XCLASSES("-Xclasses") {
   213         @Override
   214         public void process(Helper helper) {
   215             helper.docClasses = true;
   217         }
   218     },
   220     // ----- help options -----
   222     HELP("-help") {
   223         @Override
   224         public void process(Helper helper) {
   225             helper.usage();
   226         }
   227     },
   229     X("-X") {
   230         @Override
   231         public void process(Helper helper) {
   232             helper.Xusage();
   233         }
   234     };
   236     public final String opt;
   237     public final boolean hasArg;
   239     ToolOption(String opt) {
   240         this(opt, false);
   241     }
   243     ToolOption(String opt, boolean hasArg) {
   244         this.opt = opt;
   245         this.hasArg = hasArg;
   246     }
   248     void process(Helper helper, String arg) { }
   250     void process(Helper helper) { }
   252     static ToolOption get(String name) {
   253         for (ToolOption o: values()) {
   254             if (name.equals(o.opt))
   255                 return o;
   256         }
   257         return null;
   258     }
   260     static abstract class Helper {
   261         /** List of decoded options. */
   262         final ListBuffer<String[]> options = new ListBuffer<String[]>();
   264         /** Selected packages, from -subpackages. */
   265         final ListBuffer<String> subPackages = new ListBuffer<String>();
   267         /** Excluded packages, from -exclude. */
   268         final ListBuffer<String> excludedPackages = new ListBuffer<String>();
   270         /** javac options, set by various options. */
   271         Options compOpts; // = Options.instance(context)
   273         /* Encoding for javac, and files written? set by -encoding. */
   274         String encoding = null;
   276         /** Set by -breakiterator. */
   277         boolean breakiterator = false;
   279         /** Set by -quiet. */
   280         boolean quiet = false;
   282         /** Set by -Xclasses. */
   283         boolean docClasses = false;
   285         /** Set by -Xwerror. */
   286         boolean rejectWarnings = false;
   288         /** Set by -prompt. */
   289         boolean promptOnError;
   291         /** Set by -locale. */
   292         String docLocale = "";
   294         /** Set by -public, private, -protected, -package. */
   295         ModifierFilter showAccess = null;
   297         abstract void usage();
   298         abstract void Xusage();
   300         abstract void usageError(String msg, Object... args);
   302         protected void addToList(ListBuffer<String> list, String str){
   303             StringTokenizer st = new StringTokenizer(str, ":");
   304             String current;
   305             while(st.hasMoreTokens()){
   306                 current = st.nextToken();
   307                 list.append(current);
   308             }
   309         }
   311         protected void setFilter(long filterBits) {
   312             if (showAccess != null) {
   313                 usageError("main.incompatible.access.flags");
   314             }
   315             showAccess = new ModifierFilter(filterBits);
   316         }
   318         private void setCompilerOpt(String opt, String arg) {
   319             if (compOpts.get(opt) != null) {
   320                 usageError("main.option.already.seen", opt);
   321             }
   322             compOpts.put(opt, arg);
   323         }
   324     }
   325 }

mercurial