langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Messager.java
author jjg
Fri, 30 Sep 2016 13:15:22 -0700
changeset 41252 058d83c9b1c7
parent 40232 4995ab1a4558
child 41448 6689bce0cd65
permissions -rw-r--r--
8166144: New javadoc options don't conform to JEP 293 (GNU style options) Reviewed-by: ksrini, bpatel
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
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    36
import jdk.javadoc.doclet.Reporter;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    37
import com.sun.source.tree.CompilationUnitTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    38
import com.sun.source.util.DocSourcePositions;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    39
import com.sun.source.util.DocTreePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    40
import com.sun.source.util.TreePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    41
import com.sun.tools.javac.api.JavacTrees;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    42
import com.sun.tools.javac.tree.JCTree;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.javac.util.Context;
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    44
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
    45
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
    46
import com.sun.tools.javac.util.JavacMessages;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 8633
diff changeset
    47
import com.sun.tools.javac.util.Log;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * Utility for integrating with javadoc tools and for localization.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * Handle Resources. Access to error and warning counts.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * Message formatting.
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * <br>
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * Also provides implementation for DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    56
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    57
 *  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
    58
 *  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
    59
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    60
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 * @see java.util.ResourceBundle
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 * @see java.text.MessageFormat
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    65
public class Messager extends Log implements Reporter {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    66
    final Context context;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    /** Get the current messager, which is also the compiler log. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    public static Messager instance0(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        Log instance = context.get(logKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        if (instance == null || !(instance instanceof Messager))
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
            throw new InternalError("no messager instance!");
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        return (Messager)instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 7681
diff changeset
    76
    public static void preRegister(Context context,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
                                   final String programName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        context.put(logKey, new Context.Factory<Log>() {
8614
06e42328ddab 7021650: fix Context issues
jjg
parents: 7681
diff changeset
    79
            public Log make(Context c) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    80
                return new Messager(c, programName);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    81
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    82
        });
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    83
    }
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
    public static void preRegister(Context context, final String programName,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    86
            final PrintWriter outWriter, final PrintWriter errWriter) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    87
        context.put(logKey, new Context.Factory<Log>() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    88
            public Log make(Context c) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    89
                return new Messager(c, programName, outWriter, errWriter);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        });
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    93
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    94
    @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    95
    public void print(Kind kind, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    96
        switch (kind) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    97
            case ERROR:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    98
                printError(msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
    99
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   100
            case WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   101
            case MANDATORY_WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   102
                printWarning(msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   103
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   104
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   105
                printNotice(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
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   108
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   109
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   110
    @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   111
    public void print(Kind kind, DocTreePath path, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   112
        switch (kind) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   113
            case ERROR:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   114
                printError(path, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   115
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   116
            case WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   117
            case MANDATORY_WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   118
                printWarning(path, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   119
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   120
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   121
                printWarning(path, 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
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   124
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   125
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   126
    @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   127
    public void print(Kind kind, Element e, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   128
                switch (kind) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   129
            case ERROR:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   130
                printError(e, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   131
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   132
            case WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   133
            case MANDATORY_WARNING:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   134
                printWarning(e, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   135
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   136
            default:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   137
                printWarning(e, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   138
                return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   139
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
37750
d213951c811b 8154482: javadoc tool must support legacy doclet and taglet
ksrini
parents: 35426
diff changeset
   142
    public static class ExitJavadoc extends Error {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   146
    final String programName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   148
    private Locale locale;
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   149
    private final JavacMessages messages;
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   150
    private final JCDiagnostic.Factory javadocDiags;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    /** The default writer for diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   154
    static final PrintWriter defaultOutWriter = new PrintWriter(System.out);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    static final PrintWriter defaultErrWriter = new PrintWriter(System.err);
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     * @param programName  Name of the program (for error messages).
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   161
    public Messager(Context context, String programName) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   162
        this(context, programName, defaultOutWriter, defaultErrWriter);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * @param programName  Name of the program (for error messages).
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   168
     * @param stdOut    Stream for notices etc.
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   169
     * @param stdErr    Stream for errors and warnings
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 10
diff changeset
   171
    @SuppressWarnings("deprecation")
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   172
    public Messager(Context context, String programName, PrintWriter outWriter, PrintWriter errWriter) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   173
        super(context, errWriter, errWriter, outWriter);
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   174
        messages = JavacMessages.instance(context);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   175
        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
   176
                                                         locale));
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   177
        javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        this.programName = programName;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   179
        this.context = context;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   180
        locale = Locale.getDefault();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   183
    public void setLocale(Locale locale) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   184
        this.locale = locale;
10
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
     * get and format message string from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * @param key selects message from resource
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   191
     * @param args arguments for the message
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   193
    String getText(String key, Object... args) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   194
        return messages.getLocalizedString(locale, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   197
    private String getDiagSource(DocTreePath path) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   198
        if (path == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   199
            return programName;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   200
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   201
        JavacTrees trees = JavacTrees.instance(context);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   202
        DocSourcePositions sourcePositions = trees.getSourcePositions();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   203
        CompilationUnitTree cu = path.getTreePath().getCompilationUnit();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   204
        long spos = sourcePositions.getStartPosition(cu, path.getDocComment(), path.getLeaf());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   205
        long lineNumber = cu.getLineMap().getLineNumber(spos);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   206
        String fname = cu.getSourceFile().getName();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   207
        String posString = fname + ":" + lineNumber;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   208
        return posString;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   209
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   210
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   211
    private String getDiagSource(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   212
        if (e == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   213
            return programName;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   214
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   215
        JavacTrees trees = JavacTrees.instance(context);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   216
        TreePath path = trees.getPath(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   217
        DocSourcePositions sourcePositions = trees.getSourcePositions();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   218
        JCTree tree = trees.getTree(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   219
        CompilationUnitTree cu = path.getCompilationUnit();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   220
        long spos = sourcePositions.getStartPosition(cu, tree);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   221
        long lineNumber = cu.getLineMap().getLineNumber(spos);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   222
        String fname = cu.getSourceFile().getName();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   223
        String posString = fname + ":" + lineNumber;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   224
        return posString;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   225
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   226
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     *
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(String msg) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   234
        printError((DocTreePath)null, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   235
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   236
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   237
    public void printError(DocTreePath path, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   238
        String prefix = getDiagSource(path);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   239
        if (diagListener != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   240
            report(DiagnosticType.ERROR, prefix, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   241
            return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   242
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   243
        incrementErrorCount(prefix, msg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   246
    public void printError(Element e, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   247
        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
   248
        if (diagListener != null) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   249
            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
   250
            return;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   251
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   252
        incrementErrorCount(prefix, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   253
    }
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   254
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   255
    private void incrementErrorCount(String prefix, String msg) {
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   256
        if (nerrors < MaxErrors) {
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   257
            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
   258
            printRawLines(errWriter, prefix + ": " + getText("javadoc.error") + " - " + msg);
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   259
            errWriter.flush();
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   260
            prompt();
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   261
            nerrors++;
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   262
        }
10
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 warning message, increment warning count.
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 printWarning(String msg) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   272
        printWarning((DocTreePath)null, msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   273
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   274
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
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   281
        incrementWarningCount(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
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   290
        incrementWarningCount(prefix, msg);
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
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   293
    private void incrementWarningCount(String prefix, String msg) {
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   294
        if (nwarnings < MaxWarnings) {
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   295
            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
   296
            printRawLines(warnWriter, prefix + ": " + getText("javadoc.warning") + " - " + msg);
5850
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   297
            warnWriter.flush();
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   298
            nwarnings++;
6f095ff5b469 6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents: 5520
diff changeset
   299
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
     * Part of DocErrorReporter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     * @param msg message to print
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    public void printNotice(String msg) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   309
        printNotice((DocTreePath)null, msg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   312
    public void printNotice(DocTreePath path, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   313
        String prefix = getDiagSource(path);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   314
        if (diagListener != null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   315
            report(DiagnosticType.NOTE, null, prefix + ": " + msg);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   316
            return;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   317
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   318
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   319
        PrintWriter noticeWriter = getWriter(WriterKind.NOTICE);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   320
        if (path == null) {
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   321
            printRawLines(noticeWriter, msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   322
        } else {
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   323
            printRawLines(noticeWriter, prefix + ": " + msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   324
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   325
        noticeWriter.flush();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   326
    }
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
    public void printNotice(Element e, String msg) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   329
        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
   330
        if (diagListener != null) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   331
            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
   332
            return;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   333
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   334
40232
4995ab1a4558 8162359: javac should use stdout for --help and --version
jjg
parents: 37750
diff changeset
   335
        PrintWriter noticeWriter = getWriter(WriterKind.NOTICE);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   336
        if (e == null) {
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   337
            printRawLines(noticeWriter, msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   338
        } else {
41252
058d83c9b1c7 8166144: New javadoc options don't conform to JEP 293 (GNU style options)
jjg
parents: 40232
diff changeset
   339
            printRawLines(noticeWriter, pos + ": " + msg);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   340
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        noticeWriter.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     * Print error message, increment error count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   349
    public void error(Element e, String key, Object... args) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   350
        printError(e, getText(key, args));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   351
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   352
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   353
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   354
     * Print error message, increment error count.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   355
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   356
     * @param key selects message from resource
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   357
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   358
    public void error(DocTreePath path, String key, Object... args) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   359
        printError(path, getText(key, args));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   360
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   361
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   362
    public void error(String key, Object... args) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   363
        printError((Element)null, getText(key, args));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   364
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   365
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   366
    public void warning(String key, Object... args) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   367
        printWarning((Element)null, getText(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
     * Print warning message, increment warning count.
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   375
    public void warning(Element e, String key, Object... args) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   376
        printWarning(e, getText(key, args));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   377
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   378
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   379
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   380
     * Print warning message, increment warning count.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   381
     *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   382
     * @param key selects message from resource
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   383
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   384
    public void warning(DocTreePath path, String key, Object... args) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   385
        printWarning(path, getText(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
     * Print a message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
     * @param key selects message from resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
     */
14543
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   393
    public void notice(String key, Object... args) {
43edeaf6d0a9 8003257: refactor javadoc tool option handling
jjg
parents: 14260
diff changeset
   394
        printNotice(getText(key, args));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
     * Return total number of errors, including those recorded
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
     * in the compilation log.
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    public int nerrors() { return nerrors; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     * Return total number of warnings, including those recorded
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     * in the compilation log.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    public int nwarnings() { return nwarnings; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
     * Print exit message.
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    public void exitNotice() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
        if (nerrors > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
            notice((nerrors > 1) ? "main.errors" : "main.error",
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
                   "" + nerrors);
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        if (nwarnings > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
            notice((nwarnings > 1) ?  "main.warnings" : "main.warning",
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
                   "" + nwarnings);
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 28892
diff changeset
   423
    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
   424
        switch (type) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   425
            case ERROR:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   426
            case WARNING:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   427
                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
   428
                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
   429
                break;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   430
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   431
            case NOTE:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   432
                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
   433
                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
   434
                break;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   435
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   436
            default:
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   437
                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
   438
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents: 14543
diff changeset
   439
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
}