langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/Messager.java
author mcimadamore
Fri, 16 Dec 2016 15:27:34 +0000
changeset 42827 36468b5fa7f4
parent 40232 4995ab1a4558
permissions -rw-r--r--
8181370: Convert anonymous inner classes into lambdas/method references Reviewed-by: jjg, rfield, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 38617
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
10
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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
37938
42baa89d2156 8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents: 28892
diff changeset
    26
package com.sun.tools.javadoc.main;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    28
import java.io.PrintWriter;
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    29
import java.util.Locale;
28892
7e09121db885 8071836: javadoc fails as javadoc resource bundle not visible to com.sun.tools.javac.util.JavacMessages
ksrini
parents: 25874
diff changeset
    30
import java.util.ResourceBundle;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.util.Context;
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40232
diff changeset
    34
import com.sun.tools.javac.util.Context.Factory;
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    35
import com.sun.tools.javac.util.JCDiagnostic;
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
    36
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    37
import com.sun.tools.javac.util.JavacMessages;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 8633
diff changeset
    38
import com.sun.tools.javac.util.Log;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * Utility for integrating with javadoc tools and for localization.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * Handle Resources. Access to error and warning counts.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * Message formatting.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * <br>
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * Also provides implementation for DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    47
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    48
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    49
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    50
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    51
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * @see java.util.ResourceBundle
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * @see java.text.MessageFormat
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 */
38617
d93a7f64e231 8157606: deprecate com.sun.javadoc API
jjg
parents: 37938
diff changeset
    56
@Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
public class Messager extends Log implements DocErrorReporter {
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    58
    public static final SourcePosition NOPOS = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /** Get the current messager, which is also the compiler log. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    public static Messager instance0(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        Log instance = context.get(logKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        if (instance == null || !(instance instanceof Messager))
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
            throw new InternalError("no messager instance!");
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        return (Messager)instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 7681
diff changeset
    68
    public static void preRegister(Context context,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
                                   final String programName) {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40232
diff changeset
    70
        context.put(logKey, (Factory<Log>)c -> new Messager(c, programName));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    }
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 7681
diff changeset
    72
    public static void preRegister(Context context,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
                                   final String programName,
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
                                   final PrintWriter errWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
                                   final PrintWriter warnWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
                                   final PrintWriter noticeWriter) {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40232
diff changeset
    77
        context.put(logKey, (Factory<Log>)c -> new Messager(c,
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40232
diff changeset
    78
                            programName,
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40232
diff changeset
    79
                            errWriter,
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40232
diff changeset
    80
                            warnWriter,
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40232
diff changeset
    81
                            noticeWriter));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    public class ExitJavadoc extends Error {
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
    88
    final String programName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    90
    private Locale locale;
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    91
    private final JavacMessages messages;
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    92
    private final JCDiagnostic.Factory javadocDiags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /** The default writer for diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    static final PrintWriter defaultErrWriter = new PrintWriter(System.err);
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    static final PrintWriter defaultWarnWriter = new PrintWriter(System.err);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    static final PrintWriter defaultNoticeWriter = new PrintWriter(System.out);
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * @param programName  Name of the program (for error messages).
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    protected Messager(Context context, String programName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        this(context, programName, defaultErrWriter, defaultWarnWriter, defaultNoticeWriter);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * @param programName  Name of the program (for error messages).
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * @param errWriter    Stream for error messages
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * @param warnWriter   Stream for warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     * @param noticeWriter Stream for other messages
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     */
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 10
diff changeset
   115
    @SuppressWarnings("deprecation")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    protected Messager(Context context,
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                       String programName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
                       PrintWriter errWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                       PrintWriter warnWriter,
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
                       PrintWriter noticeWriter) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        super(context, errWriter, warnWriter, noticeWriter);
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   122
        messages = JavacMessages.instance(context);
28892
7e09121db885 8071836: javadoc fails as javadoc resource bundle not visible to com.sun.tools.javac.util.JavacMessages
ksrini
parents: 25874
diff changeset
   123
        messages.add(locale -> ResourceBundle.getBundle("com.sun.tools.javadoc.resources.javadoc",
7e09121db885 8071836: javadoc fails as javadoc resource bundle not visible to com.sun.tools.javac.util.JavacMessages
ksrini
parents: 25874
diff changeset
   124
                                                         locale));
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   125
        javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        this.programName = programName;
28892
7e09121db885 8071836: javadoc fails as javadoc resource bundle not visible to com.sun.tools.javac.util.JavacMessages
ksrini
parents: 25874
diff changeset
   127
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   130
    public void setLocale(Locale locale) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   131
        this.locale = locale;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * get and format message string from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * @param key selects message from resource
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   138
     * @param args arguments for the message
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   140
    String getText(String key, Object... args) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   141
        return messages.getLocalizedString(locale, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    public void printError(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        printError(null, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     * @param pos the position where the error occurs
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    public void printError(SourcePosition pos, String msg) {
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   162
        if (diagListener != null) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   163
            report(DiagnosticType.ERROR, pos, msg);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   164
            return;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   165
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   166
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   167
        if (nerrors < MaxErrors) {
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   168
            String prefix = (pos == null) ? programName : pos.toString();
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 38617
diff changeset
   169
            PrintWriter errWriter = getWriter(WriterKind.ERROR);
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   170
            errWriter.println(prefix + ": " + getText("javadoc.error") + " - " + msg);
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   171
            errWriter.flush();
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   172
            prompt();
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   173
            nerrors++;
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   174
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public void printWarning(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        printWarning(null, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * @param pos the position where the error occurs
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    public void printWarning(SourcePosition pos, String msg) {
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   195
        if (diagListener != null) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   196
            report(DiagnosticType.WARNING, pos, msg);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   197
            return;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   198
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   199
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   200
        if (nwarnings < MaxWarnings) {
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   201
            String prefix = (pos == null) ? programName : pos.toString();
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 38617
diff changeset
   202
            PrintWriter warnWriter = getWriter(WriterKind.WARNING);
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   203
            warnWriter.println(prefix +  ": " + getText("javadoc.warning") +" - " + msg);
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   204
            warnWriter.flush();
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   205
            nwarnings++;
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   206
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    public void printNotice(String msg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        printNotice(null, msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     * @param pos the position where the error occurs
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    public void printNotice(SourcePosition pos, String msg) {
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   227
        if (diagListener != null) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   228
            report(DiagnosticType.NOTE, pos, msg);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   229
            return;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   230
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   231
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 38617
diff changeset
   232
        PrintWriter noticeWriter = getWriter(WriterKind.NOTICE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        if (pos == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
            noticeWriter.println(msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            noticeWriter.println(pos + ": " + msg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        noticeWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   245
    public void error(SourcePosition pos, String key, Object... args) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   246
        printError(pos, getText(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   254
    public void warning(SourcePosition pos, String key, Object... args) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   255
        printWarning(pos, getText(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   263
    public void notice(String key, Object... args) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   264
        printNotice(getText(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * Return total number of errors, including those recorded
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     * in the compilation log.
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    public int nerrors() { return nerrors; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     * Return total number of warnings, including those recorded
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     * in the compilation log.
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    public int nwarnings() { return nwarnings; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     * Print exit message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    public void exitNotice() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        if (nerrors > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            notice((nerrors > 1) ? "main.errors" : "main.error",
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                   "" + nerrors);
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        if (nwarnings > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
            notice((nwarnings > 1) ?  "main.warnings" : "main.warning",
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                   "" + nwarnings);
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     * Force program exit, e.g., from a fatal error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
     * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     * TODO: This method does not really belong here.
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    public void exit() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        throw new ExitJavadoc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    }
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   301
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   302
    private void report(DiagnosticType type, SourcePosition pos, String msg) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   303
        switch (type) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   304
            case ERROR:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   305
            case WARNING:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   306
                Object prefix = (pos == null) ? programName : pos;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   307
                report(javadocDiags.create(type, null, null, "msg", prefix, msg));
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   308
                break;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   309
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   310
            case NOTE:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   311
                String key = (pos == null) ? "msg" : "pos.msg";
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   312
                report(javadocDiags.create(type, null, null, key, pos, msg));
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   313
                break;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   314
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   315
            default:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   316
                throw new IllegalArgumentException(type.toString());
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   317
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   318
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
}