src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Messager.java
author jlahoda
Fri, 09 Mar 2018 09:42:10 +0100
changeset 49197 cc2673fa8c20
parent 47216 71c04702a3d5
child 55138 b564f266dda0
permissions -rw-r--r--
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure. Summary: Catching CompletionFailures that would be thrown to API clients, and re-completing the symbols again when javac itself needs it. Reviewed-by: cushon, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 35426
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
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    26
package jdk.javadoc.internal.tool;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    27
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    29
import java.io.PrintWriter;
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    30
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
    31
import java.util.ResourceBundle;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    33
import javax.lang.model.element.Element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    34
import javax.tools.Diagnostic.Kind;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    35
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41451
diff changeset
    36
import com.sun.tools.javac.util.Context.Factory;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    37
import jdk.javadoc.doclet.Reporter;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    38
import com.sun.source.tree.CompilationUnitTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    39
import com.sun.source.util.DocSourcePositions;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    40
import com.sun.source.util.DocTreePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    41
import com.sun.source.util.TreePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    42
import com.sun.tools.javac.api.JavacTrees;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    43
import com.sun.tools.javac.tree.JCTree;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import com.sun.tools.javac.util.Context;
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    45
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
    46
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    47
import com.sun.tools.javac.util.JavacMessages;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 8633
diff changeset
    48
import com.sun.tools.javac.util.Log;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * Utility for integrating with javadoc tools and for localization.
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    52
 * Handle resources, access to error and warning counts and
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
    53
 * message formatting.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    55
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    56
 *  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
    57
 *  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
    58
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    59
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 * @see java.util.ResourceBundle
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 * @see java.text.MessageFormat
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    64
public class Messager extends Log implements Reporter {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    65
    final Context context;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    /** Get the current messager, which is also the compiler log. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    public static Messager instance0(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        Log instance = context.get(logKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        if (instance == null || !(instance instanceof Messager))
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
            throw new InternalError("no messager instance!");
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        return (Messager)instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 7681
diff changeset
    75
    public static void preRegister(Context context,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
                                   final String programName) {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41451
diff changeset
    77
        context.put(logKey, (Factory<Log>)c -> new Messager(c, programName));
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    78
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    79
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    80
    public static void preRegister(Context context, final String programName,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    81
            final PrintWriter outWriter, final PrintWriter errWriter) {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41451
diff changeset
    82
        context.put(logKey, (Factory<Log>)c -> new Messager(c, programName, outWriter, errWriter));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    84
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    85
    @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    86
    public void print(Kind kind, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    87
        switch (kind) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    88
            case ERROR:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    89
                printError(msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    90
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    91
            case WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    92
            case MANDATORY_WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    93
                printWarning(msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    94
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    95
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    96
                printNotice(msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    97
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    98
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    99
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   100
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   101
    @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   102
    public void print(Kind kind, DocTreePath path, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   103
        switch (kind) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   104
            case ERROR:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   105
                printError(path, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   106
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   107
            case WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   108
            case MANDATORY_WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   109
                printWarning(path, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   110
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   111
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   112
                printWarning(path, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   113
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   114
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   115
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   116
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   117
    @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   118
    public void print(Kind kind, Element e, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   119
                switch (kind) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   120
            case ERROR:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   121
                printError(e, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   122
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   123
            case WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   124
            case MANDATORY_WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   125
                printWarning(e, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   126
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   127
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   128
                printWarning(e, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   129
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   130
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   133
    final String programName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   135
    private Locale locale;
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   136
    private final JavacMessages messages;
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   137
    private final JCDiagnostic.Factory javadocDiags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    /** The default writer for diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   141
    static final PrintWriter defaultOutWriter = new PrintWriter(System.out);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    static final PrintWriter defaultErrWriter = new PrintWriter(System.err);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * @param programName  Name of the program (for error messages).
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   148
    public Messager(Context context, String programName) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   149
        this(context, programName, defaultOutWriter, defaultErrWriter);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     * @param programName  Name of the program (for error messages).
41448
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 41252
diff changeset
   155
     * @param outWriter    Stream for notices etc.
6689bce0cd65 8159855: Create an SPI for tools
jjg
parents: 41252
diff changeset
   156
     * @param errWriter    Stream for errors and warnings
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     */
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 10
diff changeset
   158
    @SuppressWarnings("deprecation")
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   159
    public Messager(Context context, String programName, PrintWriter outWriter, PrintWriter errWriter) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   160
        super(context, errWriter, errWriter, outWriter);
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   161
        messages = JavacMessages.instance(context);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   162
        messages.add(locale -> ResourceBundle.getBundle("jdk.javadoc.internal.tool.resources.javadoc",
28892
7e09121db885 8071836: javadoc fails as javadoc resource bundle not visible to com.sun.tools.javac.util.JavacMessages
ksrini
parents: 25874
diff changeset
   163
                                                         locale));
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   164
        javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        this.programName = programName;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   166
        this.context = context;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   167
        locale = Locale.getDefault();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   170
    public void setLocale(Locale locale) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   171
        this.locale = locale;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * get and format message string from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * @param key selects message from resource
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   178
     * @param args arguments for the message
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   180
    String getText(String key, Object... args) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   181
        return messages.getLocalizedString(locale, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   184
    private String getDiagSource(DocTreePath path) {
43261
d377e97291d8 8138725: Add options for Javadoc generation
jjg
parents: 42827
diff changeset
   185
        if (path == null || path.getTreePath() == null) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   186
            return programName;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   187
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   188
        JavacTrees trees = JavacTrees.instance(context);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   189
        DocSourcePositions sourcePositions = trees.getSourcePositions();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   190
        CompilationUnitTree cu = path.getTreePath().getCompilationUnit();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   191
        long spos = sourcePositions.getStartPosition(cu, path.getDocComment(), path.getLeaf());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   192
        long lineNumber = cu.getLineMap().getLineNumber(spos);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   193
        String fname = cu.getSourceFile().getName();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   194
        String posString = fname + ":" + lineNumber;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   195
        return posString;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   196
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   197
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   198
    private String getDiagSource(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   199
        if (e == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   200
            return programName;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   201
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   202
        JavacTrees trees = JavacTrees.instance(context);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   203
        TreePath path = trees.getPath(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   204
        DocSourcePositions sourcePositions = trees.getSourcePositions();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   205
        JCTree tree = trees.getTree(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   206
        CompilationUnitTree cu = path.getCompilationUnit();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   207
        long spos = sourcePositions.getStartPosition(cu, tree);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   208
        long lineNumber = cu.getLineMap().getLineNumber(spos);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   209
        String fname = cu.getSourceFile().getName();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   210
        String posString = fname + ":" + lineNumber;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   211
        return posString;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   212
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   213
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    public void printError(String msg) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   221
        printError((DocTreePath)null, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   222
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   223
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   224
    public void printError(DocTreePath path, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   225
        String prefix = getDiagSource(path);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   226
        if (diagListener != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   227
            report(DiagnosticType.ERROR, prefix, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   228
            return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   229
        }
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   230
        printError(prefix, msg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   233
    public void printError(Element e, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   234
        String prefix = getDiagSource(e);
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   235
        if (diagListener != null) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   236
            report(DiagnosticType.ERROR, prefix, msg);
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   237
            return;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   238
        }
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   239
        printError(prefix, msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   240
    }
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   241
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   242
    public void printErrorUsingKey(String key, Object... args) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   243
        printError((Element)null, getText(key, args));
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   244
    }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   245
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   246
    // print the error and increment count
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   247
    private void printError(String prefix, String msg) {
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   248
        if (nerrors < MaxErrors) {
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   249
            PrintWriter errWriter = getWriter(WriterKind.ERROR);
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   250
            printRawLines(errWriter, prefix + ": " + getText("javadoc.error") + " - " + msg);
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   251
            errWriter.flush();
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   252
            prompt();
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   253
            nerrors++;
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   254
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    public void printWarning(String msg) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   264
        printWarning((DocTreePath)null, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   265
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   266
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   267
    public void printWarningUsingKey(String key, Object... args) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   268
        printWarning((Element)null, getText(key, args));
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   269
    }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   270
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   271
    public void printWarning(Element e, String key, Object... args) {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   272
        printWarning(getText(key, args));
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   273
    }
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   274
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   275
    public void printWarning(DocTreePath path, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   276
        String prefix = getDiagSource(path);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   277
        if (diagListener != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   278
            report(DiagnosticType.WARNING, prefix, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   279
            return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   280
        }
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   281
        printWarning(prefix, msg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   284
    public void printWarning(Element e, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   285
        String prefix = getDiagSource(e);
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   286
        if (diagListener != null) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   287
            report(DiagnosticType.WARNING, prefix, msg);
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   288
            return;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   289
        }
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   290
        printWarning(prefix, msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   291
    }
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   292
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   293
    // print the warning and increment count
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   294
    private void printWarning(String prefix, String msg) {
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   295
        if (nwarnings < MaxWarnings) {
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   296
            PrintWriter warnWriter = getWriter(WriterKind.WARNING);
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   297
            printRawLines(warnWriter, prefix + ": " + getText("javadoc.warning") + " - " + msg);
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   298
            warnWriter.flush();
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   299
            nwarnings++;
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   300
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    public void printNotice(String msg) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   310
        printNotice((DocTreePath)null, msg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   313
    public void printNotice(DocTreePath path, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   314
        String prefix = getDiagSource(path);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   315
        if (diagListener != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   316
            report(DiagnosticType.NOTE, null, prefix + ": " + msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   317
            return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   318
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   319
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   320
        PrintWriter noticeWriter = getWriter(WriterKind.NOTICE);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   321
        if (path == null) {
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   322
            printRawLines(noticeWriter, msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   323
        } else {
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   324
            printRawLines(noticeWriter, prefix + ": " + msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   325
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   326
        noticeWriter.flush();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   327
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   328
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   329
    public void printNotice(Element e, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   330
        String pos = getDiagSource(e);
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   331
        if (diagListener != null) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   332
            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
   333
            return;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   334
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   335
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   336
        PrintWriter noticeWriter = getWriter(WriterKind.NOTICE);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   337
        if (e == null) {
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   338
            printRawLines(noticeWriter, msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   339
        } else {
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   340
            printRawLines(noticeWriter, pos + ": " + msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   341
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
        noticeWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
     */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   350
    public void notice(String key, Object... args) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   351
        printNotice(getText(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
    /**
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   355
     * Returns true if errors have been recorded.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   357
    public boolean hasErrors() {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   358
        return nerrors != 0;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   359
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
    /**
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   362
     * Returns true if warnings have been recorded.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   364
    public boolean hasWarnings() {
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   365
        return nwarnings != 0;
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   366
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     * Print exit message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     */
41451
a847c7aa25a7 8151102: Cleanup javadoc exception handling
ksrini
parents: 41448
diff changeset
   371
    public void printErrorWarningCounts() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        if (nerrors > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
            notice((nerrors > 1) ? "main.errors" : "main.error",
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                   "" + nerrors);
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        if (nwarnings > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
            notice((nwarnings > 1) ?  "main.warnings" : "main.warning",
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
                   "" + nwarnings);
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   382
    private void report(DiagnosticType type, String pos, String msg) {
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   383
        switch (type) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   384
            case ERROR:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   385
            case WARNING:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   386
                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
   387
                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
   388
                break;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   389
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   390
            case NOTE:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   391
                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
   392
                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
   393
                break;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   394
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   395
            default:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   396
                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
   397
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   398
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
}