author | jjg |
Thu, 10 Jun 2010 16:08:01 -0700 | |
changeset 5847 | 1908176fd6e3 |
parent 5520 | 86e4b9a9da40 |
child 6151 | dd513881e71d |
permissions | -rw-r--r-- |
867 | 1 |
/* |
5520 | 2 |
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. |
867 | 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 |
867 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
867 | 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. |
|
867 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.util; |
|
27 |
||
28 |
import java.util.HashMap; |
|
29 |
import java.util.Map; |
|
30 |
import javax.tools.JavaFileObject; |
|
31 |
||
32 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
33 |
import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; |
|
34 |
||
35 |
||
36 |
/** |
|
37 |
* A base class for error logs. Reports errors and warnings, and |
|
38 |
* keeps track of error numbers and positions. |
|
39 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
40 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
41 |
* If you write code that depends on this, you do so at your own risk. |
867 | 42 |
* This code and its internal interfaces are subject to change or |
43 |
* deletion without notice.</b> |
|
44 |
*/ |
|
45 |
public abstract class AbstractLog { |
|
46 |
AbstractLog(JCDiagnostic.Factory diags) { |
|
47 |
this.diags = diags; |
|
48 |
sourceMap = new HashMap<JavaFileObject, DiagnosticSource>(); |
|
49 |
} |
|
50 |
||
51 |
/** Re-assign source, returning previous setting. |
|
52 |
*/ |
|
53 |
public JavaFileObject useSource(JavaFileObject file) { |
|
54 |
JavaFileObject prev = (source == null ? null : source.getFile()); |
|
55 |
source = getSource(file); |
|
56 |
return prev; |
|
57 |
} |
|
58 |
||
59 |
protected DiagnosticSource getSource(JavaFileObject file) { |
|
60 |
if (file == null) |
|
3144
202fa249dc34
6852595: Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
mcimadamore
parents:
1591
diff
changeset
|
61 |
return DiagnosticSource.NO_SOURCE; |
867 | 62 |
DiagnosticSource s = sourceMap.get(file); |
63 |
if (s == null) { |
|
64 |
s = new DiagnosticSource(file, this); |
|
65 |
sourceMap.put(file, s); |
|
66 |
} |
|
67 |
return s; |
|
68 |
} |
|
69 |
||
1591 | 70 |
/** Return the underlying diagnostic source |
71 |
*/ |
|
72 |
public DiagnosticSource currentSource() { |
|
73 |
return source; |
|
74 |
} |
|
75 |
||
867 | 76 |
/** Report an error, unless another error was already reported at same |
77 |
* source position. |
|
78 |
* @param key The key for the localized error message. |
|
79 |
* @param args Fields of the error message. |
|
80 |
*/ |
|
81 |
public void error(String key, Object ... args) { |
|
82 |
report(diags.error(source, null, key, args)); |
|
83 |
} |
|
84 |
||
85 |
/** Report an error, unless another error was already reported at same |
|
86 |
* source position. |
|
87 |
* @param pos The source position at which to report the error. |
|
88 |
* @param key The key for the localized error message. |
|
89 |
* @param args Fields of the error message. |
|
90 |
*/ |
|
91 |
public void error(DiagnosticPosition pos, String key, Object ... args) { |
|
92 |
report(diags.error(source, pos, key, args)); |
|
93 |
} |
|
94 |
||
95 |
/** Report an error, unless another error was already reported at same |
|
96 |
* source position. |
|
97 |
* @param pos The source position at which to report the error. |
|
98 |
* @param key The key for the localized error message. |
|
99 |
* @param args Fields of the error message. |
|
100 |
*/ |
|
101 |
public void error(int pos, String key, Object ... args) { |
|
102 |
report(diags.error(source, wrap(pos), key, args)); |
|
103 |
} |
|
104 |
||
105 |
/** Report a warning, unless suppressed by the -nowarn option or the |
|
106 |
* maximum number of warnings has been reached. |
|
107 |
* @param pos The source position at which to report the warning. |
|
108 |
* @param key The key for the localized warning message. |
|
109 |
* @param args Fields of the warning message. |
|
110 |
*/ |
|
111 |
public void warning(String key, Object ... args) { |
|
112 |
report(diags.warning(source, null, key, args)); |
|
113 |
} |
|
114 |
||
115 |
/** Report a warning, unless suppressed by the -nowarn option or the |
|
116 |
* maximum number of warnings has been reached. |
|
117 |
* @param pos The source position at which to report the warning. |
|
118 |
* @param key The key for the localized warning message. |
|
119 |
* @param args Fields of the warning message. |
|
120 |
*/ |
|
121 |
public void warning(DiagnosticPosition pos, String key, Object ... args) { |
|
122 |
report(diags.warning(source, pos, key, args)); |
|
123 |
} |
|
124 |
||
125 |
/** Report a warning, unless suppressed by the -nowarn option or the |
|
126 |
* maximum number of warnings has been reached. |
|
127 |
* @param pos The source position at which to report the warning. |
|
128 |
* @param key The key for the localized warning message. |
|
129 |
* @param args Fields of the warning message. |
|
130 |
*/ |
|
131 |
public void warning(int pos, String key, Object ... args) { |
|
132 |
report(diags.warning(source, wrap(pos), key, args)); |
|
133 |
} |
|
134 |
||
135 |
/** Report a warning. |
|
136 |
* @param pos The source position at which to report the warning. |
|
137 |
* @param key The key for the localized warning message. |
|
138 |
* @param args Fields of the warning message. |
|
139 |
*/ |
|
140 |
public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) { |
|
141 |
report(diags.mandatoryWarning(source, pos, key, args)); |
|
142 |
} |
|
143 |
||
144 |
/** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
|
145 |
* @param key The key for the localized notification message. |
|
146 |
* @param args Fields of the notint an error or warning message: |
|
147 |
*/ |
|
148 |
public void note(String key, Object ... args) { |
|
149 |
report(diags.note(source, null, key, args)); |
|
150 |
} |
|
151 |
||
152 |
/** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
|
153 |
* @param key The key for the localized notification message. |
|
154 |
* @param args Fields of the notification message. |
|
155 |
*/ |
|
156 |
public void note(DiagnosticPosition pos, String key, Object ... args) { |
|
157 |
report(diags.note(source, pos, key, args)); |
|
158 |
} |
|
159 |
||
160 |
/** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
|
161 |
* @param key The key for the localized notification message. |
|
162 |
* @param args Fields of the notification message. |
|
163 |
*/ |
|
164 |
public void note(int pos, String key, Object ... args) { |
|
165 |
report(diags.note(source, wrap(pos), key, args)); |
|
166 |
} |
|
167 |
||
168 |
/** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
|
169 |
* @param key The key for the localized notification message. |
|
170 |
* @param args Fields of the notification message. |
|
171 |
*/ |
|
172 |
public void note(JavaFileObject file, String key, Object ... args) { |
|
173 |
report(diags.note(getSource(file), null, key, args)); |
|
174 |
} |
|
175 |
||
176 |
/** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
|
177 |
* @param key The key for the localized notification message. |
|
178 |
* @param args Fields of the notification message. |
|
179 |
*/ |
|
180 |
public void mandatoryNote(final JavaFileObject file, String key, Object ... args) { |
|
181 |
report(diags.mandatoryNote(getSource(file), key, args)); |
|
182 |
} |
|
183 |
||
184 |
protected abstract void report(JCDiagnostic diagnostic); |
|
185 |
||
186 |
protected abstract void directError(String key, Object... args); |
|
187 |
||
188 |
private DiagnosticPosition wrap(int pos) { |
|
189 |
return (pos == Position.NOPOS ? null : new SimpleDiagnosticPosition(pos)); |
|
190 |
} |
|
191 |
||
192 |
/** Factory for diagnostics |
|
193 |
*/ |
|
194 |
protected JCDiagnostic.Factory diags; |
|
195 |
||
196 |
/** The file that's currently being translated. |
|
197 |
*/ |
|
198 |
protected DiagnosticSource source; |
|
199 |
||
200 |
/** A cache of lightweight DiagnosticSource objects. |
|
201 |
*/ |
|
202 |
protected Map<JavaFileObject, DiagnosticSource> sourceMap; |
|
203 |
} |