langtools/src/share/classes/com/sun/tools/javadoc/Messager.java
author jjg
Tue, 20 Jan 2009 18:23:13 -0800
changeset 1870 57a1138dffc8
parent 10 06bc494ca11e
child 2212 1d3dc0e0ba0c
permissions -rw-r--r--
6795903: fix latent build warnings in langtools repository Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2004 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javadoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.PrintWriter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.text.MessageFormat;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.ResourceBundle;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.MissingResourceException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.Context;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.util.Log;  // Access to 'javac' output streams
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * Utility for integrating with javadoc tools and for localization.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * Handle Resources. Access to error and warning counts.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * Message formatting.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * <br>
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * Also provides implementation for DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * @see java.util.ResourceBundle
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * @see java.text.MessageFormat
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
public class Messager extends Log implements DocErrorReporter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /** Get the current messager, which is also the compiler log. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    public static Messager instance0(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        Log instance = context.get(logKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        if (instance == null || !(instance instanceof Messager))
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
            throw new InternalError("no messager instance!");
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        return (Messager)instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    public static void preRegister(final Context context,
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
                                   final String programName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        context.put(logKey, new Context.Factory<Log>() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
            public Log make() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
                return new Messager(context,
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
                                    programName);
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        });
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    public static void preRegister(final Context context,
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
                                   final String programName,
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
                                   final PrintWriter errWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
                                   final PrintWriter warnWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
                                   final PrintWriter noticeWriter) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        context.put(logKey, new Context.Factory<Log>() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            public Log make() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
                return new Messager(context,
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
                                    programName,
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
                                    errWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
                                    warnWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                                    noticeWriter);
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        });
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    public class ExitJavadoc extends Error {
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    private final String programName;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    private ResourceBundle messageRB = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    /** The default writer for diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    static final PrintWriter defaultErrWriter = new PrintWriter(System.err);
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    static final PrintWriter defaultWarnWriter = new PrintWriter(System.err);
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    static final PrintWriter defaultNoticeWriter = new PrintWriter(System.out);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     * @param programName  Name of the program (for error messages).
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    protected Messager(Context context, String programName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        this(context, programName, defaultErrWriter, defaultWarnWriter, defaultNoticeWriter);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * @param programName  Name of the program (for error messages).
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * @param errWriter    Stream for error messages
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * @param warnWriter   Stream for warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * @param noticeWriter Stream for other messages
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     */
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 10
diff changeset
   114
    @SuppressWarnings("deprecation")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    protected Messager(Context context,
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
                       String programName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                       PrintWriter errWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
                       PrintWriter warnWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                       PrintWriter noticeWriter) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        super(context, errWriter, warnWriter, noticeWriter);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        this.programName = programName;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     * Reset resource bundle, eg. locale has changed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    public void reset() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        messageRB = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     * Get string from ResourceBundle, initialize ResourceBundle
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     * if needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    private String getString(String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        ResourceBundle messageRB = this.messageRB;
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        if (messageRB == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
                this.messageRB = messageRB =
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                    ResourceBundle.getBundle(
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                          "com.sun.tools.javadoc.resources.javadoc");
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            } catch (MissingResourceException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                throw new Error("Fatal: Resource for javadoc is missing");
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        return messageRB.getString(key);
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * get and format message string from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    String getText(String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        return getText(key, (String)null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     * get and format message string from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    String getText(String key, String a1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        return getText(key, a1, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     * get and format message string from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    String getText(String key, String a1, String a2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        return getText(key, a1, a2, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     * get and format message string from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    String getText(String key, String a1, String a2, String a3) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        return getText(key, a1, a2, a3, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     * get and format message string from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     * @param a4 fourth argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    String getText(String key, String a1, String a2, String a3,
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
                          String a4) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            String message = getString(key);
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
            String[] args = new String[4];
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            args[0] = a1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            args[1] = a2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            args[2] = a3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            args[3] = a4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            return MessageFormat.format(message, (Object[])args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        } catch (MissingResourceException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
            return "********** Resource for javadoc is broken. There is no " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                key + " key in resource.";
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    public void printError(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        printError(null, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     * @param pos the position where the error occurs
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    public void printError(SourcePosition pos, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        String prefix = (pos == null) ? programName : pos.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        errWriter.println(prefix + ": " + getText("javadoc.error") + " - " + msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        errWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        prompt();
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        nerrors++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    public void printWarning(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        printWarning(null, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     * @param pos the position where the error occurs
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    public void printWarning(SourcePosition pos, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        String prefix = (pos == null) ? programName : pos.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        warnWriter.println(prefix +  ": " + getText("javadoc.warning") +" - " + msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        warnWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        nwarnings++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    public void printNotice(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        printNotice(null, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     * @param pos the position where the error occurs
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    public void printNotice(SourcePosition pos, String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        if (pos == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            noticeWriter.println(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            noticeWriter.println(pos + ": " + msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        noticeWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    public void error(SourcePosition pos, String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        printError(pos, getText(key));
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
    public void error(SourcePosition pos, String key, String a1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
        printError(pos, getText(key, a1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    public void error(SourcePosition pos, String key, String a1, String a2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        printError(pos, getText(key, a1, a2));
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
    public void error(SourcePosition pos, String key, String a1, String a2, String a3) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        printError(pos, getText(key, a1, a2, a3));
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    public void warning(SourcePosition pos, String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        printWarning(pos, getText(key));
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
    public void warning(SourcePosition pos, String key, String a1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        printWarning(pos, getText(key, a1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
    public void warning(SourcePosition pos, String key, String a1, String a2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        printWarning(pos, getText(key, a1, a2));
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
    public void warning(SourcePosition pos, String key, String a1, String a2, String a3) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        printWarning(pos, getText(key, a1, a2, a3));
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
    public void warning(SourcePosition pos, String key, String a1, String a2, String a3,
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
                        String a4) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        printWarning(pos, getText(key, a1, a2, a3, a4));
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    public void notice(String key) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        printNotice(getText(key));
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    public void notice(String key, String a1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        printNotice(getText(key, a1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    public void notice(String key, String a1, String a2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        printNotice(getText(key, a1, a2));
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
     * @param a1 first argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
     * @param a2 second argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
     * @param a3 third argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
    public void notice(String key, String a1, String a2, String a3) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        printNotice(getText(key, a1, a2, a3));
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
     * Return total number of errors, including those recorded
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
     * in the compilation log.
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
    public int nerrors() { return nerrors; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
     * Return total number of warnings, including those recorded
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
     * in the compilation log.
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    public int nwarnings() { return nwarnings; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
     * Print exit message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
    public void exitNotice() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        int nerrors = nerrors();
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        int nwarnings = nwarnings();
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
        if (nerrors > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
            notice((nerrors > 1) ? "main.errors" : "main.error",
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
                   "" + nerrors);
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        if (nwarnings > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
            notice((nwarnings > 1) ?  "main.warnings" : "main.warning",
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
                   "" + nwarnings);
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
     * Force program exit, e.g., from a fatal error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
     * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
     * TODO: This method does not really belong here.
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
    public void exit() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        throw new ExitJavadoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
}