author | jlahoda |
Fri, 09 Mar 2018 09:42:10 +0100 | |
changeset 49197 | cc2673fa8c20 |
parent 47216 | 71c04702a3d5 |
child 55138 | b564f266dda0 |
permissions | -rw-r--r-- |
10 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
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 | 28 |
|
14543 | 29 |
import java.io.PrintWriter; |
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 | 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 | 44 |
import com.sun.tools.javac.util.Context; |
14543 | 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 | 47 |
import com.sun.tools.javac.util.JavacMessages; |
14258 | 48 |
import com.sun.tools.javac.util.Log; |
10 | 49 |
|
50 |
/** |
|
51 |
* Utility for integrating with javadoc tools and for localization. |
|
41451 | 52 |
* Handle resources, access to error and warning counts and |
53 |
* message formatting. |
|
10 | 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 | 60 |
* @see java.util.ResourceBundle |
61 |
* @see java.text.MessageFormat |
|
62 |
* @author Neal Gafter (rewrite) |
|
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 | 66 |
|
67 |
/** Get the current messager, which is also the compiler log. */ |
|
68 |
public static Messager instance0(Context context) { |
|
69 |
Log instance = context.get(logKey); |
|
70 |
if (instance == null || !(instance instanceof Messager)) |
|
71 |
throw new InternalError("no messager instance!"); |
|
72 |
return (Messager)instance; |
|
73 |
} |
|
74 |
||
8614 | 75 |
public static void preRegister(Context context, |
10 | 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 | 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 | 131 |
} |
132 |
||
5850
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5520
diff
changeset
|
133 |
final String programName; |
10 | 134 |
|
14543 | 135 |
private Locale locale; |
136 |
private final JavacMessages messages; |
|
137 |
private final JCDiagnostic.Factory javadocDiags; |
|
10 | 138 |
|
139 |
/** The default writer for diagnostics |
|
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 | 142 |
static final PrintWriter defaultErrWriter = new PrintWriter(System.err); |
143 |
||
144 |
/** |
|
145 |
* Constructor |
|
146 |
* @param programName Name of the program (for error messages). |
|
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 | 150 |
} |
151 |
||
152 |
/** |
|
153 |
* Constructor |
|
154 |
* @param programName Name of the program (for error messages). |
|
41448 | 155 |
* @param outWriter Stream for notices etc. |
156 |
* @param errWriter Stream for errors and warnings |
|
10 | 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 | 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 | 164 |
javadocDiags = new JCDiagnostic.Factory(messages, "javadoc"); |
10 | 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 | 168 |
} |
169 |
||
14543 | 170 |
public void setLocale(Locale locale) { |
171 |
this.locale = locale; |
|
10 | 172 |
} |
173 |
||
174 |
/** |
|
175 |
* get and format message string from resource |
|
176 |
* |
|
177 |
* @param key selects message from resource |
|
14543 | 178 |
* @param args arguments for the message |
10 | 179 |
*/ |
14543 | 180 |
String getText(String key, Object... args) { |
181 |
return messages.getLocalizedString(locale, key, args); |
|
10 | 182 |
} |
183 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
28892
diff
changeset
|
184 |
private String getDiagSource(DocTreePath path) { |
43261 | 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 | 214 |
/** |
215 |
* Print error message, increment error count. |
|
216 |
* Part of DocErrorReporter. |
|
217 |
* |
|
218 |
* @param msg message to print |
|
219 |
*/ |
|
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 | 230 |
printError(prefix, msg); |
10 | 231 |
} |
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 | 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 | 242 |
public void printErrorUsingKey(String key, Object... args) { |
243 |
printError((Element)null, getText(key, args)); |
|
244 |
} |
|
245 |
||
246 |
// print the error and increment count |
|
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 | 255 |
} |
256 |
||
257 |
/** |
|
258 |
* Print warning message, increment warning count. |
|
259 |
* Part of DocErrorReporter. |
|
260 |
* |
|
261 |
* @param msg message to print |
|
262 |
*/ |
|
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 | 267 |
public void printWarningUsingKey(String key, Object... args) { |
268 |
printWarning((Element)null, getText(key, args)); |
|
269 |
} |
|
270 |
||
271 |
public void printWarning(Element e, String key, Object... args) { |
|
272 |
printWarning(getText(key, args)); |
|
273 |
} |
|
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 | 281 |
printWarning(prefix, msg); |
10 | 282 |
} |
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 | 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 | 293 |
// print the warning and increment count |
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 | 301 |
} |
302 |
||
303 |
/** |
|
304 |
* Print a message. |
|
305 |
* Part of DocErrorReporter. |
|
306 |
* |
|
307 |
* @param msg message to print |
|
308 |
*/ |
|
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 | 311 |
} |
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 | 342 |
noticeWriter.flush(); |
343 |
} |
|
344 |
||
345 |
/** |
|
346 |
* Print a message. |
|
347 |
* |
|
348 |
* @param key selects message from resource |
|
349 |
*/ |
|
14543 | 350 |
public void notice(String key, Object... args) { |
351 |
printNotice(getText(key, args)); |
|
10 | 352 |
} |
353 |
||
354 |
/** |
|
41451 | 355 |
* Returns true if errors have been recorded. |
10 | 356 |
*/ |
41451 | 357 |
public boolean hasErrors() { |
358 |
return nerrors != 0; |
|
359 |
} |
|
10 | 360 |
|
361 |
/** |
|
41451 | 362 |
* Returns true if warnings have been recorded. |
10 | 363 |
*/ |
41451 | 364 |
public boolean hasWarnings() { |
365 |
return nwarnings != 0; |
|
366 |
} |
|
10 | 367 |
|
368 |
/** |
|
369 |
* Print exit message. |
|
370 |
*/ |
|
41451 | 371 |
public void printErrorWarningCounts() { |
10 | 372 |
if (nerrors > 0) { |
373 |
notice((nerrors > 1) ? "main.errors" : "main.error", |
|
374 |
"" + nerrors); |
|
375 |
} |
|
376 |
if (nwarnings > 0) { |
|
377 |
notice((nwarnings > 1) ? "main.warnings" : "main.warning", |
|
378 |
"" + nwarnings); |
|
379 |
} |
|
380 |
} |
|
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 | 399 |
} |