8003257: refactor javadoc tool option handling

Thu, 15 Nov 2012 14:41:31 -0800

author
jjg
date
Thu, 15 Nov 2012 14:41:31 -0800
changeset 1411
467f4f754368
parent 1410
bfec2a1cc869
child 1412
400a4e8accd3

8003257: refactor javadoc tool option handling
Reviewed-by: darcy

src/share/classes/com/sun/tools/javadoc/DocEnv.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/DocLocale.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/DocletInvoker.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/JavadocTool.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/Messager.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/Start.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/ToolOption.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javadoc/DocEnv.java	Thu Nov 15 09:18:36 2012 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javadoc/DocEnv.java	Thu Nov 15 14:41:31 2012 -0800
     1.3 @@ -211,8 +211,8 @@
     1.4      public void setLocale(String localeName) {
     1.5          // create locale specifics
     1.6          doclocale = new DocLocale(this, localeName, breakiterator);
     1.7 -        // reset Messager if locale has changed.
     1.8 -        messager.reset();
     1.9 +        // update Messager if locale has changed.
    1.10 +        messager.setLocale(doclocale.locale);
    1.11      }
    1.12  
    1.13      /** Check whether this member should be documented. */
     2.1 --- a/src/share/classes/com/sun/tools/javadoc/DocLocale.java	Thu Nov 15 09:18:36 2012 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javadoc/DocLocale.java	Thu Nov 15 14:41:31 2012 -0800
     2.3 @@ -49,7 +49,7 @@
     2.4      final String localeName;
     2.5  
     2.6      /**
     2.7 -     * The locale to be used. If user doesen't provide this,
     2.8 +     * The locale to be used. If user doesn't provide this,
     2.9       * then set it to default locale value.
    2.10       */
    2.11      final Locale locale;
    2.12 @@ -98,7 +98,7 @@
    2.13          if (locale == null) {
    2.14              docenv.exit();
    2.15          } else {
    2.16 -            Locale.setDefault(locale);
    2.17 +            Locale.setDefault(locale); // NOTE: updating global state
    2.18          }
    2.19          collator = Collator.getInstance(locale);
    2.20          sentenceBreaker = BreakIterator.getSentenceInstance(locale);
     3.1 --- a/src/share/classes/com/sun/tools/javadoc/DocletInvoker.java	Thu Nov 15 09:18:36 2012 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javadoc/DocletInvoker.java	Thu Nov 15 14:41:31 2012 -0800
     3.3 @@ -95,7 +95,7 @@
     3.4          try {
     3.5              dc = appClassLoader.loadClass(docletClassName);
     3.6          } catch (ClassNotFoundException exc) {
     3.7 -            messager.error(null, "main.doclet_class_not_found", docletClassName);
     3.8 +            messager.error(Messager.NOPOS, "main.doclet_class_not_found", docletClassName);
     3.9              messager.exit();
    3.10          }
    3.11          docletClass = dc;
    3.12 @@ -168,7 +168,7 @@
    3.13          if (retVal instanceof Boolean) {
    3.14              return ((Boolean)retVal).booleanValue();
    3.15          } else {
    3.16 -            messager.error(null, "main.must_return_boolean",
    3.17 +            messager.error(Messager.NOPOS, "main.must_return_boolean",
    3.18                             docletClassName, methodName);
    3.19              return false;
    3.20          }
    3.21 @@ -192,7 +192,7 @@
    3.22          if (retVal instanceof Integer) {
    3.23              return ((Integer)retVal).intValue();
    3.24          } else {
    3.25 -            messager.error(null, "main.must_return_int",
    3.26 +            messager.error(Messager.NOPOS, "main.must_return_int",
    3.27                             docletClassName, methodName);
    3.28              return -1;
    3.29          }
    3.30 @@ -217,7 +217,7 @@
    3.31          if (retVal instanceof Boolean) {
    3.32              return ((Boolean)retVal).booleanValue();
    3.33          } else {
    3.34 -            messager.error(null, "main.must_return_boolean",
    3.35 +            messager.error(Messager.NOPOS, "main.must_return_boolean",
    3.36                             docletClassName, methodName);
    3.37              return false;
    3.38          }
    3.39 @@ -241,7 +241,7 @@
    3.40              if (retVal instanceof LanguageVersion) {
    3.41                  return (LanguageVersion)retVal;
    3.42              } else {
    3.43 -                messager.error(null, "main.must_return_languageversion",
    3.44 +                messager.error(Messager.NOPOS, "main.must_return_languageversion",
    3.45                                 docletClassName, methodName);
    3.46                  return JAVA_1_1;
    3.47              }
    3.48 @@ -261,19 +261,19 @@
    3.49                  meth = docletClass.getMethod(methodName, paramTypes);
    3.50              } catch (NoSuchMethodException exc) {
    3.51                  if (returnValueIfNonExistent == null) {
    3.52 -                    messager.error(null, "main.doclet_method_not_found",
    3.53 +                    messager.error(Messager.NOPOS, "main.doclet_method_not_found",
    3.54                                     docletClassName, methodName);
    3.55                      throw new DocletInvokeException();
    3.56                  } else {
    3.57                      return returnValueIfNonExistent;
    3.58                  }
    3.59              } catch (SecurityException exc) {
    3.60 -                messager.error(null, "main.doclet_method_not_accessible",
    3.61 +                messager.error(Messager.NOPOS, "main.doclet_method_not_accessible",
    3.62                                 docletClassName, methodName);
    3.63                  throw new DocletInvokeException();
    3.64              }
    3.65              if (!Modifier.isStatic(meth.getModifiers())) {
    3.66 -                messager.error(null, "main.doclet_method_must_be_static",
    3.67 +                messager.error(Messager.NOPOS, "main.doclet_method_must_be_static",
    3.68                                 docletClassName, methodName);
    3.69                  throw new DocletInvokeException();
    3.70              }
    3.71 @@ -283,23 +283,23 @@
    3.72                  Thread.currentThread().setContextClassLoader(appClassLoader);
    3.73                  return meth.invoke(null , params);
    3.74              } catch (IllegalArgumentException exc) {
    3.75 -                messager.error(null, "main.internal_error_exception_thrown",
    3.76 +                messager.error(Messager.NOPOS, "main.internal_error_exception_thrown",
    3.77                                 docletClassName, methodName, exc.toString());
    3.78                  throw new DocletInvokeException();
    3.79              } catch (IllegalAccessException exc) {
    3.80 -                messager.error(null, "main.doclet_method_not_accessible",
    3.81 +                messager.error(Messager.NOPOS, "main.doclet_method_not_accessible",
    3.82                                 docletClassName, methodName);
    3.83                  throw new DocletInvokeException();
    3.84              } catch (NullPointerException exc) {
    3.85 -                messager.error(null, "main.internal_error_exception_thrown",
    3.86 +                messager.error(Messager.NOPOS, "main.internal_error_exception_thrown",
    3.87                                 docletClassName, methodName, exc.toString());
    3.88                  throw new DocletInvokeException();
    3.89              } catch (InvocationTargetException exc) {
    3.90                  Throwable err = exc.getTargetException();
    3.91                  if (err instanceof java.lang.OutOfMemoryError) {
    3.92 -                    messager.error(null, "main.out.of.memory");
    3.93 +                    messager.error(Messager.NOPOS, "main.out.of.memory");
    3.94                  } else {
    3.95 -                messager.error(null, "main.exception_thrown",
    3.96 +                messager.error(Messager.NOPOS, "main.exception_thrown",
    3.97                                 docletClassName, methodName, exc.toString());
    3.98                      exc.getTargetException().printStackTrace();
    3.99                  }
     4.1 --- a/src/share/classes/com/sun/tools/javadoc/JavadocTool.java	Thu Nov 15 09:18:36 2012 -0800
     4.2 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocTool.java	Thu Nov 15 14:41:31 2012 -0800
     4.3 @@ -38,7 +38,6 @@
     4.4  import javax.tools.StandardLocation;
     4.5  
     4.6  import com.sun.tools.javac.code.Symbol.CompletionFailure;
     4.7 -import com.sun.tools.javac.comp.Annotate;
     4.8  import com.sun.tools.javac.tree.JCTree;
     4.9  import com.sun.tools.javac.tree.JCTree.JCClassDecl;
    4.10  import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
    4.11 @@ -65,11 +64,9 @@
    4.12  public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
    4.13      DocEnv docenv;
    4.14  
    4.15 -    final Context context;
    4.16      final Messager messager;
    4.17 -    final JavadocClassReader reader;
    4.18 -    final JavadocEnter enter;
    4.19 -    final Annotate annotate;
    4.20 +    final JavadocClassReader javadocReader;
    4.21 +    final JavadocEnter javadocEnter;
    4.22  
    4.23      /**
    4.24       * Construct a new JavaCompiler processor, using appropriately
    4.25 @@ -77,11 +74,9 @@
    4.26       */
    4.27      protected JavadocTool(Context context) {
    4.28          super(context);
    4.29 -        this.context = context;
    4.30          messager = Messager.instance0(context);
    4.31 -        reader = JavadocClassReader.instance0(context);
    4.32 -        enter = JavadocEnter.instance0(context);
    4.33 -        annotate = Annotate.instance(context);
    4.34 +        javadocReader = JavadocClassReader.instance0(context);
    4.35 +        javadocEnter = JavadocEnter.instance0(context);
    4.36      }
    4.37  
    4.38      /**
    4.39 @@ -138,7 +133,7 @@
    4.40          docenv.setEncoding(encoding);
    4.41          docenv.docClasses = docClasses;
    4.42          docenv.legacyDoclet = legacyDoclet;
    4.43 -        reader.sourceCompleter = docClasses ? null : this;
    4.44 +        javadocReader.sourceCompleter = docClasses ? null : this;
    4.45  
    4.46          ListBuffer<String> names = new ListBuffer<String>();
    4.47          ListBuffer<JCCompilationUnit> classTrees = new ListBuffer<JCCompilationUnit>();
    4.48 @@ -156,7 +151,7 @@
    4.49                  } else if (isValidPackageName(name)) {
    4.50                      names = names.append(name);
    4.51                  } else if (name.endsWith(".java")) {
    4.52 -                    docenv.error(null, "main.file_not_found", name);
    4.53 +                        docenv.error(null, "main.file_not_found", name);
    4.54                  } else {
    4.55                      docenv.error(null, "main.illegal_package_name", name);
    4.56                  }
    4.57 @@ -179,7 +174,7 @@
    4.58  
    4.59                  // Enter symbols for all files
    4.60                  docenv.notice("main.Building_tree");
    4.61 -                enter.main(classTrees.toList().appendList(packTrees.toList()));
    4.62 +                javadocEnter.main(classTrees.toList().appendList(packTrees.toList()));
    4.63              }
    4.64          } catch (Abort ex) {}
    4.65  
    4.66 @@ -240,7 +235,7 @@
    4.67          }
    4.68  
    4.69          if (!hasFiles) {
    4.70 -            messager.warning(null, "main.no_source_files_for_package",
    4.71 +            messager.warning(Messager.NOPOS, "main.no_source_files_for_package",
    4.72                      name.replace(File.separatorChar, '.'));
    4.73          }
    4.74      }
     5.1 --- a/src/share/classes/com/sun/tools/javadoc/Messager.java	Thu Nov 15 09:18:36 2012 -0800
     5.2 +++ b/src/share/classes/com/sun/tools/javadoc/Messager.java	Thu Nov 15 14:41:31 2012 -0800
     5.3 @@ -25,13 +25,15 @@
     5.4  
     5.5  package com.sun.tools.javadoc;
     5.6  
     5.7 -import java.io.PrintWriter;  // Access to 'javac' output streams
     5.8 +import java.io.PrintWriter;
     5.9  import java.text.MessageFormat;
    5.10 -import java.util.MissingResourceException;
    5.11 +import java.util.Locale;
    5.12  import java.util.ResourceBundle;
    5.13  
    5.14  import com.sun.javadoc.*;
    5.15  import com.sun.tools.javac.util.Context;
    5.16 +import com.sun.tools.javac.util.JCDiagnostic;
    5.17 +import com.sun.tools.javac.util.JavacMessages;
    5.18  import com.sun.tools.javac.util.Log;
    5.19  
    5.20  /**
    5.21 @@ -51,6 +53,7 @@
    5.22   * @author Neal Gafter (rewrite)
    5.23   */
    5.24  public class Messager extends Log implements DocErrorReporter {
    5.25 +    public static final SourcePosition NOPOS = null;
    5.26  
    5.27      /** Get the current messager, which is also the compiler log. */
    5.28      public static Messager instance0(Context context) {
    5.29 @@ -91,7 +94,9 @@
    5.30  
    5.31      final String programName;
    5.32  
    5.33 -    private ResourceBundle messageRB = null;
    5.34 +    private Locale locale;
    5.35 +    private final JavacMessages messages;
    5.36 +    private final JCDiagnostic.Factory javadocDiags;
    5.37  
    5.38      /** The default writer for diagnostics
    5.39       */
    5.40 @@ -121,6 +126,9 @@
    5.41                         PrintWriter warnWriter,
    5.42                         PrintWriter noticeWriter) {
    5.43          super(context, errWriter, warnWriter, noticeWriter);
    5.44 +        messages = JavacMessages.instance(context);
    5.45 +        messages.add("com.sun.tools.javadoc.resources.javadoc");
    5.46 +        javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
    5.47          this.programName = programName;
    5.48      }
    5.49  
    5.50 @@ -134,94 +142,18 @@
    5.51          return Integer.MAX_VALUE;
    5.52      }
    5.53  
    5.54 -    /**
    5.55 -     * Reset resource bundle, eg. locale has changed.
    5.56 -     */
    5.57 -    public void reset() {
    5.58 -        messageRB = null;
    5.59 -    }
    5.60 -
    5.61 -    /**
    5.62 -     * Get string from ResourceBundle, initialize ResourceBundle
    5.63 -     * if needed.
    5.64 -     */
    5.65 -    private String getString(String key) {
    5.66 -        if (messageRB == null) {
    5.67 -            try {
    5.68 -                messageRB = ResourceBundle.getBundle(
    5.69 -                          "com.sun.tools.javadoc.resources.javadoc");
    5.70 -            } catch (MissingResourceException e) {
    5.71 -                throw new Error("Fatal: Resource for javadoc is missing");
    5.72 -            }
    5.73 -        }
    5.74 -        return messageRB.getString(key);
    5.75 +    public void setLocale(Locale locale) {
    5.76 +        this.locale = locale;
    5.77      }
    5.78  
    5.79      /**
    5.80       * get and format message string from resource
    5.81       *
    5.82       * @param key selects message from resource
    5.83 +     * @param args arguments for the message
    5.84       */
    5.85 -    String getText(String key) {
    5.86 -        return getText(key, (String)null);
    5.87 -    }
    5.88 -
    5.89 -    /**
    5.90 -     * get and format message string from resource
    5.91 -     *
    5.92 -     * @param key selects message from resource
    5.93 -     * @param a1 first argument
    5.94 -     */
    5.95 -    String getText(String key, String a1) {
    5.96 -        return getText(key, a1, null);
    5.97 -    }
    5.98 -
    5.99 -    /**
   5.100 -     * get and format message string from resource
   5.101 -     *
   5.102 -     * @param key selects message from resource
   5.103 -     * @param a1 first argument
   5.104 -     * @param a2 second argument
   5.105 -     */
   5.106 -    String getText(String key, String a1, String a2) {
   5.107 -        return getText(key, a1, a2, null);
   5.108 -    }
   5.109 -
   5.110 -    /**
   5.111 -     * get and format message string from resource
   5.112 -     *
   5.113 -     * @param key selects message from resource
   5.114 -     * @param a1 first argument
   5.115 -     * @param a2 second argument
   5.116 -     * @param a3 third argument
   5.117 -     */
   5.118 -    String getText(String key, String a1, String a2, String a3) {
   5.119 -        return getText(key, a1, a2, a3, null);
   5.120 -    }
   5.121 -
   5.122 -    /**
   5.123 -     * get and format message string from resource
   5.124 -     *
   5.125 -     * @param key selects message from resource
   5.126 -     * @param a1 first argument
   5.127 -     * @param a2 second argument
   5.128 -     * @param a3 third argument
   5.129 -     * @param a4 fourth argument
   5.130 -     */
   5.131 -    String getText(String key, String a1, String a2, String a3,
   5.132 -                          String a4) {
   5.133 -        try {
   5.134 -            String message = getString(key);
   5.135 -            String[] args = new String[4];
   5.136 -            args[0] = a1;
   5.137 -            args[1] = a2;
   5.138 -            args[2] = a3;
   5.139 -            args[3] = a4;
   5.140 -            return MessageFormat.format(message, (Object[])args);
   5.141 -        } catch (MissingResourceException e) {
   5.142 -            return "********** Resource for javadoc is broken. There is no " +
   5.143 -                key + " key in resource.";
   5.144 -        }
   5.145 +    String getText(String key, Object... args) {
   5.146 +        return messages.getLocalizedString(locale, key, args);
   5.147      }
   5.148  
   5.149      /**
   5.150 @@ -307,41 +239,8 @@
   5.151       *
   5.152       * @param key selects message from resource
   5.153       */
   5.154 -    public void error(SourcePosition pos, String key) {
   5.155 -        printError(pos, getText(key));
   5.156 -    }
   5.157 -
   5.158 -    /**
   5.159 -     * Print error message, increment error count.
   5.160 -     *
   5.161 -     * @param key selects message from resource
   5.162 -     * @param a1 first argument
   5.163 -     */
   5.164 -    public void error(SourcePosition pos, String key, String a1) {
   5.165 -        printError(pos, getText(key, a1));
   5.166 -    }
   5.167 -
   5.168 -    /**
   5.169 -     * Print error message, increment error count.
   5.170 -     *
   5.171 -     * @param key selects message from resource
   5.172 -     * @param a1 first argument
   5.173 -     * @param a2 second argument
   5.174 -     */
   5.175 -    public void error(SourcePosition pos, String key, String a1, String a2) {
   5.176 -        printError(pos, getText(key, a1, a2));
   5.177 -    }
   5.178 -
   5.179 -    /**
   5.180 -     * Print error message, increment error count.
   5.181 -     *
   5.182 -     * @param key selects message from resource
   5.183 -     * @param a1 first argument
   5.184 -     * @param a2 second argument
   5.185 -     * @param a3 third argument
   5.186 -     */
   5.187 -    public void error(SourcePosition pos, String key, String a1, String a2, String a3) {
   5.188 -        printError(pos, getText(key, a1, a2, a3));
   5.189 +    public void error(SourcePosition pos, String key, Object... args) {
   5.190 +        printError(pos, getText(key, args));
   5.191      }
   5.192  
   5.193      /**
   5.194 @@ -349,54 +248,8 @@
   5.195       *
   5.196       * @param key selects message from resource
   5.197       */
   5.198 -    public void warning(SourcePosition pos, String key) {
   5.199 -        printWarning(pos, getText(key));
   5.200 -    }
   5.201 -
   5.202 -    /**
   5.203 -     * Print warning message, increment warning count.
   5.204 -     *
   5.205 -     * @param key selects message from resource
   5.206 -     * @param a1 first argument
   5.207 -     */
   5.208 -    public void warning(SourcePosition pos, String key, String a1) {
   5.209 -        printWarning(pos, getText(key, a1));
   5.210 -    }
   5.211 -
   5.212 -    /**
   5.213 -     * Print warning message, increment warning count.
   5.214 -     *
   5.215 -     * @param key selects message from resource
   5.216 -     * @param a1 first argument
   5.217 -     * @param a2 second argument
   5.218 -     */
   5.219 -    public void warning(SourcePosition pos, String key, String a1, String a2) {
   5.220 -        printWarning(pos, getText(key, a1, a2));
   5.221 -    }
   5.222 -
   5.223 -    /**
   5.224 -     * Print warning message, increment warning count.
   5.225 -     *
   5.226 -     * @param key selects message from resource
   5.227 -     * @param a1 first argument
   5.228 -     * @param a2 second argument
   5.229 -     * @param a3 third argument
   5.230 -     */
   5.231 -    public void warning(SourcePosition pos, String key, String a1, String a2, String a3) {
   5.232 -        printWarning(pos, getText(key, a1, a2, a3));
   5.233 -    }
   5.234 -
   5.235 -    /**
   5.236 -     * Print warning message, increment warning count.
   5.237 -     *
   5.238 -     * @param key selects message from resource
   5.239 -     * @param a1 first argument
   5.240 -     * @param a2 second argument
   5.241 -     * @param a3 third argument
   5.242 -     */
   5.243 -    public void warning(SourcePosition pos, String key, String a1, String a2, String a3,
   5.244 -                        String a4) {
   5.245 -        printWarning(pos, getText(key, a1, a2, a3, a4));
   5.246 +    public void warning(SourcePosition pos, String key, Object... args) {
   5.247 +        printWarning(pos, getText(key, args));
   5.248      }
   5.249  
   5.250      /**
   5.251 @@ -404,41 +257,8 @@
   5.252       *
   5.253       * @param key selects message from resource
   5.254       */
   5.255 -    public void notice(String key) {
   5.256 -        printNotice(getText(key));
   5.257 -    }
   5.258 -
   5.259 -    /**
   5.260 -     * Print a message.
   5.261 -     *
   5.262 -     * @param key selects message from resource
   5.263 -     * @param a1 first argument
   5.264 -     */
   5.265 -    public void notice(String key, String a1) {
   5.266 -        printNotice(getText(key, a1));
   5.267 -    }
   5.268 -
   5.269 -    /**
   5.270 -     * Print a message.
   5.271 -     *
   5.272 -     * @param key selects message from resource
   5.273 -     * @param a1 first argument
   5.274 -     * @param a2 second argument
   5.275 -     */
   5.276 -    public void notice(String key, String a1, String a2) {
   5.277 -        printNotice(getText(key, a1, a2));
   5.278 -    }
   5.279 -
   5.280 -    /**
   5.281 -     * Print a message.
   5.282 -     *
   5.283 -     * @param key selects message from resource
   5.284 -     * @param a1 first argument
   5.285 -     * @param a2 second argument
   5.286 -     * @param a3 third argument
   5.287 -     */
   5.288 -    public void notice(String key, String a1, String a2, String a3) {
   5.289 -        printNotice(getText(key, a1, a2, a3));
   5.290 +    public void notice(String key, Object... args) {
   5.291 +        printNotice(getText(key, args));
   5.292      }
   5.293  
   5.294      /**
   5.295 @@ -475,5 +295,4 @@
   5.296      public void exit() {
   5.297          throw new ExitJavadoc();
   5.298      }
   5.299 -
   5.300  }
     6.1 --- a/src/share/classes/com/sun/tools/javadoc/Start.java	Thu Nov 15 09:18:36 2012 -0800
     6.2 +++ b/src/share/classes/com/sun/tools/javadoc/Start.java	Thu Nov 15 14:41:31 2012 -0800
     6.3 @@ -29,7 +29,6 @@
     6.4  import java.io.FileNotFoundException;
     6.5  import java.io.IOException;
     6.6  import java.io.PrintWriter;
     6.7 -import java.util.StringTokenizer;
     6.8  
     6.9  import com.sun.javadoc.*;
    6.10  import com.sun.tools.javac.main.CommandLine;
    6.11 @@ -53,7 +52,7 @@
    6.12   * @author Robert Field
    6.13   * @author Neal Gafter (rewrite)
    6.14   */
    6.15 -class Start {
    6.16 +public class Start extends ToolOption.Helper {
    6.17      /** Context for this invocation. */
    6.18      private final Context context;
    6.19  
    6.20 @@ -65,25 +64,12 @@
    6.21      private static final String standardDocletClassName =
    6.22          "com.sun.tools.doclets.standard.Standard";
    6.23  
    6.24 -    private ListBuffer<String[]> options = new ListBuffer<String[]>();
    6.25 -
    6.26 -    private ModifierFilter showAccess = null;
    6.27 -
    6.28      private long defaultFilter = PUBLIC | PROTECTED;
    6.29  
    6.30      private final Messager messager;
    6.31  
    6.32 -    String docLocale = "";
    6.33 -
    6.34 -    boolean breakiterator = false;
    6.35 -    boolean quiet = false;
    6.36 -    String encoding = null;
    6.37 -
    6.38      private DocletInvoker docletInvoker;
    6.39  
    6.40 -    /* Treat warnings as errors. */
    6.41 -    private boolean rejectWarnings = false;
    6.42 -
    6.43      Start(String programName,
    6.44            PrintWriter errWriter,
    6.45            PrintWriter warnWriter,
    6.46 @@ -132,23 +118,58 @@
    6.47          this(javadocName);
    6.48      }
    6.49  
    6.50 +    public Start(Context context) {
    6.51 +        context.getClass(); // null check
    6.52 +        this.context = context;
    6.53 +        defaultDocletClassName = standardDocletClassName;
    6.54 +        docletParentClassLoader = null;
    6.55 +
    6.56 +        Log log = context.get(Log.logKey);
    6.57 +        if (log instanceof Messager)
    6.58 +            messager = (Messager) log;
    6.59 +        else {
    6.60 +            PrintWriter out = context.get(Log.outKey);
    6.61 +            messager = (out == null) ? new Messager(context, javadocName)
    6.62 +                    : new Messager(context, javadocName, out, out, out);
    6.63 +        }
    6.64 +    }
    6.65 +
    6.66      /**
    6.67       * Usage
    6.68       */
    6.69 -    private void usage() {
    6.70 +    @Override
    6.71 +    void usage() {
    6.72 +        usage(true);
    6.73 +    }
    6.74 +
    6.75 +
    6.76 +    /**
    6.77 +     * Usage
    6.78 +     */
    6.79 +    private void usage(boolean exit) {
    6.80 +        // RFE: it would be better to replace the following with code to
    6.81 +        // write a header, then help for each option, then a footer.
    6.82          messager.notice("main.usage");
    6.83  
    6.84          // let doclet print usage information (does nothing on error)
    6.85          if (docletInvoker != null) {
    6.86              docletInvoker.optionLength("-help");
    6.87          }
    6.88 +
    6.89 +        if (exit) exit();
    6.90 +    }
    6.91 +
    6.92 +    @Override
    6.93 +    void Xusage() {
    6.94 +        Xusage(true);
    6.95      }
    6.96  
    6.97      /**
    6.98       * Usage
    6.99       */
   6.100 -    private void Xusage() {
   6.101 +    private void Xusage(boolean exit) {
   6.102          messager.notice("main.Xusage");
   6.103 +        if (exit) exit();
   6.104      }
   6.105  
   6.106      /**
   6.107 @@ -167,18 +188,18 @@
   6.108  
   6.109          try {
   6.110              failed = !parseAndExecute(argv);
   6.111 -        } catch(Messager.ExitJavadoc exc) {
   6.112 +        } catch (Messager.ExitJavadoc exc) {
   6.113              // ignore, we just exit this way
   6.114          } catch (OutOfMemoryError ee) {
   6.115 -            messager.error(null, "main.out.of.memory");
   6.116 +            messager.error(Messager.NOPOS, "main.out.of.memory");
   6.117              failed = true;
   6.118          } catch (Error ee) {
   6.119              ee.printStackTrace(System.err);
   6.120 -            messager.error(null, "main.fatal.error");
   6.121 +            messager.error(Messager.NOPOS, "main.fatal.error");
   6.122              failed = true;
   6.123          } catch (Exception ee) {
   6.124              ee.printStackTrace(System.err);
   6.125 -            messager.error(null, "main.fatal.exception");
   6.126 +            messager.error(Messager.NOPOS, "main.fatal.exception");
   6.127              failed = true;
   6.128          } finally {
   6.129              messager.exitNotice();
   6.130 @@ -189,15 +210,6 @@
   6.131          return failed ? 1 : 0;
   6.132      }
   6.133  
   6.134 -    private void addToList(ListBuffer<String> list, String str){
   6.135 -        StringTokenizer st = new StringTokenizer(str, ":");
   6.136 -        String current;
   6.137 -        while(st.hasMoreTokens()){
   6.138 -            current = st.nextToken();
   6.139 -            list.append(current);
   6.140 -        }
   6.141 -    }
   6.142 -
   6.143      /**
   6.144       * Main program - internal
   6.145       */
   6.146 @@ -210,7 +222,7 @@
   6.147          try {
   6.148              argv = CommandLine.parse(argv);
   6.149          } catch (FileNotFoundException e) {
   6.150 -            messager.error(null, "main.cant.read", e.getMessage());
   6.151 +            messager.error(Messager.NOPOS, "main.cant.read", e.getMessage());
   6.152              exit();
   6.153          } catch (IOException e) {
   6.154              e.printStackTrace(System.err);
   6.155 @@ -218,116 +230,29 @@
   6.156          }
   6.157  
   6.158          setDocletInvoker(argv);
   6.159 -        ListBuffer<String> subPackages = new ListBuffer<String>();
   6.160 -        ListBuffer<String> excludedPackages = new ListBuffer<String>();
   6.161  
   6.162 -        Options compOpts = Options.instance(context);
   6.163 -        boolean docClasses = false;
   6.164 +        compOpts = Options.instance(context);
   6.165  
   6.166          // Parse arguments
   6.167          for (int i = 0 ; i < argv.length ; i++) {
   6.168              String arg = argv[i];
   6.169 -            if (arg.equals("-subpackages")) {
   6.170 -                oneArg(argv, i++);
   6.171 -                addToList(subPackages, argv[i]);
   6.172 -            } else if (arg.equals("-exclude")){
   6.173 -                oneArg(argv, i++);
   6.174 -                addToList(excludedPackages, argv[i]);
   6.175 -            } else if (arg.equals("-verbose")) {
   6.176 -                setOption(arg);
   6.177 -                compOpts.put("-verbose", "");
   6.178 -            } else if (arg.equals("-encoding")) {
   6.179 -                oneArg(argv, i++);
   6.180 -                encoding = argv[i];
   6.181 -                compOpts.put("-encoding", argv[i]);
   6.182 -            } else if (arg.equals("-breakiterator")) {
   6.183 -                breakiterator = true;
   6.184 -                setOption("-breakiterator");
   6.185 -            } else if (arg.equals("-quiet")) {
   6.186 -                quiet = true;
   6.187 -                setOption("-quiet");
   6.188 -            } else if (arg.equals("-help")) {
   6.189 -                usage();
   6.190 -                exit();
   6.191 -            } else if (arg.equals("-Xclasses")) {
   6.192 -                setOption(arg);
   6.193 -                docClasses = true;
   6.194 -            } else if (arg.equals("-Xwerror")) {
   6.195 -                setOption(arg);
   6.196 -                rejectWarnings = true;
   6.197 -            } else if (arg.equals("-private")) {
   6.198 -                setOption(arg);
   6.199 -                setFilter(ModifierFilter.ALL_ACCESS);
   6.200 -            } else if (arg.equals("-package")) {
   6.201 -                setOption(arg);
   6.202 -                setFilter(PUBLIC | PROTECTED |
   6.203 -                          ModifierFilter.PACKAGE );
   6.204 -            } else if (arg.equals("-protected")) {
   6.205 -                setOption(arg);
   6.206 -                setFilter(PUBLIC | PROTECTED );
   6.207 -            } else if (arg.equals("-public")) {
   6.208 -                setOption(arg);
   6.209 -                setFilter(PUBLIC);
   6.210 -            } else if (arg.equals("-source")) {
   6.211 -                oneArg(argv, i++);
   6.212 -                if (compOpts.get("-source") != null) {
   6.213 -                    usageError("main.option.already.seen", arg);
   6.214 +
   6.215 +            ToolOption o = ToolOption.get(arg);
   6.216 +            if (o != null) {
   6.217 +                // hack: this restriction should be removed
   6.218 +                if (o == ToolOption.LOCALE && i > 0)
   6.219 +                    usageError("main.locale_first");
   6.220 +
   6.221 +                if (o.hasArg) {
   6.222 +                    oneArg(argv, i++);
   6.223 +                    o.process(this, argv[i]);
   6.224 +                } else {
   6.225 +                    setOption(arg);
   6.226 +                    o.process(this);
   6.227                  }
   6.228 -                compOpts.put("-source", argv[i]);
   6.229 -            } else if (arg.equals("-prompt")) {
   6.230 -                compOpts.put("-prompt", "-prompt");
   6.231 -                messager.promptOnError = true;
   6.232 -            } else if (arg.equals("-sourcepath")) {
   6.233 -                oneArg(argv, i++);
   6.234 -                if (compOpts.get("-sourcepath") != null) {
   6.235 -                    usageError("main.option.already.seen", arg);
   6.236 -                }
   6.237 -                compOpts.put("-sourcepath", argv[i]);
   6.238 -            } else if (arg.equals("-classpath")) {
   6.239 -                oneArg(argv, i++);
   6.240 -                if (compOpts.get("-classpath") != null) {
   6.241 -                    usageError("main.option.already.seen", arg);
   6.242 -                }
   6.243 -                compOpts.put("-classpath", argv[i]);
   6.244 -            } else if (arg.equals("-sysclasspath")) {
   6.245 -                oneArg(argv, i++);
   6.246 -                if (compOpts.get("-bootclasspath") != null) {
   6.247 -                    usageError("main.option.already.seen", arg);
   6.248 -                }
   6.249 -                compOpts.put("-bootclasspath", argv[i]);
   6.250 -            } else if (arg.equals("-bootclasspath")) {
   6.251 -                oneArg(argv, i++);
   6.252 -                if (compOpts.get("-bootclasspath") != null) {
   6.253 -                    usageError("main.option.already.seen", arg);
   6.254 -                }
   6.255 -                compOpts.put("-bootclasspath", argv[i]);
   6.256 -            } else if (arg.equals("-extdirs")) {
   6.257 -                oneArg(argv, i++);
   6.258 -                if (compOpts.get("-extdirs") != null) {
   6.259 -                    usageError("main.option.already.seen", arg);
   6.260 -                }
   6.261 -                compOpts.put("-extdirs", argv[i]);
   6.262 -            } else if (arg.equals("-overview")) {
   6.263 -                oneArg(argv, i++);
   6.264 -            } else if (arg.equals("-doclet")) {
   6.265 -                i++;  // handled in setDocletInvoker
   6.266 -            } else if (arg.equals("-docletpath")) {
   6.267 -                i++;  // handled in setDocletInvoker
   6.268 -            } else if (arg.equals("-locale")) {
   6.269 -                if (i != 0)
   6.270 -                    usageError("main.locale_first");
   6.271 -                oneArg(argv, i++);
   6.272 -                docLocale = argv[i];
   6.273 -            } else if (arg.equals("-Xmaxerrs") || arg.equals("-Xmaxwarns")) {
   6.274 -                oneArg(argv, i++);
   6.275 -                if (compOpts.get(arg) != null) {
   6.276 -                    usageError("main.option.already.seen", arg);
   6.277 -                }
   6.278 -                compOpts.put(arg, argv[i]);
   6.279 -            } else if (arg.equals("-X")) {
   6.280 -                Xusage();
   6.281 -                exit();
   6.282 +
   6.283              } else if (arg.startsWith("-XD")) {
   6.284 +                // hidden javac options
   6.285                  String s = arg.substring("-XD".length());
   6.286                  int eq = s.indexOf('=');
   6.287                  String key = (eq < 0) ? s : s.substring(0, eq);
   6.288 @@ -336,7 +261,7 @@
   6.289              }
   6.290              // call doclet for its options
   6.291              // other arg starts with - is invalid
   6.292 -            else if ( arg.startsWith("-") ) {
   6.293 +            else if (arg.startsWith("-")) {
   6.294                  int optionLength;
   6.295                  optionLength = docletInvoker.optionLength(arg);
   6.296                  if (optionLength < 0) {
   6.297 @@ -380,12 +305,18 @@
   6.298  
   6.299          LanguageVersion languageVersion = docletInvoker.languageVersion();
   6.300          RootDocImpl root = comp.getRootDocImpl(
   6.301 -                docLocale, encoding, showAccess,
   6.302 -                javaNames.toList(), options.toList(), breakiterator,
   6.303 -                subPackages.toList(), excludedPackages.toList(),
   6.304 +                docLocale,
   6.305 +                encoding,
   6.306 +                showAccess,
   6.307 +                javaNames.toList(),
   6.308 +                options.toList(),
   6.309 +                breakiterator,
   6.310 +                subPackages.toList(),
   6.311 +                excludedPackages.toList(),
   6.312                  docClasses,
   6.313                  // legacy?
   6.314 -                languageVersion == null || languageVersion == LanguageVersion.JAVA_1_1, quiet);
   6.315 +                languageVersion == null || languageVersion == LanguageVersion.JAVA_1_1,
   6.316 +                quiet);
   6.317  
   6.318          // release resources
   6.319          comp = null;
   6.320 @@ -437,15 +368,6 @@
   6.321                                            docletParentClassLoader);
   6.322      }
   6.323  
   6.324 -    private void setFilter(long filterBits) {
   6.325 -        if (showAccess != null) {
   6.326 -            messager.error(null, "main.incompatible.access.flags");
   6.327 -            usage();
   6.328 -            exit();
   6.329 -        }
   6.330 -        showAccess = new ModifierFilter(filterBits);
   6.331 -    }
   6.332 -
   6.333      /**
   6.334       * Set one arg option.
   6.335       * Error and exit if one argument is not provided.
   6.336 @@ -458,22 +380,10 @@
   6.337          }
   6.338      }
   6.339  
   6.340 -    private void usageError(String key) {
   6.341 -        messager.error(null, key);
   6.342 -        usage();
   6.343 -        exit();
   6.344 -    }
   6.345 -
   6.346 -    private void usageError(String key, String a1) {
   6.347 -        messager.error(null, key, a1);
   6.348 -        usage();
   6.349 -        exit();
   6.350 -    }
   6.351 -
   6.352 -    private void usageError(String key, String a1, String a2) {
   6.353 -        messager.error(null, key, a1, a2);
   6.354 -        usage();
   6.355 -        exit();
   6.356 +    @Override
   6.357 +    void usageError(String key, Object... args) {
   6.358 +        messager.error(Messager.NOPOS, key, args);
   6.359 +        usage(true);
   6.360      }
   6.361  
   6.362      /**
   6.363 @@ -502,7 +412,6 @@
   6.364          for (List<String> i = arguments; i.nonEmpty(); i=i.tail) {
   6.365              args[k++] = i.head;
   6.366          }
   6.367 -        options = options.append(args);
   6.368 +        options.append(args);
   6.369      }
   6.370 -
   6.371  }
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/share/classes/com/sun/tools/javadoc/ToolOption.java	Thu Nov 15 14:41:31 2012 -0800
     7.3 @@ -0,0 +1,325 @@
     7.4 +/*
     7.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.  Oracle designates this
    7.11 + * particular file as subject to the "Classpath" exception as provided
    7.12 + * by Oracle in the LICENSE file that accompanied this code.
    7.13 + *
    7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.17 + * version 2 for more details (a copy is included in the LICENSE file that
    7.18 + * accompanied this code).
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License version
    7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.23 + *
    7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.25 + * or visit www.oracle.com if you need additional information or have any
    7.26 + * questions.
    7.27 + */
    7.28 +
    7.29 +package com.sun.tools.javadoc;
    7.30 +
    7.31 +import com.sun.tools.javac.code.Flags;
    7.32 +import com.sun.tools.javac.util.ListBuffer;
    7.33 +import com.sun.tools.javac.util.Options;
    7.34 +import java.util.StringTokenizer;
    7.35 +
    7.36 +
    7.37 +/**
    7.38 + * javadoc tool options.
    7.39 + *
    7.40 + *  <p><b>This is NOT part of any supported API.
    7.41 + *  If you write code that depends on this, you do so at your own risk.
    7.42 + *  This code and its internal interfaces are subject to change or
    7.43 + *  deletion without notice.</b>
    7.44 + */
    7.45 +public enum ToolOption {
    7.46 +    // ----- options for underlying compiler -----
    7.47 +
    7.48 +    BOOTCLASSPATH("-bootclasspath", true) {
    7.49 +        @Override
    7.50 +        public void process(Helper helper, String arg) {
    7.51 +            helper.setCompilerOpt(opt, arg);
    7.52 +        }
    7.53 +    },
    7.54 +
    7.55 +    CLASSPATH("-classpath", true) {
    7.56 +        @Override
    7.57 +        public void process(Helper helper, String arg) {
    7.58 +            helper.setCompilerOpt(opt, arg);
    7.59 +        }
    7.60 +    },
    7.61 +
    7.62 +    EXTDIRS("-extdirs", true) {
    7.63 +        @Override
    7.64 +        public void process(Helper helper, String arg) {
    7.65 +            helper.setCompilerOpt(opt, arg);
    7.66 +        }
    7.67 +    },
    7.68 +
    7.69 +    SOURCEPATH("-sourcepath", true) {
    7.70 +        @Override
    7.71 +        public void process(Helper helper, String arg) {
    7.72 +            helper.setCompilerOpt(opt, arg);
    7.73 +        }
    7.74 +    },
    7.75 +
    7.76 +    SYSCLASSPATH("-sysclasspath", true) {
    7.77 +        @Override
    7.78 +        public void process(Helper helper, String arg) {
    7.79 +            helper.setCompilerOpt("-bootclasspath", arg);
    7.80 +        }
    7.81 +    },
    7.82 +
    7.83 +    ENCODING("-encoding", true) {
    7.84 +        @Override
    7.85 +        public void process(Helper helper, String arg) {
    7.86 +            helper.encoding = arg;
    7.87 +            helper.setCompilerOpt(opt, arg);
    7.88 +        }
    7.89 +    },
    7.90 +
    7.91 +    SOURCE("-source", true) {
    7.92 +        @Override
    7.93 +        public void process(Helper helper, String arg) {
    7.94 +            helper.setCompilerOpt(opt, arg);
    7.95 +        }
    7.96 +    },
    7.97 +
    7.98 +    XMAXERRS("-Xmaxerrs", true) {
    7.99 +        @Override
   7.100 +        public void process(Helper helper, String arg) {
   7.101 +            helper.setCompilerOpt(opt, arg);
   7.102 +        }
   7.103 +    },
   7.104 +
   7.105 +    XMAXWARNS("-Xmaxwarns", true) {
   7.106 +        @Override
   7.107 +        public void process(Helper helper, String arg) {
   7.108 +            helper.setCompilerOpt(opt, arg);
   7.109 +        }
   7.110 +    },
   7.111 +
   7.112 +    // ----- doclet options -----
   7.113 +
   7.114 +    DOCLET("-doclet", true), // handled in setDocletInvoker
   7.115 +
   7.116 +    DOCLETPATH("-docletpath", true), // handled in setDocletInvoker
   7.117 +
   7.118 +    // ----- selection options -----
   7.119 +
   7.120 +    SUBPACKAGES("-subpackages", true) {
   7.121 +        @Override
   7.122 +        public void process(Helper helper, String arg) {
   7.123 +            helper.addToList(helper.subPackages, arg);
   7.124 +        }
   7.125 +    },
   7.126 +
   7.127 +    EXCLUDE("-exclude", true) {
   7.128 +        @Override
   7.129 +        public void process(Helper helper, String arg) {
   7.130 +            helper.addToList(helper.excludedPackages, arg);
   7.131 +        }
   7.132 +    },
   7.133 +
   7.134 +    // ----- filtering options -----
   7.135 +
   7.136 +    PACKAGE("-package") {
   7.137 +        @Override
   7.138 +        public void process(Helper helper) {
   7.139 +            helper.setFilter(
   7.140 +                    Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE);
   7.141 +        }
   7.142 +    },
   7.143 +
   7.144 +    PRIVATE("-private") {
   7.145 +        @Override
   7.146 +        public void process(Helper helper) {
   7.147 +            helper.setFilter(ModifierFilter.ALL_ACCESS);
   7.148 +        }
   7.149 +    },
   7.150 +
   7.151 +    PROTECTED("-protected") {
   7.152 +        @Override
   7.153 +        public void process(Helper helper) {
   7.154 +            helper.setFilter(Flags.PUBLIC | Flags.PROTECTED);
   7.155 +        }
   7.156 +    },
   7.157 +
   7.158 +    PUBLIC("-public") {
   7.159 +        @Override
   7.160 +        public void process(Helper helper) {
   7.161 +            helper.setFilter(Flags.PUBLIC);
   7.162 +        }
   7.163 +    },
   7.164 +
   7.165 +    // ----- output control options -----
   7.166 +
   7.167 +    PROMPT("-prompt") {
   7.168 +        @Override
   7.169 +        public void process(Helper helper) {
   7.170 +            helper.compOpts.put("-prompt", "-prompt");
   7.171 +            helper.promptOnError = true;
   7.172 +        }
   7.173 +    },
   7.174 +
   7.175 +    QUIET("-quiet") {
   7.176 +        @Override
   7.177 +        public void process(Helper helper) {
   7.178 +            helper.quiet = true;
   7.179 +        }
   7.180 +    },
   7.181 +
   7.182 +    VERBOSE("-verbose") {
   7.183 +        @Override
   7.184 +        public void process(Helper helper) {
   7.185 +            helper.compOpts.put("-verbose", "");
   7.186 +        }
   7.187 +    },
   7.188 +
   7.189 +    XWERROR("-Xwerror") {
   7.190 +        @Override
   7.191 +        public void process(Helper helper) {
   7.192 +            helper.rejectWarnings = true;
   7.193 +
   7.194 +        }
   7.195 +    },
   7.196 +
   7.197 +    // ----- other options -----
   7.198 +
   7.199 +    BREAKITERATOR("-breakiterator") {
   7.200 +        @Override
   7.201 +        public void process(Helper helper) {
   7.202 +            helper.breakiterator = true;
   7.203 +        }
   7.204 +    },
   7.205 +
   7.206 +    LOCALE("-locale", true) {
   7.207 +        @Override
   7.208 +        public void process(Helper helper, String arg) {
   7.209 +            helper.docLocale = arg;
   7.210 +        }
   7.211 +    },
   7.212 +
   7.213 +    OVERVIEW("-overview", true),
   7.214 +
   7.215 +    XCLASSES("-Xclasses") {
   7.216 +        @Override
   7.217 +        public void process(Helper helper) {
   7.218 +            helper.docClasses = true;
   7.219 +
   7.220 +        }
   7.221 +    },
   7.222 +
   7.223 +    // ----- help options -----
   7.224 +
   7.225 +    HELP("-help") {
   7.226 +        @Override
   7.227 +        public void process(Helper helper) {
   7.228 +            helper.usage();
   7.229 +        }
   7.230 +    },
   7.231 +
   7.232 +    X("-X") {
   7.233 +        @Override
   7.234 +        public void process(Helper helper) {
   7.235 +            helper.Xusage();
   7.236 +        }
   7.237 +    };
   7.238 +
   7.239 +    public final String opt;
   7.240 +    public final boolean hasArg;
   7.241 +
   7.242 +    ToolOption(String opt) {
   7.243 +        this(opt, false);
   7.244 +    }
   7.245 +
   7.246 +    ToolOption(String opt, boolean hasArg) {
   7.247 +        this.opt = opt;
   7.248 +        this.hasArg = hasArg;
   7.249 +    }
   7.250 +
   7.251 +    void process(Helper helper, String arg) { }
   7.252 +
   7.253 +    void process(Helper helper) { }
   7.254 +
   7.255 +    static ToolOption get(String name) {
   7.256 +        for (ToolOption o: values()) {
   7.257 +            if (name.equals(o.opt))
   7.258 +                return o;
   7.259 +        }
   7.260 +        return null;
   7.261 +    }
   7.262 +
   7.263 +    static abstract class Helper {
   7.264 +        /** List of decoded options. */
   7.265 +        final ListBuffer<String[]> options = new ListBuffer<String[]>();
   7.266 +
   7.267 +        /** Selected packages, from -subpackages. */
   7.268 +        final ListBuffer<String> subPackages = new ListBuffer<String>();
   7.269 +
   7.270 +        /** Excluded packages, from -exclude. */
   7.271 +        final ListBuffer<String> excludedPackages = new ListBuffer<String>();
   7.272 +
   7.273 +        /** javac options, set by various options. */
   7.274 +        Options compOpts; // = Options.instance(context)
   7.275 +
   7.276 +        /* Encoding for javac, and files written? set by -encoding. */
   7.277 +        String encoding = null;
   7.278 +
   7.279 +        /** Set by -breakiterator. */
   7.280 +        boolean breakiterator = false;
   7.281 +
   7.282 +        /** Set by -quiet. */
   7.283 +        boolean quiet = false;
   7.284 +
   7.285 +        /** Set by -Xclasses. */
   7.286 +        boolean docClasses = false;
   7.287 +
   7.288 +        /** Set by -Xwerror. */
   7.289 +        boolean rejectWarnings = false;
   7.290 +
   7.291 +        /** Set by -prompt. */
   7.292 +        boolean promptOnError;
   7.293 +
   7.294 +        /** Set by -locale. */
   7.295 +        String docLocale = "";
   7.296 +
   7.297 +        /** Set by -public, private, -protected, -package. */
   7.298 +        ModifierFilter showAccess = null;
   7.299 +
   7.300 +        abstract void usage();
   7.301 +        abstract void Xusage();
   7.302 +
   7.303 +        abstract void usageError(String msg, Object... args);
   7.304 +
   7.305 +        protected void addToList(ListBuffer<String> list, String str){
   7.306 +            StringTokenizer st = new StringTokenizer(str, ":");
   7.307 +            String current;
   7.308 +            while(st.hasMoreTokens()){
   7.309 +                current = st.nextToken();
   7.310 +                list.append(current);
   7.311 +            }
   7.312 +        }
   7.313 +
   7.314 +        protected void setFilter(long filterBits) {
   7.315 +            if (showAccess != null) {
   7.316 +                usageError("main.incompatible.access.flags");
   7.317 +            }
   7.318 +            showAccess = new ModifierFilter(filterBits);
   7.319 +        }
   7.320 +
   7.321 +        private void setCompilerOpt(String opt, String arg) {
   7.322 +            if (compOpts.get(opt) != null) {
   7.323 +                usageError("main.option.already.seen", opt);
   7.324 +            }
   7.325 +            compOpts.put(opt, arg);
   7.326 +        }
   7.327 +    }
   7.328 +}

mercurial