author | jjg |
Mon, 10 Jan 2011 15:08:31 -0800 | |
changeset 8032 | e1aa25ccdabb |
parent 8031 | d5fe2c1cecfc |
child 8037 | b3f278fe95d6 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
8031 | 2 |
* Copyright (c) 1999, 2011, 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 |
||
26 |
package com.sun.tools.javac.comp; |
|
27 |
||
28 |
import java.util.*; |
|
29 |
import java.util.Set; |
|
30 |
||
31 |
import com.sun.tools.javac.code.*; |
|
32 |
import com.sun.tools.javac.jvm.*; |
|
33 |
import com.sun.tools.javac.tree.*; |
|
34 |
import com.sun.tools.javac.util.*; |
|
35 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
36 |
import com.sun.tools.javac.util.List; |
|
37 |
||
38 |
import com.sun.tools.javac.tree.JCTree.*; |
|
39 |
import com.sun.tools.javac.code.Lint; |
|
40 |
import com.sun.tools.javac.code.Lint.LintCategory; |
|
41 |
import com.sun.tools.javac.code.Type.*; |
|
42 |
import com.sun.tools.javac.code.Symbol.*; |
|
43 |
||
44 |
import static com.sun.tools.javac.code.Flags.*; |
|
45 |
import static com.sun.tools.javac.code.Kinds.*; |
|
46 |
import static com.sun.tools.javac.code.TypeTags.*; |
|
47 |
||
6721 | 48 |
import static com.sun.tools.javac.main.OptionName.*; |
49 |
||
10 | 50 |
/** Type checking helper class for the attribution phase. |
51 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
52 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
53 |
* If you write code that depends on this, you do so at your own risk. |
10 | 54 |
* This code and its internal interfaces are subject to change or |
55 |
* deletion without notice.</b> |
|
56 |
*/ |
|
57 |
public class Check { |
|
58 |
protected static final Context.Key<Check> checkKey = |
|
59 |
new Context.Key<Check>(); |
|
60 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
61 |
private final Names names; |
10 | 62 |
private final Log log; |
63 |
private final Symtab syms; |
|
6711
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
64 |
private final Enter enter; |
10 | 65 |
private final Infer infer; |
66 |
private final Types types; |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
67 |
private final JCDiagnostic.Factory diags; |
10 | 68 |
private final boolean skipAnnotations; |
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
69 |
private boolean warnOnSyntheticConflicts; |
5842
714e365b4b1b
6955264: add option to suppress Abort in Check.completionError
jjg
parents:
5654
diff
changeset
|
70 |
private boolean suppressAbortOnBadClassFile; |
10 | 71 |
private final TreeInfo treeinfo; |
72 |
||
73 |
// The set of lint options currently in effect. It is initialized |
|
74 |
// from the context, and then is set/reset as needed by Attr as it |
|
75 |
// visits all the various parts of the trees during attribution. |
|
76 |
private Lint lint; |
|
77 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
78 |
// The method being analyzed in Attr - it is set/reset as needed by |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
79 |
// Attr as it visits new method declarations. |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
80 |
private MethodSymbol method; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
81 |
|
10 | 82 |
public static Check instance(Context context) { |
83 |
Check instance = context.get(checkKey); |
|
84 |
if (instance == null) |
|
85 |
instance = new Check(context); |
|
86 |
return instance; |
|
87 |
} |
|
88 |
||
89 |
protected Check(Context context) { |
|
90 |
context.put(checkKey, this); |
|
91 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
92 |
names = Names.instance(context); |
10 | 93 |
log = Log.instance(context); |
94 |
syms = Symtab.instance(context); |
|
6711
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
95 |
enter = Enter.instance(context); |
10 | 96 |
infer = Infer.instance(context); |
97 |
this.types = Types.instance(context); |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
98 |
diags = JCDiagnostic.Factory.instance(context); |
10 | 99 |
Options options = Options.instance(context); |
100 |
lint = Lint.instance(context); |
|
101 |
treeinfo = TreeInfo.instance(context); |
|
102 |
||
103 |
Source source = Source.instance(context); |
|
104 |
allowGenerics = source.allowGenerics(); |
|
105 |
allowAnnotations = source.allowAnnotations(); |
|
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
106 |
allowCovariantReturns = source.allowCovariantReturns(); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
107 |
allowSimplifiedVarargs = source.allowSimplifiedVarargs(); |
6721 | 108 |
complexInference = options.isSet(COMPLEXINFERENCE); |
109 |
skipAnnotations = options.isSet("skipAnnotations"); |
|
110 |
warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); |
|
111 |
suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile"); |
|
10 | 112 |
|
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
113 |
Target target = Target.instance(context); |
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
114 |
syntheticNameChar = target.syntheticNameChar(); |
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
115 |
|
10 | 116 |
boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION); |
117 |
boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED); |
|
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
118 |
boolean verboseVarargs = lint.isEnabled(LintCategory.VARARGS); |
3661 | 119 |
boolean verboseSunApi = lint.isEnabled(LintCategory.SUNAPI); |
813 | 120 |
boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings(); |
10 | 121 |
|
813 | 122 |
deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
123 |
enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION); |
813 | 124 |
uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
125 |
enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED); |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
126 |
unsafeVarargsHandler = new MandatoryWarningHandler(log, verboseVarargs, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
127 |
enforceMandatoryWarnings, "varargs", LintCategory.VARARGS); |
3661 | 128 |
sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
129 |
enforceMandatoryWarnings, "sunapi", null); |
10 | 130 |
} |
131 |
||
132 |
/** Switch: generics enabled? |
|
133 |
*/ |
|
134 |
boolean allowGenerics; |
|
135 |
||
136 |
/** Switch: annotations enabled? |
|
137 |
*/ |
|
138 |
boolean allowAnnotations; |
|
139 |
||
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
140 |
/** Switch: covariant returns enabled? |
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
141 |
*/ |
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
142 |
boolean allowCovariantReturns; |
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
143 |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
144 |
/** Switch: simplified varargs enabled? |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
145 |
*/ |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
146 |
boolean allowSimplifiedVarargs; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
147 |
|
10 | 148 |
/** Switch: -complexinference option set? |
149 |
*/ |
|
150 |
boolean complexInference; |
|
151 |
||
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
152 |
/** Character for synthetic names |
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
153 |
*/ |
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
154 |
char syntheticNameChar; |
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
155 |
|
10 | 156 |
/** A table mapping flat names of all compiled classes in this run to their |
157 |
* symbols; maintained from outside. |
|
158 |
*/ |
|
159 |
public Map<Name,ClassSymbol> compiled = new HashMap<Name, ClassSymbol>(); |
|
160 |
||
161 |
/** A handler for messages about deprecated usage. |
|
162 |
*/ |
|
163 |
private MandatoryWarningHandler deprecationHandler; |
|
164 |
||
165 |
/** A handler for messages about unchecked or unsafe usage. |
|
166 |
*/ |
|
167 |
private MandatoryWarningHandler uncheckedHandler; |
|
168 |
||
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
169 |
/** A handler for messages about unchecked or unsafe vararg method decl. |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
170 |
*/ |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
171 |
private MandatoryWarningHandler unsafeVarargsHandler; |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
172 |
|
5848
c5a4ce47e780
6960407: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5847
diff
changeset
|
173 |
/** A handler for messages about using proprietary API. |
3661 | 174 |
*/ |
175 |
private MandatoryWarningHandler sunApiHandler; |
|
10 | 176 |
|
177 |
/* ************************************************************************* |
|
178 |
* Errors and Warnings |
|
179 |
**************************************************************************/ |
|
180 |
||
181 |
Lint setLint(Lint newLint) { |
|
182 |
Lint prev = lint; |
|
183 |
lint = newLint; |
|
184 |
return prev; |
|
185 |
} |
|
186 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
187 |
MethodSymbol setMethod(MethodSymbol newMethod) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
188 |
MethodSymbol prev = method; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
189 |
method = newMethod; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
190 |
return prev; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
191 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
192 |
|
10 | 193 |
/** Warn about deprecated symbol. |
194 |
* @param pos Position to be used for error reporting. |
|
195 |
* @param sym The deprecated symbol. |
|
196 |
*/ |
|
197 |
void warnDeprecated(DiagnosticPosition pos, Symbol sym) { |
|
198 |
if (!lint.isSuppressed(LintCategory.DEPRECATION)) |
|
199 |
deprecationHandler.report(pos, "has.been.deprecated", sym, sym.location()); |
|
200 |
} |
|
201 |
||
202 |
/** Warn about unchecked operation. |
|
203 |
* @param pos Position to be used for error reporting. |
|
204 |
* @param msg A string describing the problem. |
|
205 |
*/ |
|
206 |
public void warnUnchecked(DiagnosticPosition pos, String msg, Object... args) { |
|
207 |
if (!lint.isSuppressed(LintCategory.UNCHECKED)) |
|
208 |
uncheckedHandler.report(pos, msg, args); |
|
209 |
} |
|
210 |
||
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
211 |
/** Warn about unsafe vararg method decl. |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
212 |
* @param pos Position to be used for error reporting. |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
213 |
* @param sym The deprecated symbol. |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
214 |
*/ |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
215 |
void warnUnsafeVararg(DiagnosticPosition pos, String key, Object... args) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
216 |
if (lint.isEnabled(LintCategory.VARARGS) && allowSimplifiedVarargs) |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
217 |
log.warning(LintCategory.VARARGS, pos, key, args); |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
218 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
219 |
|
5848
c5a4ce47e780
6960407: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5847
diff
changeset
|
220 |
/** Warn about using proprietary API. |
3661 | 221 |
* @param pos Position to be used for error reporting. |
222 |
* @param msg A string describing the problem. |
|
223 |
*/ |
|
224 |
public void warnSunApi(DiagnosticPosition pos, String msg, Object... args) { |
|
225 |
if (!lint.isSuppressed(LintCategory.SUNAPI)) |
|
226 |
sunApiHandler.report(pos, msg, args); |
|
227 |
} |
|
228 |
||
5002
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
4867
diff
changeset
|
229 |
public void warnStatic(DiagnosticPosition pos, String msg, Object... args) { |
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
4867
diff
changeset
|
230 |
if (lint.isEnabled(LintCategory.STATIC)) |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
231 |
log.warning(LintCategory.STATIC, pos, msg, args); |
5002
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
4867
diff
changeset
|
232 |
} |
12a9e8562200
4880220: Add a warning when accessing a static method via an reference
jjg
parents:
4867
diff
changeset
|
233 |
|
10 | 234 |
/** |
235 |
* Report any deferred diagnostics. |
|
236 |
*/ |
|
237 |
public void reportDeferredDiagnostics() { |
|
238 |
deprecationHandler.reportDeferredDiagnostic(); |
|
239 |
uncheckedHandler.reportDeferredDiagnostic(); |
|
3661 | 240 |
sunApiHandler.reportDeferredDiagnostic(); |
10 | 241 |
} |
242 |
||
243 |
||
244 |
/** Report a failure to complete a class. |
|
245 |
* @param pos Position to be used for error reporting. |
|
246 |
* @param ex The failure to report. |
|
247 |
*/ |
|
248 |
public Type completionError(DiagnosticPosition pos, CompletionFailure ex) { |
|
169 | 249 |
log.error(pos, "cant.access", ex.sym, ex.getDetailValue()); |
5842
714e365b4b1b
6955264: add option to suppress Abort in Check.completionError
jjg
parents:
5654
diff
changeset
|
250 |
if (ex instanceof ClassReader.BadClassFile |
714e365b4b1b
6955264: add option to suppress Abort in Check.completionError
jjg
parents:
5654
diff
changeset
|
251 |
&& !suppressAbortOnBadClassFile) throw new Abort(); |
10 | 252 |
else return syms.errType; |
253 |
} |
|
254 |
||
255 |
/** Report a type error. |
|
256 |
* @param pos Position to be used for error reporting. |
|
257 |
* @param problem A string describing the error. |
|
258 |
* @param found The type that was found. |
|
259 |
* @param req The type that was required. |
|
260 |
*/ |
|
261 |
Type typeError(DiagnosticPosition pos, Object problem, Type found, Type req) { |
|
262 |
log.error(pos, "prob.found.req", |
|
263 |
problem, found, req); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
264 |
return types.createErrorType(found); |
10 | 265 |
} |
266 |
||
267 |
Type typeError(DiagnosticPosition pos, String problem, Type found, Type req, Object explanation) { |
|
268 |
log.error(pos, "prob.found.req.1", problem, found, req, explanation); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
269 |
return types.createErrorType(found); |
10 | 270 |
} |
271 |
||
272 |
/** Report an error that wrong type tag was found. |
|
273 |
* @param pos Position to be used for error reporting. |
|
274 |
* @param required An internationalized string describing the type tag |
|
275 |
* required. |
|
276 |
* @param found The type that was found. |
|
277 |
*/ |
|
278 |
Type typeTagError(DiagnosticPosition pos, Object required, Object found) { |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
279 |
// this error used to be raised by the parser, |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
280 |
// but has been delayed to this point: |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
281 |
if (found instanceof Type && ((Type)found).tag == VOID) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
282 |
log.error(pos, "illegal.start.of.type"); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
283 |
return syms.errType; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
284 |
} |
10 | 285 |
log.error(pos, "type.found.req", found, required); |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
286 |
return types.createErrorType(found instanceof Type ? (Type)found : syms.errType); |
10 | 287 |
} |
288 |
||
289 |
/** Report an error that symbol cannot be referenced before super |
|
290 |
* has been called. |
|
291 |
* @param pos Position to be used for error reporting. |
|
292 |
* @param sym The referenced symbol. |
|
293 |
*/ |
|
294 |
void earlyRefError(DiagnosticPosition pos, Symbol sym) { |
|
295 |
log.error(pos, "cant.ref.before.ctor.called", sym); |
|
296 |
} |
|
297 |
||
298 |
/** Report duplicate declaration error. |
|
299 |
*/ |
|
300 |
void duplicateError(DiagnosticPosition pos, Symbol sym) { |
|
301 |
if (!sym.type.isErroneous()) { |
|
302 |
log.error(pos, "already.defined", sym, sym.location()); |
|
303 |
} |
|
304 |
} |
|
305 |
||
306 |
/** Report array/varargs duplicate declaration |
|
307 |
*/ |
|
308 |
void varargsDuplicateError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) { |
|
309 |
if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) { |
|
310 |
log.error(pos, "array.and.varargs", sym1, sym2, sym2.location()); |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
/* ************************************************************************ |
|
315 |
* duplicate declaration checking |
|
316 |
*************************************************************************/ |
|
317 |
||
318 |
/** Check that variable does not hide variable with same name in |
|
319 |
* immediately enclosing local scope. |
|
320 |
* @param pos Position for error reporting. |
|
321 |
* @param v The symbol. |
|
322 |
* @param s The scope. |
|
323 |
*/ |
|
324 |
void checkTransparentVar(DiagnosticPosition pos, VarSymbol v, Scope s) { |
|
325 |
if (s.next != null) { |
|
326 |
for (Scope.Entry e = s.next.lookup(v.name); |
|
327 |
e.scope != null && e.sym.owner == v.owner; |
|
328 |
e = e.next()) { |
|
329 |
if (e.sym.kind == VAR && |
|
330 |
(e.sym.owner.kind & (VAR | MTH)) != 0 && |
|
331 |
v.name != names.error) { |
|
332 |
duplicateError(pos, e.sym); |
|
333 |
return; |
|
334 |
} |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
/** Check that a class or interface does not hide a class or |
|
340 |
* interface with same name in immediately enclosing local scope. |
|
341 |
* @param pos Position for error reporting. |
|
342 |
* @param c The symbol. |
|
343 |
* @param s The scope. |
|
344 |
*/ |
|
345 |
void checkTransparentClass(DiagnosticPosition pos, ClassSymbol c, Scope s) { |
|
346 |
if (s.next != null) { |
|
347 |
for (Scope.Entry e = s.next.lookup(c.name); |
|
348 |
e.scope != null && e.sym.owner == c.owner; |
|
349 |
e = e.next()) { |
|
6352
217d5a69681a
6977800: Regression: invalid resolution of supertype for local class
mcimadamore
parents:
6351
diff
changeset
|
350 |
if (e.sym.kind == TYP && e.sym.type.tag != TYPEVAR && |
10 | 351 |
(e.sym.owner.kind & (VAR | MTH)) != 0 && |
352 |
c.name != names.error) { |
|
353 |
duplicateError(pos, e.sym); |
|
354 |
return; |
|
355 |
} |
|
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
/** Check that class does not have the same name as one of |
|
361 |
* its enclosing classes, or as a class defined in its enclosing scope. |
|
362 |
* return true if class is unique in its enclosing scope. |
|
363 |
* @param pos Position for error reporting. |
|
364 |
* @param name The class name. |
|
365 |
* @param s The enclosing scope. |
|
366 |
*/ |
|
367 |
boolean checkUniqueClassName(DiagnosticPosition pos, Name name, Scope s) { |
|
368 |
for (Scope.Entry e = s.lookup(name); e.scope == s; e = e.next()) { |
|
369 |
if (e.sym.kind == TYP && e.sym.name != names.error) { |
|
370 |
duplicateError(pos, e.sym); |
|
371 |
return false; |
|
372 |
} |
|
373 |
} |
|
374 |
for (Symbol sym = s.owner; sym != null; sym = sym.owner) { |
|
375 |
if (sym.kind == TYP && sym.name == name && sym.name != names.error) { |
|
376 |
duplicateError(pos, sym); |
|
377 |
return true; |
|
378 |
} |
|
379 |
} |
|
380 |
return true; |
|
381 |
} |
|
382 |
||
383 |
/* ************************************************************************* |
|
384 |
* Class name generation |
|
385 |
**************************************************************************/ |
|
386 |
||
387 |
/** Return name of local class. |
|
388 |
* This is of the form <enclClass> $ n <classname> |
|
389 |
* where |
|
390 |
* enclClass is the flat name of the enclosing class, |
|
391 |
* classname is the simple name of the local class |
|
392 |
*/ |
|
393 |
Name localClassName(ClassSymbol c) { |
|
394 |
for (int i=1; ; i++) { |
|
395 |
Name flatname = names. |
|
396 |
fromString("" + c.owner.enclClass().flatname + |
|
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
397 |
syntheticNameChar + i + |
10 | 398 |
c.name); |
399 |
if (compiled.get(flatname) == null) return flatname; |
|
400 |
} |
|
401 |
} |
|
402 |
||
403 |
/* ************************************************************************* |
|
404 |
* Type Checking |
|
405 |
**************************************************************************/ |
|
406 |
||
407 |
/** Check that a given type is assignable to a given proto-type. |
|
408 |
* If it is, return the type, otherwise return errType. |
|
409 |
* @param pos Position to be used for error reporting. |
|
410 |
* @param found The type that was found. |
|
411 |
* @param req The type that was required. |
|
412 |
*/ |
|
413 |
Type checkType(DiagnosticPosition pos, Type found, Type req) { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6147
diff
changeset
|
414 |
return checkType(pos, found, req, "incompatible.types"); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6147
diff
changeset
|
415 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6147
diff
changeset
|
416 |
|
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6147
diff
changeset
|
417 |
Type checkType(DiagnosticPosition pos, Type found, Type req, String errKey) { |
10 | 418 |
if (req.tag == ERROR) |
419 |
return req; |
|
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
420 |
if (found.tag == FORALL) |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
421 |
return instantiatePoly(pos, (ForAll)found, req, convertWarner(pos, found, req)); |
10 | 422 |
if (req.tag == NONE) |
423 |
return found; |
|
424 |
if (types.isAssignable(found, req, convertWarner(pos, found, req))) |
|
425 |
return found; |
|
426 |
if (found.tag <= DOUBLE && req.tag <= DOUBLE) |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
427 |
return typeError(pos, diags.fragment("possible.loss.of.precision"), found, req); |
10 | 428 |
if (found.isSuperBound()) { |
429 |
log.error(pos, "assignment.from.super-bound", found); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
430 |
return types.createErrorType(found); |
10 | 431 |
} |
432 |
if (req.isExtendsBound()) { |
|
433 |
log.error(pos, "assignment.to.extends-bound", req); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
434 |
return types.createErrorType(found); |
10 | 435 |
} |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6147
diff
changeset
|
436 |
return typeError(pos, diags.fragment(errKey), found, req); |
10 | 437 |
} |
438 |
||
439 |
/** Instantiate polymorphic type to some prototype, unless |
|
440 |
* prototype is `anyPoly' in which case polymorphic type |
|
441 |
* is returned unchanged. |
|
442 |
*/ |
|
3765
9548183897cb
6840638: Project Coin: Improved Type Inference for Generic Instance Creation (aka 'diamond')
mcimadamore
parents:
3661
diff
changeset
|
443 |
Type instantiatePoly(DiagnosticPosition pos, ForAll t, Type pt, Warner warn) throws Infer.NoInstanceException { |
10 | 444 |
if (pt == Infer.anyPoly && complexInference) { |
445 |
return t; |
|
446 |
} else if (pt == Infer.anyPoly || pt.tag == NONE) { |
|
447 |
Type newpt = t.qtype.tag <= VOID ? t.qtype : syms.objectType; |
|
448 |
return instantiatePoly(pos, t, newpt, warn); |
|
449 |
} else if (pt.tag == ERROR) { |
|
450 |
return pt; |
|
451 |
} else { |
|
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
452 |
try { |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
453 |
return infer.instantiateExpr(t, pt, warn); |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
454 |
} catch (Infer.NoInstanceException ex) { |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
455 |
if (ex.isAmbiguous) { |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
456 |
JCDiagnostic d = ex.getDiagnostic(); |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
457 |
log.error(pos, |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
458 |
"undetermined.type" + (d!=null ? ".1" : ""), |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
459 |
t, d); |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
460 |
return types.createErrorType(pt); |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
461 |
} else { |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
462 |
JCDiagnostic d = ex.getDiagnostic(); |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
463 |
return typeError(pos, |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
464 |
diags.fragment("incompatible.types" + (d!=null ? ".1" : ""), d), |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
465 |
t, pt); |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
466 |
} |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
467 |
} catch (Infer.InvalidInstanceException ex) { |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
468 |
JCDiagnostic d = ex.getDiagnostic(); |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
469 |
log.error(pos, "invalid.inferred.types", t.tvars, d); |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
470 |
return types.createErrorType(pt); |
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
471 |
} |
10 | 472 |
} |
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
473 |
} |
10 | 474 |
|
475 |
/** Check that a given type can be cast to a given target type. |
|
476 |
* Return the result of the cast. |
|
477 |
* @param pos Position to be used for error reporting. |
|
478 |
* @param found The type that is being cast. |
|
479 |
* @param req The target type of the cast. |
|
480 |
*/ |
|
481 |
Type checkCastable(DiagnosticPosition pos, Type found, Type req) { |
|
482 |
if (found.tag == FORALL) { |
|
483 |
instantiatePoly(pos, (ForAll) found, req, castWarner(pos, found, req)); |
|
484 |
return req; |
|
485 |
} else if (types.isCastable(found, req, castWarner(pos, found, req))) { |
|
486 |
return req; |
|
487 |
} else { |
|
488 |
return typeError(pos, |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
489 |
diags.fragment("inconvertible.types"), |
10 | 490 |
found, req); |
491 |
} |
|
492 |
} |
|
493 |
//where |
|
494 |
/** Is type a type variable, or a (possibly multi-dimensional) array of |
|
495 |
* type variables? |
|
496 |
*/ |
|
497 |
boolean isTypeVar(Type t) { |
|
498 |
return t.tag == TYPEVAR || t.tag == ARRAY && isTypeVar(types.elemtype(t)); |
|
499 |
} |
|
500 |
||
501 |
/** Check that a type is within some bounds. |
|
502 |
* |
|
503 |
* Used in TypeApply to verify that, e.g., X in V<X> is a valid |
|
504 |
* type argument. |
|
505 |
* @param pos Position to be used for error reporting. |
|
506 |
* @param a The type that should be bounded by bs. |
|
507 |
* @param bs The bound. |
|
508 |
*/ |
|
509 |
private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) { |
|
1527 | 510 |
if (a.isUnbound()) { |
511 |
return; |
|
512 |
} else if (a.tag != WILDCARD) { |
|
513 |
a = types.upperBound(a); |
|
514 |
for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) { |
|
515 |
if (!types.isSubtype(a, l.head)) { |
|
516 |
log.error(pos, "not.within.bounds", a); |
|
517 |
return; |
|
518 |
} |
|
519 |
} |
|
520 |
} else if (a.isExtendsBound()) { |
|
521 |
if (!types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings)) |
|
522 |
log.error(pos, "not.within.bounds", a); |
|
523 |
} else if (a.isSuperBound()) { |
|
524 |
if (types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound())) |
|
525 |
log.error(pos, "not.within.bounds", a); |
|
526 |
} |
|
527 |
} |
|
528 |
||
529 |
/** Check that a type is within some bounds. |
|
530 |
* |
|
531 |
* Used in TypeApply to verify that, e.g., X in V<X> is a valid |
|
532 |
* type argument. |
|
533 |
* @param pos Position to be used for error reporting. |
|
534 |
* @param a The type that should be bounded by bs. |
|
535 |
* @param bs The bound. |
|
536 |
*/ |
|
537 |
private void checkCapture(JCTypeApply tree) { |
|
538 |
List<JCExpression> args = tree.getTypeArguments(); |
|
539 |
for (Type arg : types.capture(tree.type).getTypeArguments()) { |
|
540 |
if (arg.tag == TYPEVAR && arg.getUpperBound().isErroneous()) { |
|
541 |
log.error(args.head.pos, "not.within.bounds", args.head.type); |
|
542 |
break; |
|
938
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
937
diff
changeset
|
543 |
} |
1527 | 544 |
args = args.tail; |
938
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
937
diff
changeset
|
545 |
} |
1527 | 546 |
} |
10 | 547 |
|
548 |
/** Check that type is different from 'void'. |
|
549 |
* @param pos Position to be used for error reporting. |
|
550 |
* @param t The type to be checked. |
|
551 |
*/ |
|
552 |
Type checkNonVoid(DiagnosticPosition pos, Type t) { |
|
553 |
if (t.tag == VOID) { |
|
554 |
log.error(pos, "void.not.allowed.here"); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
555 |
return types.createErrorType(t); |
10 | 556 |
} else { |
557 |
return t; |
|
558 |
} |
|
559 |
} |
|
560 |
||
561 |
/** Check that type is a class or interface type. |
|
562 |
* @param pos Position to be used for error reporting. |
|
563 |
* @param t The type to be checked. |
|
564 |
*/ |
|
565 |
Type checkClassType(DiagnosticPosition pos, Type t) { |
|
566 |
if (t.tag != CLASS && t.tag != ERROR) |
|
567 |
return typeTagError(pos, |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
568 |
diags.fragment("type.req.class"), |
10 | 569 |
(t.tag == TYPEVAR) |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
570 |
? diags.fragment("type.parameter", t) |
10 | 571 |
: t); |
572 |
else |
|
573 |
return t; |
|
574 |
} |
|
575 |
||
576 |
/** Check that type is a class or interface type. |
|
577 |
* @param pos Position to be used for error reporting. |
|
578 |
* @param t The type to be checked. |
|
579 |
* @param noBounds True if type bounds are illegal here. |
|
580 |
*/ |
|
581 |
Type checkClassType(DiagnosticPosition pos, Type t, boolean noBounds) { |
|
582 |
t = checkClassType(pos, t); |
|
583 |
if (noBounds && t.isParameterized()) { |
|
584 |
List<Type> args = t.getTypeArguments(); |
|
585 |
while (args.nonEmpty()) { |
|
586 |
if (args.head.tag == WILDCARD) |
|
587 |
return typeTagError(pos, |
|
6032 | 588 |
diags.fragment("type.req.exact"), |
10 | 589 |
args.head); |
590 |
args = args.tail; |
|
591 |
} |
|
592 |
} |
|
593 |
return t; |
|
594 |
} |
|
595 |
||
596 |
/** Check that type is a reifiable class, interface or array type. |
|
597 |
* @param pos Position to be used for error reporting. |
|
598 |
* @param t The type to be checked. |
|
599 |
*/ |
|
600 |
Type checkReifiableReferenceType(DiagnosticPosition pos, Type t) { |
|
601 |
if (t.tag != CLASS && t.tag != ARRAY && t.tag != ERROR) { |
|
602 |
return typeTagError(pos, |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
603 |
diags.fragment("type.req.class.array"), |
10 | 604 |
t); |
605 |
} else if (!types.isReifiable(t)) { |
|
606 |
log.error(pos, "illegal.generic.type.for.instof"); |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
607 |
return types.createErrorType(t); |
10 | 608 |
} else { |
609 |
return t; |
|
610 |
} |
|
611 |
} |
|
612 |
||
613 |
/** Check that type is a reference type, i.e. a class, interface or array type |
|
614 |
* or a type variable. |
|
615 |
* @param pos Position to be used for error reporting. |
|
616 |
* @param t The type to be checked. |
|
617 |
*/ |
|
618 |
Type checkRefType(DiagnosticPosition pos, Type t) { |
|
619 |
switch (t.tag) { |
|
620 |
case CLASS: |
|
621 |
case ARRAY: |
|
622 |
case TYPEVAR: |
|
623 |
case WILDCARD: |
|
624 |
case ERROR: |
|
625 |
return t; |
|
626 |
default: |
|
627 |
return typeTagError(pos, |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
628 |
diags.fragment("type.req.ref"), |
10 | 629 |
t); |
630 |
} |
|
631 |
} |
|
632 |
||
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
633 |
/** Check that each type is a reference type, i.e. a class, interface or array type |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
634 |
* or a type variable. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
635 |
* @param trees Original trees, used for error reporting. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
636 |
* @param types The types to be checked. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
637 |
*/ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
638 |
List<Type> checkRefTypes(List<JCExpression> trees, List<Type> types) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
639 |
List<JCExpression> tl = trees; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
640 |
for (List<Type> l = types; l.nonEmpty(); l = l.tail) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
641 |
l.head = checkRefType(tl.head.pos(), l.head); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
642 |
tl = tl.tail; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
643 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
644 |
return types; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
645 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2509
diff
changeset
|
646 |
|
10 | 647 |
/** Check that type is a null or reference type. |
648 |
* @param pos Position to be used for error reporting. |
|
649 |
* @param t The type to be checked. |
|
650 |
*/ |
|
651 |
Type checkNullOrRefType(DiagnosticPosition pos, Type t) { |
|
652 |
switch (t.tag) { |
|
653 |
case CLASS: |
|
654 |
case ARRAY: |
|
655 |
case TYPEVAR: |
|
656 |
case WILDCARD: |
|
657 |
case BOT: |
|
658 |
case ERROR: |
|
659 |
return t; |
|
660 |
default: |
|
661 |
return typeTagError(pos, |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
662 |
diags.fragment("type.req.ref"), |
10 | 663 |
t); |
664 |
} |
|
665 |
} |
|
666 |
||
667 |
/** Check that flag set does not contain elements of two conflicting sets. s |
|
668 |
* Return true if it doesn't. |
|
669 |
* @param pos Position to be used for error reporting. |
|
670 |
* @param flags The set of flags to be checked. |
|
671 |
* @param set1 Conflicting flags set #1. |
|
672 |
* @param set2 Conflicting flags set #2. |
|
673 |
*/ |
|
674 |
boolean checkDisjoint(DiagnosticPosition pos, long flags, long set1, long set2) { |
|
675 |
if ((flags & set1) != 0 && (flags & set2) != 0) { |
|
676 |
log.error(pos, |
|
677 |
"illegal.combination.of.modifiers", |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
938
diff
changeset
|
678 |
asFlagSet(TreeInfo.firstFlag(flags & set1)), |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
938
diff
changeset
|
679 |
asFlagSet(TreeInfo.firstFlag(flags & set2))); |
10 | 680 |
return false; |
681 |
} else |
|
682 |
return true; |
|
683 |
} |
|
684 |
||
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
685 |
/** Check that the type inferred using the diamond operator does not contain |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
686 |
* non-denotable types such as captured types or intersection types. |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
687 |
* @param t the type inferred using the diamond operator |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
688 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
689 |
List<Type> checkDiamond(ClassType t) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
690 |
DiamondTypeChecker dtc = new DiamondTypeChecker(); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
691 |
ListBuffer<Type> buf = ListBuffer.lb(); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
692 |
for (Type arg : t.getTypeArguments()) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
693 |
if (!dtc.visit(arg, null)) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
694 |
buf.append(arg); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
695 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
696 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
697 |
return buf.toList(); |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
698 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
699 |
|
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
700 |
static class DiamondTypeChecker extends Types.SimpleVisitor<Boolean, Void> { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
701 |
public Boolean visitType(Type t, Void s) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
702 |
return true; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
703 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
704 |
@Override |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
705 |
public Boolean visitClassType(ClassType t, Void s) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
706 |
if (t.isCompound()) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
707 |
return false; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
708 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
709 |
for (Type targ : t.getTypeArguments()) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
710 |
if (!visit(targ, s)) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
711 |
return false; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
712 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
713 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
714 |
return true; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
715 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
716 |
@Override |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
717 |
public Boolean visitCapturedType(CapturedType t, Void s) { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
718 |
return false; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
719 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
720 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
721 |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
722 |
void checkVarargsMethodDecl(Env<AttrContext> env, JCMethodDecl tree) { |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
723 |
MethodSymbol m = tree.sym; |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
724 |
if (!allowSimplifiedVarargs) return; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
725 |
boolean hasTrustMeAnno = m.attribute(syms.trustMeType.tsym) != null; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
726 |
Type varargElemType = null; |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
727 |
if (m.isVarArgs()) { |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
728 |
varargElemType = types.elemtype(tree.params.last().type); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
729 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
730 |
if (hasTrustMeAnno && !isTrustMeAllowedOnMethod(m)) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
731 |
if (varargElemType != null) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
732 |
log.error(tree, |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
733 |
"varargs.invalid.trustme.anno", |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
734 |
syms.trustMeType.tsym, |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
735 |
diags.fragment("varargs.trustme.on.virtual.varargs", m)); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
736 |
} else { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
737 |
log.error(tree, |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
738 |
"varargs.invalid.trustme.anno", |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
739 |
syms.trustMeType.tsym, |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
740 |
diags.fragment("varargs.trustme.on.non.varargs.meth", m)); |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
741 |
} |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
742 |
} else if (hasTrustMeAnno && varargElemType != null && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
743 |
types.isReifiable(varargElemType)) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
744 |
warnUnsafeVararg(tree, |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
745 |
"varargs.redundant.trustme.anno", |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
746 |
syms.trustMeType.tsym, |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
747 |
diags.fragment("varargs.trustme.on.reifiable.varargs", varargElemType)); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
748 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
749 |
else if (!hasTrustMeAnno && varargElemType != null && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
750 |
!types.isReifiable(varargElemType)) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
751 |
warnUnchecked(tree.params.head.pos(), "unchecked.varargs.non.reifiable.type", varargElemType); |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
752 |
} |
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
753 |
} |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
754 |
//where |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
755 |
private boolean isTrustMeAllowedOnMethod(Symbol s) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
756 |
return (s.flags() & VARARGS) != 0 && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
757 |
(s.isConstructor() || |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
758 |
(s.flags() & (STATIC | FINAL)) != 0); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
759 |
} |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
760 |
|
5489
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
761 |
/** |
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
762 |
* Check that vararg method call is sound |
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
763 |
* @param pos Position to be used for error reporting. |
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
764 |
* @param argtypes Actual arguments supplied to vararg method. |
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
765 |
*/ |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
766 |
void checkVararg(DiagnosticPosition pos, List<Type> argtypes, Symbol msym) { |
5489
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
767 |
Type argtype = argtypes.last(); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
768 |
if (!types.isReifiable(argtype) && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
769 |
(!allowSimplifiedVarargs || |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
770 |
msym.attribute(syms.trustMeType.tsym) == null || |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
771 |
!isTrustMeAllowedOnMethod(msym))) { |
5489
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
772 |
warnUnchecked(pos, |
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
773 |
"unchecked.generic.array.creation", |
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
774 |
argtype); |
5846
6df0e6bcb388
6945418: Project Coin: Simplified Varargs Method Invocation
mcimadamore
parents:
5842
diff
changeset
|
775 |
} |
5489
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
776 |
} |
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
5321
diff
changeset
|
777 |
|
10 | 778 |
/** Check that given modifiers are legal for given symbol and |
779 |
* return modifiers together with any implicit modififiers for that symbol. |
|
780 |
* Warning: we can't use flags() here since this method |
|
781 |
* is called during class enter, when flags() would cause a premature |
|
782 |
* completion. |
|
783 |
* @param pos Position to be used for error reporting. |
|
784 |
* @param flags The set of modifiers given in a definition. |
|
785 |
* @param sym The defined symbol. |
|
786 |
*/ |
|
787 |
long checkFlags(DiagnosticPosition pos, long flags, Symbol sym, JCTree tree) { |
|
788 |
long mask; |
|
789 |
long implicit = 0; |
|
790 |
switch (sym.kind) { |
|
791 |
case VAR: |
|
792 |
if (sym.owner.kind != TYP) |
|
793 |
mask = LocalVarFlags; |
|
794 |
else if ((sym.owner.flags_field & INTERFACE) != 0) |
|
795 |
mask = implicit = InterfaceVarFlags; |
|
796 |
else |
|
797 |
mask = VarFlags; |
|
798 |
break; |
|
799 |
case MTH: |
|
800 |
if (sym.name == names.init) { |
|
801 |
if ((sym.owner.flags_field & ENUM) != 0) { |
|
802 |
// enum constructors cannot be declared public or |
|
803 |
// protected and must be implicitly or explicitly |
|
804 |
// private |
|
805 |
implicit = PRIVATE; |
|
806 |
mask = PRIVATE; |
|
807 |
} else |
|
808 |
mask = ConstructorFlags; |
|
809 |
} else if ((sym.owner.flags_field & INTERFACE) != 0) |
|
810 |
mask = implicit = InterfaceMethodFlags; |
|
811 |
else { |
|
812 |
mask = MethodFlags; |
|
813 |
} |
|
814 |
// Imply STRICTFP if owner has STRICTFP set. |
|
815 |
if (((flags|implicit) & Flags.ABSTRACT) == 0) |
|
816 |
implicit |= sym.owner.flags_field & STRICTFP; |
|
817 |
break; |
|
818 |
case TYP: |
|
819 |
if (sym.isLocal()) { |
|
820 |
mask = LocalClassFlags; |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
821 |
if (sym.name.isEmpty()) { // Anonymous class |
10 | 822 |
// Anonymous classes in static methods are themselves static; |
823 |
// that's why we admit STATIC here. |
|
824 |
mask |= STATIC; |
|
825 |
// JLS: Anonymous classes are final. |
|
826 |
implicit |= FINAL; |
|
827 |
} |
|
828 |
if ((sym.owner.flags_field & STATIC) == 0 && |
|
829 |
(flags & ENUM) != 0) |
|
830 |
log.error(pos, "enums.must.be.static"); |
|
831 |
} else if (sym.owner.kind == TYP) { |
|
832 |
mask = MemberClassFlags; |
|
833 |
if (sym.owner.owner.kind == PCK || |
|
834 |
(sym.owner.flags_field & STATIC) != 0) |
|
835 |
mask |= STATIC; |
|
836 |
else if ((flags & ENUM) != 0) |
|
837 |
log.error(pos, "enums.must.be.static"); |
|
838 |
// Nested interfaces and enums are always STATIC (Spec ???) |
|
839 |
if ((flags & (INTERFACE | ENUM)) != 0 ) implicit = STATIC; |
|
840 |
} else { |
|
841 |
mask = ClassFlags; |
|
842 |
} |
|
843 |
// Interfaces are always ABSTRACT |
|
844 |
if ((flags & INTERFACE) != 0) implicit |= ABSTRACT; |
|
845 |
||
846 |
if ((flags & ENUM) != 0) { |
|
847 |
// enums can't be declared abstract or final |
|
848 |
mask &= ~(ABSTRACT | FINAL); |
|
849 |
implicit |= implicitEnumFinalFlag(tree); |
|
850 |
} |
|
851 |
// Imply STRICTFP if owner has STRICTFP set. |
|
852 |
implicit |= sym.owner.flags_field & STRICTFP; |
|
853 |
break; |
|
854 |
default: |
|
855 |
throw new AssertionError(); |
|
856 |
} |
|
857 |
long illegal = flags & StandardFlags & ~mask; |
|
858 |
if (illegal != 0) { |
|
859 |
if ((illegal & INTERFACE) != 0) { |
|
860 |
log.error(pos, "intf.not.allowed.here"); |
|
861 |
mask |= INTERFACE; |
|
862 |
} |
|
863 |
else { |
|
864 |
log.error(pos, |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
938
diff
changeset
|
865 |
"mod.not.allowed.here", asFlagSet(illegal)); |
10 | 866 |
} |
867 |
} |
|
868 |
else if ((sym.kind == TYP || |
|
869 |
// ISSUE: Disallowing abstract&private is no longer appropriate |
|
870 |
// in the presence of inner classes. Should it be deleted here? |
|
871 |
checkDisjoint(pos, flags, |
|
872 |
ABSTRACT, |
|
873 |
PRIVATE | STATIC)) |
|
874 |
&& |
|
875 |
checkDisjoint(pos, flags, |
|
876 |
ABSTRACT | INTERFACE, |
|
877 |
FINAL | NATIVE | SYNCHRONIZED) |
|
878 |
&& |
|
879 |
checkDisjoint(pos, flags, |
|
880 |
PUBLIC, |
|
881 |
PRIVATE | PROTECTED) |
|
882 |
&& |
|
883 |
checkDisjoint(pos, flags, |
|
884 |
PRIVATE, |
|
885 |
PUBLIC | PROTECTED) |
|
886 |
&& |
|
887 |
checkDisjoint(pos, flags, |
|
888 |
FINAL, |
|
889 |
VOLATILE) |
|
890 |
&& |
|
891 |
(sym.kind == TYP || |
|
892 |
checkDisjoint(pos, flags, |
|
893 |
ABSTRACT | NATIVE, |
|
894 |
STRICTFP))) { |
|
895 |
// skip |
|
896 |
} |
|
897 |
return flags & (mask | ~StandardFlags) | implicit; |
|
898 |
} |
|
899 |
||
900 |
||
901 |
/** Determine if this enum should be implicitly final. |
|
902 |
* |
|
903 |
* If the enum has no specialized enum contants, it is final. |
|
904 |
* |
|
905 |
* If the enum does have specialized enum contants, it is |
|
906 |
* <i>not</i> final. |
|
907 |
*/ |
|
908 |
private long implicitEnumFinalFlag(JCTree tree) { |
|
909 |
if (tree.getTag() != JCTree.CLASSDEF) return 0; |
|
910 |
class SpecialTreeVisitor extends JCTree.Visitor { |
|
911 |
boolean specialized; |
|
912 |
SpecialTreeVisitor() { |
|
913 |
this.specialized = false; |
|
914 |
}; |
|
915 |
||
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
916 |
@Override |
10 | 917 |
public void visitTree(JCTree tree) { /* no-op */ } |
918 |
||
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
919 |
@Override |
10 | 920 |
public void visitVarDef(JCVariableDecl tree) { |
921 |
if ((tree.mods.flags & ENUM) != 0) { |
|
922 |
if (tree.init instanceof JCNewClass && |
|
923 |
((JCNewClass) tree.init).def != null) { |
|
924 |
specialized = true; |
|
925 |
} |
|
926 |
} |
|
927 |
} |
|
928 |
} |
|
929 |
||
930 |
SpecialTreeVisitor sts = new SpecialTreeVisitor(); |
|
931 |
JCClassDecl cdef = (JCClassDecl) tree; |
|
932 |
for (JCTree defs: cdef.defs) { |
|
933 |
defs.accept(sts); |
|
934 |
if (sts.specialized) return 0; |
|
935 |
} |
|
936 |
return FINAL; |
|
937 |
} |
|
938 |
||
939 |
/* ************************************************************************* |
|
940 |
* Type Validation |
|
941 |
**************************************************************************/ |
|
942 |
||
943 |
/** Validate a type expression. That is, |
|
944 |
* check that all type arguments of a parametric type are within |
|
945 |
* their bounds. This must be done in a second phase after type attributon |
|
946 |
* since a class might have a subclass as type parameter bound. E.g: |
|
947 |
* |
|
948 |
* class B<A extends C> { ... } |
|
949 |
* class C extends B<C> { ... } |
|
950 |
* |
|
951 |
* and we can't make sure that the bound is already attributed because |
|
952 |
* of possible cycles. |
|
6351 | 953 |
* |
954 |
* Visitor method: Validate a type expression, if it is not null, catching |
|
10 | 955 |
* and reporting any completion failures. |
956 |
*/ |
|
1358 | 957 |
void validate(JCTree tree, Env<AttrContext> env) { |
6351 | 958 |
validate(tree, env, true); |
10 | 959 |
} |
6351 | 960 |
void validate(JCTree tree, Env<AttrContext> env, boolean checkRaw) { |
961 |
new Validator(env).validateTree(tree, checkRaw, true); |
|
1358 | 962 |
} |
10 | 963 |
|
964 |
/** Visitor method: Validate a list of type expressions. |
|
965 |
*/ |
|
1358 | 966 |
void validate(List<? extends JCTree> trees, Env<AttrContext> env) { |
10 | 967 |
for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) |
1358 | 968 |
validate(l.head, env); |
10 | 969 |
} |
970 |
||
971 |
/** A visitor class for type validation. |
|
972 |
*/ |
|
973 |
class Validator extends JCTree.Visitor { |
|
974 |
||
6351 | 975 |
boolean isOuter; |
976 |
Env<AttrContext> env; |
|
977 |
||
978 |
Validator(Env<AttrContext> env) { |
|
979 |
this.env = env; |
|
980 |
} |
|
981 |
||
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
982 |
@Override |
10 | 983 |
public void visitTypeArray(JCArrayTypeTree tree) { |
6351 | 984 |
tree.elemtype.accept(this); |
10 | 985 |
} |
986 |
||
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
987 |
@Override |
10 | 988 |
public void visitTypeApply(JCTypeApply tree) { |
989 |
if (tree.type.tag == CLASS) { |
|
1531
37df4e42719a
6557954: Inner class type parameters doesn't get substituted when checking type well-formedness
mcimadamore
parents:
1527
diff
changeset
|
990 |
List<Type> formals = tree.type.tsym.type.allparams(); |
37df4e42719a
6557954: Inner class type parameters doesn't get substituted when checking type well-formedness
mcimadamore
parents:
1527
diff
changeset
|
991 |
List<Type> actuals = tree.type.allparams(); |
10 | 992 |
List<JCExpression> args = tree.arguments; |
1531
37df4e42719a
6557954: Inner class type parameters doesn't get substituted when checking type well-formedness
mcimadamore
parents:
1527
diff
changeset
|
993 |
List<Type> forms = tree.type.tsym.type.getTypeArguments(); |
5648
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5489
diff
changeset
|
994 |
ListBuffer<Type> tvars_buf = new ListBuffer<Type>(); |
10 | 995 |
|
6351 | 996 |
boolean is_java_lang_Class = tree.type.tsym.flatName() == names.java_lang_Class; |
997 |
||
10 | 998 |
// For matching pairs of actual argument types `a' and |
999 |
// formal type parameters with declared bound `b' ... |
|
1000 |
while (args.nonEmpty() && forms.nonEmpty()) { |
|
6351 | 1001 |
validateTree(args.head, |
1002 |
!(isOuter && is_java_lang_Class), |
|
1003 |
false); |
|
10 | 1004 |
|
1005 |
// exact type arguments needs to know their |
|
1006 |
// bounds (for upper and lower bound |
|
1007 |
// calculations). So we create new TypeVars with |
|
1008 |
// bounds substed with actuals. |
|
1009 |
tvars_buf.append(types.substBound(((TypeVar)forms.head), |
|
1010 |
formals, |
|
937
457a11ae2e84
6651719: Compiler crashes possibly during forward reference of TypeParameter
mcimadamore
parents:
815
diff
changeset
|
1011 |
actuals)); |
10 | 1012 |
|
1013 |
args = args.tail; |
|
1014 |
forms = forms.tail; |
|
1015 |
} |
|
1016 |
||
1017 |
args = tree.arguments; |
|
1527 | 1018 |
List<Type> tvars_cap = types.substBounds(formals, |
1019 |
formals, |
|
1531
37df4e42719a
6557954: Inner class type parameters doesn't get substituted when checking type well-formedness
mcimadamore
parents:
1527
diff
changeset
|
1020 |
types.capture(tree.type).allparams()); |
1527 | 1021 |
while (args.nonEmpty() && tvars_cap.nonEmpty()) { |
1022 |
// Let the actual arguments know their bound |
|
1023 |
args.head.type.withTypeVar((TypeVar)tvars_cap.head); |
|
1024 |
args = args.tail; |
|
1025 |
tvars_cap = tvars_cap.tail; |
|
1026 |
} |
|
1027 |
||
1028 |
args = tree.arguments; |
|
5648
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5489
diff
changeset
|
1029 |
List<Type> tvars = tvars_buf.toList(); |
1527 | 1030 |
|
10 | 1031 |
while (args.nonEmpty() && tvars.nonEmpty()) { |
5648
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5489
diff
changeset
|
1032 |
Type actual = types.subst(args.head.type, |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5489
diff
changeset
|
1033 |
tree.type.tsym.type.getTypeArguments(), |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5489
diff
changeset
|
1034 |
tvars_buf.toList()); |
1527 | 1035 |
checkExtends(args.head.pos(), |
5648
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5489
diff
changeset
|
1036 |
actual, |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5489
diff
changeset
|
1037 |
(TypeVar)tvars.head); |
10 | 1038 |
args = args.tail; |
1039 |
tvars = tvars.tail; |
|
1040 |
} |
|
1041 |
||
1527 | 1042 |
checkCapture(tree); |
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5002
diff
changeset
|
1043 |
|
10 | 1044 |
// Check that this type is either fully parameterized, or |
1045 |
// not parameterized at all. |
|
1046 |
if (tree.type.getEnclosingType().isRaw()) |
|
1047 |
log.error(tree.pos(), "improperly.formed.type.inner.raw.param"); |
|
1048 |
if (tree.clazz.getTag() == JCTree.SELECT) |
|
1049 |
visitSelectInternal((JCFieldAccess)tree.clazz); |
|
1050 |
} |
|
1051 |
} |
|
1052 |
||
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
1053 |
@Override |
10 | 1054 |
public void visitTypeParameter(JCTypeParameter tree) { |
6351 | 1055 |
validateTrees(tree.bounds, true, isOuter); |
10 | 1056 |
checkClassBounds(tree.pos(), tree.type); |
1057 |
} |
|
1058 |
||
1059 |
@Override |
|
1060 |
public void visitWildcard(JCWildcard tree) { |
|
1061 |
if (tree.inner != null) |
|
6351 | 1062 |
validateTree(tree.inner, true, isOuter); |
10 | 1063 |
} |
1064 |
||
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
1065 |
@Override |
10 | 1066 |
public void visitSelect(JCFieldAccess tree) { |
1067 |
if (tree.type.tag == CLASS) { |
|
1068 |
visitSelectInternal(tree); |
|
1069 |
||
1070 |
// Check that this type is either fully parameterized, or |
|
1071 |
// not parameterized at all. |
|
1072 |
if (tree.selected.type.isParameterized() && tree.type.tsym.type.getTypeArguments().nonEmpty()) |
|
1073 |
log.error(tree.pos(), "improperly.formed.type.param.missing"); |
|
1074 |
} |
|
1075 |
} |
|
1076 |
public void visitSelectInternal(JCFieldAccess tree) { |
|
1358 | 1077 |
if (tree.type.tsym.isStatic() && |
10 | 1078 |
tree.selected.type.isParameterized()) { |
1079 |
// The enclosing type is not a class, so we are |
|
1080 |
// looking at a static member type. However, the |
|
1081 |
// qualifying expression is parameterized. |
|
1082 |
log.error(tree.pos(), "cant.select.static.class.from.param.type"); |
|
1083 |
} else { |
|
1084 |
// otherwise validate the rest of the expression |
|
1358 | 1085 |
tree.selected.accept(this); |
10 | 1086 |
} |
1087 |
} |
|
1088 |
||
1089 |
/** Default visitor method: do nothing. |
|
1090 |
*/ |
|
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
1091 |
@Override |
10 | 1092 |
public void visitTree(JCTree tree) { |
1093 |
} |
|
1358 | 1094 |
|
6351 | 1095 |
public void validateTree(JCTree tree, boolean checkRaw, boolean isOuter) { |
1096 |
try { |
|
1097 |
if (tree != null) { |
|
1098 |
this.isOuter = isOuter; |
|
1099 |
tree.accept(this); |
|
1100 |
if (checkRaw) |
|
1101 |
checkRaw(tree, env); |
|
1102 |
} |
|
1103 |
} catch (CompletionFailure ex) { |
|
1104 |
completionError(tree.pos(), ex); |
|
1105 |
} |
|
1106 |
} |
|
1107 |
||
1108 |
public void validateTrees(List<? extends JCTree> trees, boolean checkRaw, boolean isOuter) { |
|
1109 |
for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) |
|
1110 |
validateTree(l.head, checkRaw, isOuter); |
|
1111 |
} |
|
1112 |
||
1113 |
void checkRaw(JCTree tree, Env<AttrContext> env) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
1114 |
if (lint.isEnabled(LintCategory.RAW) && |
6351 | 1115 |
tree.type.tag == CLASS && |
1116 |
!TreeInfo.isDiamond(tree) && |
|
1117 |
!env.enclClass.name.isEmpty() && //anonymous or intersection |
|
1118 |
tree.type.isRaw()) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
1119 |
log.warning(LintCategory.RAW, |
6351 | 1120 |
tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type); |
1121 |
} |
|
1122 |
} |
|
10 | 1123 |
} |
1124 |
||
1125 |
/* ************************************************************************* |
|
1126 |
* Exception checking |
|
1127 |
**************************************************************************/ |
|
1128 |
||
1129 |
/* The following methods treat classes as sets that contain |
|
1130 |
* the class itself and all their subclasses |
|
1131 |
*/ |
|
1132 |
||
1133 |
/** Is given type a subtype of some of the types in given list? |
|
1134 |
*/ |
|
1135 |
boolean subset(Type t, List<Type> ts) { |
|
1136 |
for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
|
1137 |
if (types.isSubtype(t, l.head)) return true; |
|
1138 |
return false; |
|
1139 |
} |
|
1140 |
||
1141 |
/** Is given type a subtype or supertype of |
|
1142 |
* some of the types in given list? |
|
1143 |
*/ |
|
1144 |
boolean intersects(Type t, List<Type> ts) { |
|
1145 |
for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
|
1146 |
if (types.isSubtype(t, l.head) || types.isSubtype(l.head, t)) return true; |
|
1147 |
return false; |
|
1148 |
} |
|
1149 |
||
1150 |
/** Add type set to given type list, unless it is a subclass of some class |
|
1151 |
* in the list. |
|
1152 |
*/ |
|
1153 |
List<Type> incl(Type t, List<Type> ts) { |
|
1154 |
return subset(t, ts) ? ts : excl(t, ts).prepend(t); |
|
1155 |
} |
|
1156 |
||
1157 |
/** Remove type set from type set list. |
|
1158 |
*/ |
|
1159 |
List<Type> excl(Type t, List<Type> ts) { |
|
1160 |
if (ts.isEmpty()) { |
|
1161 |
return ts; |
|
1162 |
} else { |
|
1163 |
List<Type> ts1 = excl(t, ts.tail); |
|
1164 |
if (types.isSubtype(ts.head, t)) return ts1; |
|
1165 |
else if (ts1 == ts.tail) return ts; |
|
1166 |
else return ts1.prepend(ts.head); |
|
1167 |
} |
|
1168 |
} |
|
1169 |
||
1170 |
/** Form the union of two type set lists. |
|
1171 |
*/ |
|
1172 |
List<Type> union(List<Type> ts1, List<Type> ts2) { |
|
1173 |
List<Type> ts = ts1; |
|
1174 |
for (List<Type> l = ts2; l.nonEmpty(); l = l.tail) |
|
1175 |
ts = incl(l.head, ts); |
|
1176 |
return ts; |
|
1177 |
} |
|
1178 |
||
1179 |
/** Form the difference of two type lists. |
|
1180 |
*/ |
|
1181 |
List<Type> diff(List<Type> ts1, List<Type> ts2) { |
|
1182 |
List<Type> ts = ts1; |
|
1183 |
for (List<Type> l = ts2; l.nonEmpty(); l = l.tail) |
|
1184 |
ts = excl(l.head, ts); |
|
1185 |
return ts; |
|
1186 |
} |
|
1187 |
||
1188 |
/** Form the intersection of two type lists. |
|
1189 |
*/ |
|
1190 |
public List<Type> intersect(List<Type> ts1, List<Type> ts2) { |
|
1191 |
List<Type> ts = List.nil(); |
|
1192 |
for (List<Type> l = ts1; l.nonEmpty(); l = l.tail) |
|
1193 |
if (subset(l.head, ts2)) ts = incl(l.head, ts); |
|
1194 |
for (List<Type> l = ts2; l.nonEmpty(); l = l.tail) |
|
1195 |
if (subset(l.head, ts1)) ts = incl(l.head, ts); |
|
1196 |
return ts; |
|
1197 |
} |
|
1198 |
||
1199 |
/** Is exc an exception symbol that need not be declared? |
|
1200 |
*/ |
|
1201 |
boolean isUnchecked(ClassSymbol exc) { |
|
1202 |
return |
|
1203 |
exc.kind == ERR || |
|
1204 |
exc.isSubClass(syms.errorType.tsym, types) || |
|
1205 |
exc.isSubClass(syms.runtimeExceptionType.tsym, types); |
|
1206 |
} |
|
1207 |
||
1208 |
/** Is exc an exception type that need not be declared? |
|
1209 |
*/ |
|
1210 |
boolean isUnchecked(Type exc) { |
|
1211 |
return |
|
1212 |
(exc.tag == TYPEVAR) ? isUnchecked(types.supertype(exc)) : |
|
1213 |
(exc.tag == CLASS) ? isUnchecked((ClassSymbol)exc.tsym) : |
|
1214 |
exc.tag == BOT; |
|
1215 |
} |
|
1216 |
||
1217 |
/** Same, but handling completion failures. |
|
1218 |
*/ |
|
1219 |
boolean isUnchecked(DiagnosticPosition pos, Type exc) { |
|
1220 |
try { |
|
1221 |
return isUnchecked(exc); |
|
1222 |
} catch (CompletionFailure ex) { |
|
1223 |
completionError(pos, ex); |
|
1224 |
return true; |
|
1225 |
} |
|
1226 |
} |
|
1227 |
||
1228 |
/** Is exc handled by given exception list? |
|
1229 |
*/ |
|
1230 |
boolean isHandled(Type exc, List<Type> handled) { |
|
1231 |
return isUnchecked(exc) || subset(exc, handled); |
|
1232 |
} |
|
1233 |
||
1234 |
/** Return all exceptions in thrown list that are not in handled list. |
|
1235 |
* @param thrown The list of thrown exceptions. |
|
1236 |
* @param handled The list of handled exceptions. |
|
1237 |
*/ |
|
3560 | 1238 |
List<Type> unhandled(List<Type> thrown, List<Type> handled) { |
10 | 1239 |
List<Type> unhandled = List.nil(); |
1240 |
for (List<Type> l = thrown; l.nonEmpty(); l = l.tail) |
|
1241 |
if (!isHandled(l.head, handled)) unhandled = unhandled.prepend(l.head); |
|
1242 |
return unhandled; |
|
1243 |
} |
|
1244 |
||
1245 |
/* ************************************************************************* |
|
1246 |
* Overriding/Implementation checking |
|
1247 |
**************************************************************************/ |
|
1248 |
||
1249 |
/** The level of access protection given by a flag set, |
|
1250 |
* where PRIVATE is highest and PUBLIC is lowest. |
|
1251 |
*/ |
|
1252 |
static int protection(long flags) { |
|
1253 |
switch ((short)(flags & AccessFlags)) { |
|
1254 |
case PRIVATE: return 3; |
|
1255 |
case PROTECTED: return 1; |
|
1256 |
default: |
|
1257 |
case PUBLIC: return 0; |
|
1258 |
case 0: return 2; |
|
1259 |
} |
|
1260 |
} |
|
1261 |
||
1262 |
/** A customized "cannot override" error message. |
|
1263 |
* @param m The overriding method. |
|
1264 |
* @param other The overridden method. |
|
1265 |
* @return An internationalized string. |
|
1266 |
*/ |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
1267 |
Object cannotOverride(MethodSymbol m, MethodSymbol other) { |
10 | 1268 |
String key; |
1269 |
if ((other.owner.flags() & INTERFACE) == 0) |
|
1270 |
key = "cant.override"; |
|
1271 |
else if ((m.owner.flags() & INTERFACE) == 0) |
|
1272 |
key = "cant.implement"; |
|
1273 |
else |
|
1274 |
key = "clashes.with"; |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
1275 |
return diags.fragment(key, m, m.location(), other, other.location()); |
10 | 1276 |
} |
1277 |
||
1278 |
/** A customized "override" warning message. |
|
1279 |
* @param m The overriding method. |
|
1280 |
* @param other The overridden method. |
|
1281 |
* @return An internationalized string. |
|
1282 |
*/ |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
1283 |
Object uncheckedOverrides(MethodSymbol m, MethodSymbol other) { |
10 | 1284 |
String key; |
1285 |
if ((other.owner.flags() & INTERFACE) == 0) |
|
1286 |
key = "unchecked.override"; |
|
1287 |
else if ((m.owner.flags() & INTERFACE) == 0) |
|
1288 |
key = "unchecked.implement"; |
|
1289 |
else |
|
1290 |
key = "unchecked.clash.with"; |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
1291 |
return diags.fragment(key, m, m.location(), other, other.location()); |
10 | 1292 |
} |
1293 |
||
1294 |
/** A customized "override" warning message. |
|
1295 |
* @param m The overriding method. |
|
1296 |
* @param other The overridden method. |
|
1297 |
* @return An internationalized string. |
|
1298 |
*/ |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
1299 |
Object varargsOverrides(MethodSymbol m, MethodSymbol other) { |
10 | 1300 |
String key; |
1301 |
if ((other.owner.flags() & INTERFACE) == 0) |
|
1302 |
key = "varargs.override"; |
|
1303 |
else if ((m.owner.flags() & INTERFACE) == 0) |
|
1304 |
key = "varargs.implement"; |
|
1305 |
else |
|
1306 |
key = "varargs.clash.with"; |
|
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
939
diff
changeset
|
1307 |
return diags.fragment(key, m, m.location(), other, other.location()); |
10 | 1308 |
} |
1309 |
||
1310 |
/** Check that this method conforms with overridden method 'other'. |
|
1311 |
* where `origin' is the class where checking started. |
|
1312 |
* Complications: |
|
1313 |
* (1) Do not check overriding of synthetic methods |
|
1314 |
* (reason: they might be final). |
|
1315 |
* todo: check whether this is still necessary. |
|
1316 |
* (2) Admit the case where an interface proxy throws fewer exceptions |
|
1317 |
* than the method it implements. Augment the proxy methods with the |
|
1318 |
* undeclared exceptions in this case. |
|
1319 |
* (3) When generics are enabled, admit the case where an interface proxy |
|
1320 |
* has a result type |
|
1321 |
* extended by the result type of the method it implements. |
|
1322 |
* Change the proxies result type to the smaller type in this case. |
|
1323 |
* |
|
1324 |
* @param tree The tree from which positions |
|
1325 |
* are extracted for errors. |
|
1326 |
* @param m The overriding method. |
|
1327 |
* @param other The overridden method. |
|
1328 |
* @param origin The class of which the overriding method |
|
1329 |
* is a member. |
|
1330 |
*/ |
|
1331 |
void checkOverride(JCTree tree, |
|
1332 |
MethodSymbol m, |
|
1333 |
MethodSymbol other, |
|
1334 |
ClassSymbol origin) { |
|
1335 |
// Don't check overriding of synthetic methods or by bridge methods. |
|
1336 |
if ((m.flags() & (SYNTHETIC|BRIDGE)) != 0 || (other.flags() & SYNTHETIC) != 0) { |
|
1337 |
return; |
|
1338 |
} |
|
1339 |
||
1340 |
// Error if static method overrides instance method (JLS 8.4.6.2). |
|
1341 |
if ((m.flags() & STATIC) != 0 && |
|
1342 |
(other.flags() & STATIC) == 0) { |
|
1343 |
log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.static", |
|
1344 |
cannotOverride(m, other)); |
|
1345 |
return; |
|
1346 |
} |
|
1347 |
||
1348 |
// Error if instance method overrides static or final |
|
1349 |
// method (JLS 8.4.6.1). |
|
1350 |
if ((other.flags() & FINAL) != 0 || |
|
1351 |
(m.flags() & STATIC) == 0 && |
|
1352 |
(other.flags() & STATIC) != 0) { |
|
1353 |
log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.meth", |
|
1354 |
cannotOverride(m, other), |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
938
diff
changeset
|
1355 |
asFlagSet(other.flags() & (FINAL | STATIC))); |
10 | 1356 |
return; |
1357 |
} |
|
1358 |
||
1359 |
if ((m.owner.flags() & ANNOTATION) != 0) { |
|
1360 |
// handled in validateAnnotationMethod |
|
1361 |
return; |
|
1362 |
} |
|
1363 |
||
1364 |
// Error if overriding method has weaker access (JLS 8.4.6.3). |
|
1365 |
if ((origin.flags() & INTERFACE) == 0 && |
|
1366 |
protection(m.flags()) > protection(other.flags())) { |
|
1367 |
log.error(TreeInfo.diagnosticPositionFor(m, tree), "override.weaker.access", |
|
1368 |
cannotOverride(m, other), |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
938
diff
changeset
|
1369 |
other.flags() == 0 ? |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
938
diff
changeset
|
1370 |
Flag.PACKAGE : |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
938
diff
changeset
|
1371 |
asFlagSet(other.flags() & AccessFlags)); |
10 | 1372 |
return; |
1373 |
} |
|
1374 |
||
1375 |
Type mt = types.memberType(origin.type, m); |
|
1376 |
Type ot = types.memberType(origin.type, other); |
|
1377 |
// Error if overriding result type is different |
|
1378 |
// (or, in the case of generics mode, not a subtype) of |
|
1379 |
// overridden result type. We have to rename any type parameters |
|
1380 |
// before comparing types. |
|
1381 |
List<Type> mtvars = mt.getTypeArguments(); |
|
1382 |
List<Type> otvars = ot.getTypeArguments(); |
|
1383 |
Type mtres = mt.getReturnType(); |
|
1384 |
Type otres = types.subst(ot.getReturnType(), otvars, mtvars); |
|
1385 |
||
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
1386 |
overrideWarner.clear(); |
10 | 1387 |
boolean resultTypesOK = |
1874 | 1388 |
types.returnTypeSubstitutable(mt, ot, otres, overrideWarner); |
10 | 1389 |
if (!resultTypesOK) { |
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
1390 |
if (!allowCovariantReturns && |
10 | 1391 |
m.owner != origin && |
1392 |
m.owner.isSubClass(other.owner, types)) { |
|
1393 |
// allow limited interoperability with covariant returns |
|
1394 |
} else { |
|
3560 | 1395 |
log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1396 |
"override.incompatible.ret", |
|
1397 |
cannotOverride(m, other), |
|
10 | 1398 |
mtres, otres); |
1399 |
return; |
|
1400 |
} |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
1401 |
} else if (overrideWarner.hasNonSilentLint(LintCategory.UNCHECKED)) { |
10 | 1402 |
warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), |
3560 | 1403 |
"override.unchecked.ret", |
1404 |
uncheckedOverrides(m, other), |
|
1405 |
mtres, otres); |
|
10 | 1406 |
} |
1407 |
||
1408 |
// Error if overriding method throws an exception not reported |
|
1409 |
// by overridden method. |
|
1410 |
List<Type> otthrown = types.subst(ot.getThrownTypes(), otvars, mtvars); |
|
3560 | 1411 |
List<Type> unhandledErased = unhandled(mt.getThrownTypes(), types.erasure(otthrown)); |
1412 |
List<Type> unhandledUnerased = unhandled(mt.getThrownTypes(), otthrown); |
|
1413 |
if (unhandledErased.nonEmpty()) { |
|
10 | 1414 |
log.error(TreeInfo.diagnosticPositionFor(m, tree), |
1415 |
"override.meth.doesnt.throw", |
|
1416 |
cannotOverride(m, other), |
|
3560 | 1417 |
unhandledUnerased.head); |
1418 |
return; |
|
1419 |
} |
|
1420 |
else if (unhandledUnerased.nonEmpty()) { |
|
1421 |
warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), |
|
1422 |
"override.unchecked.thrown", |
|
1423 |
cannotOverride(m, other), |
|
1424 |
unhandledUnerased.head); |
|
10 | 1425 |
return; |
1426 |
} |
|
1427 |
||
1428 |
// Optional warning if varargs don't agree |
|
1429 |
if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
1430 |
&& lint.isEnabled(LintCategory.OVERRIDES)) { |
10 | 1431 |
log.warning(TreeInfo.diagnosticPositionFor(m, tree), |
1432 |
((m.flags() & Flags.VARARGS) != 0) |
|
1433 |
? "override.varargs.missing" |
|
1434 |
: "override.varargs.extra", |
|
1435 |
varargsOverrides(m, other)); |
|
1436 |
} |
|
1437 |
||
1438 |
// Warn if instance method overrides bridge method (compiler spec ??) |
|
1439 |
if ((other.flags() & BRIDGE) != 0) { |
|
1440 |
log.warning(TreeInfo.diagnosticPositionFor(m, tree), "override.bridge", |
|
1441 |
uncheckedOverrides(m, other)); |
|
1442 |
} |
|
1443 |
||
1444 |
// Warn if a deprecated method overridden by a non-deprecated one. |
|
1445 |
if ((other.flags() & DEPRECATED) != 0 |
|
1446 |
&& (m.flags() & DEPRECATED) == 0 |
|
1447 |
&& m.outermostClass() != other.outermostClass() |
|
1448 |
&& !isDeprecatedOverrideIgnorable(other, origin)) { |
|
1449 |
warnDeprecated(TreeInfo.diagnosticPositionFor(m, tree), other); |
|
1450 |
} |
|
1451 |
} |
|
1452 |
// where |
|
1453 |
private boolean isDeprecatedOverrideIgnorable(MethodSymbol m, ClassSymbol origin) { |
|
1454 |
// If the method, m, is defined in an interface, then ignore the issue if the method |
|
1455 |
// is only inherited via a supertype and also implemented in the supertype, |
|
1456 |
// because in that case, we will rediscover the issue when examining the method |
|
1457 |
// in the supertype. |
|
1458 |
// If the method, m, is not defined in an interface, then the only time we need to |
|
1459 |
// address the issue is when the method is the supertype implemementation: any other |
|
1460 |
// case, we will have dealt with when examining the supertype classes |
|
1461 |
ClassSymbol mc = m.enclClass(); |
|
1462 |
Type st = types.supertype(origin.type); |
|
1463 |
if (st.tag != CLASS) |
|
1464 |
return true; |
|
1465 |
MethodSymbol stimpl = m.implementation((ClassSymbol)st.tsym, types, false); |
|
1466 |
||
1467 |
if (mc != null && ((mc.flags() & INTERFACE) != 0)) { |
|
1468 |
List<Type> intfs = types.interfaces(origin.type); |
|
1469 |
return (intfs.contains(mc.type) ? false : (stimpl != null)); |
|
1470 |
} |
|
1471 |
else |
|
1472 |
return (stimpl != m); |
|
1473 |
} |
|
1474 |
||
1475 |
||
1476 |
// used to check if there were any unchecked conversions |
|
1477 |
Warner overrideWarner = new Warner(); |
|
1478 |
||
1479 |
/** Check that a class does not inherit two concrete methods |
|
1480 |
* with the same signature. |
|
1481 |
* @param pos Position to be used for error reporting. |
|
1482 |
* @param site The class type to be checked. |
|
1483 |
*/ |
|
1484 |
public void checkCompatibleConcretes(DiagnosticPosition pos, Type site) { |
|
1485 |
Type sup = types.supertype(site); |
|
1486 |
if (sup.tag != CLASS) return; |
|
1487 |
||
1488 |
for (Type t1 = sup; |
|
1489 |
t1.tsym.type.isParameterized(); |
|
1490 |
t1 = types.supertype(t1)) { |
|
1491 |
for (Scope.Entry e1 = t1.tsym.members().elems; |
|
1492 |
e1 != null; |
|
1493 |
e1 = e1.sibling) { |
|
1494 |
Symbol s1 = e1.sym; |
|
1495 |
if (s1.kind != MTH || |
|
1496 |
(s1.flags() & (STATIC|SYNTHETIC|BRIDGE)) != 0 || |
|
1497 |
!s1.isInheritedIn(site.tsym, types) || |
|
1498 |
((MethodSymbol)s1).implementation(site.tsym, |
|
1499 |
types, |
|
1500 |
true) != s1) |
|
1501 |
continue; |
|
1502 |
Type st1 = types.memberType(t1, s1); |
|
1503 |
int s1ArgsLength = st1.getParameterTypes().length(); |
|
1504 |
if (st1 == s1.type) continue; |
|
1505 |
||
1506 |
for (Type t2 = sup; |
|
1507 |
t2.tag == CLASS; |
|
1508 |
t2 = types.supertype(t2)) { |
|
508
118e500e2e50
5009937: hiding versus generics versus binary compatibility
mcimadamore
parents:
169
diff
changeset
|
1509 |
for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); |
10 | 1510 |
e2.scope != null; |
1511 |
e2 = e2.next()) { |
|
1512 |
Symbol s2 = e2.sym; |
|
1513 |
if (s2 == s1 || |
|
1514 |
s2.kind != MTH || |
|
1515 |
(s2.flags() & (STATIC|SYNTHETIC|BRIDGE)) != 0 || |
|
1516 |
s2.type.getParameterTypes().length() != s1ArgsLength || |
|
1517 |
!s2.isInheritedIn(site.tsym, types) || |
|
1518 |
((MethodSymbol)s2).implementation(site.tsym, |
|
1519 |
types, |
|
1520 |
true) != s2) |
|
1521 |
continue; |
|
1522 |
Type st2 = types.memberType(t2, s2); |
|
1523 |
if (types.overrideEquivalent(st1, st2)) |
|
1524 |
log.error(pos, "concrete.inheritance.conflict", |
|
1525 |
s1, t1, s2, t2, sup); |
|
1526 |
} |
|
1527 |
} |
|
1528 |
} |
|
1529 |
} |
|
1530 |
} |
|
1531 |
||
1532 |
/** Check that classes (or interfaces) do not each define an abstract |
|
1533 |
* method with same name and arguments but incompatible return types. |
|
1534 |
* @param pos Position to be used for error reporting. |
|
1535 |
* @param t1 The first argument type. |
|
1536 |
* @param t2 The second argument type. |
|
1537 |
*/ |
|
1538 |
public boolean checkCompatibleAbstracts(DiagnosticPosition pos, |
|
1539 |
Type t1, |
|
1540 |
Type t2) { |
|
1541 |
return checkCompatibleAbstracts(pos, t1, t2, |
|
1542 |
types.makeCompoundType(t1, t2)); |
|
1543 |
} |
|
1544 |
||
1545 |
public boolean checkCompatibleAbstracts(DiagnosticPosition pos, |
|
1546 |
Type t1, |
|
1547 |
Type t2, |
|
1548 |
Type site) { |
|
7214
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1549 |
return firstIncompatibility(pos, t1, t2, site) == null; |
10 | 1550 |
} |
1551 |
||
1552 |
/** Return the first method which is defined with same args |
|
1553 |
* but different return types in two given interfaces, or null if none |
|
1554 |
* exists. |
|
1555 |
* @param t1 The first type. |
|
1556 |
* @param t2 The second type. |
|
1557 |
* @param site The most derived type. |
|
1558 |
* @returns symbol from t2 that conflicts with one in t1. |
|
1559 |
*/ |
|
7214
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1560 |
private Symbol firstIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) { |
10 | 1561 |
Map<TypeSymbol,Type> interfaces1 = new HashMap<TypeSymbol,Type>(); |
1562 |
closure(t1, interfaces1); |
|
1563 |
Map<TypeSymbol,Type> interfaces2; |
|
1564 |
if (t1 == t2) |
|
1565 |
interfaces2 = interfaces1; |
|
1566 |
else |
|
1567 |
closure(t2, interfaces1, interfaces2 = new HashMap<TypeSymbol,Type>()); |
|
1568 |
||
1569 |
for (Type t3 : interfaces1.values()) { |
|
1570 |
for (Type t4 : interfaces2.values()) { |
|
7214
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1571 |
Symbol s = firstDirectIncompatibility(pos, t3, t4, site); |
10 | 1572 |
if (s != null) return s; |
1573 |
} |
|
1574 |
} |
|
1575 |
return null; |
|
1576 |
} |
|
1577 |
||
1578 |
/** Compute all the supertypes of t, indexed by type symbol. */ |
|
1579 |
private void closure(Type t, Map<TypeSymbol,Type> typeMap) { |
|
1580 |
if (t.tag != CLASS) return; |
|
1581 |
if (typeMap.put(t.tsym, t) == null) { |
|
1582 |
closure(types.supertype(t), typeMap); |
|
1583 |
for (Type i : types.interfaces(t)) |
|
1584 |
closure(i, typeMap); |
|
1585 |
} |
|
1586 |
} |
|
1587 |
||
1588 |
/** Compute all the supertypes of t, indexed by type symbol (except thise in typesSkip). */ |
|
1589 |
private void closure(Type t, Map<TypeSymbol,Type> typesSkip, Map<TypeSymbol,Type> typeMap) { |
|
1590 |
if (t.tag != CLASS) return; |
|
1591 |
if (typesSkip.get(t.tsym) != null) return; |
|
1592 |
if (typeMap.put(t.tsym, t) == null) { |
|
1593 |
closure(types.supertype(t), typesSkip, typeMap); |
|
1594 |
for (Type i : types.interfaces(t)) |
|
1595 |
closure(i, typesSkip, typeMap); |
|
1596 |
} |
|
1597 |
} |
|
1598 |
||
1599 |
/** Return the first method in t2 that conflicts with a method from t1. */ |
|
7214
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1600 |
private Symbol firstDirectIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) { |
10 | 1601 |
for (Scope.Entry e1 = t1.tsym.members().elems; e1 != null; e1 = e1.sibling) { |
1602 |
Symbol s1 = e1.sym; |
|
1603 |
Type st1 = null; |
|
1604 |
if (s1.kind != MTH || !s1.isInheritedIn(site.tsym, types)) continue; |
|
1605 |
Symbol impl = ((MethodSymbol)s1).implementation(site.tsym, types, false); |
|
1606 |
if (impl != null && (impl.flags() & ABSTRACT) == 0) continue; |
|
1607 |
for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); e2.scope != null; e2 = e2.next()) { |
|
1608 |
Symbol s2 = e2.sym; |
|
1609 |
if (s1 == s2) continue; |
|
1610 |
if (s2.kind != MTH || !s2.isInheritedIn(site.tsym, types)) continue; |
|
1611 |
if (st1 == null) st1 = types.memberType(t1, s1); |
|
1612 |
Type st2 = types.memberType(t2, s2); |
|
1613 |
if (types.overrideEquivalent(st1, st2)) { |
|
1614 |
List<Type> tvars1 = st1.getTypeArguments(); |
|
1615 |
List<Type> tvars2 = st2.getTypeArguments(); |
|
1616 |
Type rt1 = st1.getReturnType(); |
|
1617 |
Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1); |
|
1618 |
boolean compat = |
|
1619 |
types.isSameType(rt1, rt2) || |
|
1620 |
rt1.tag >= CLASS && rt2.tag >= CLASS && |
|
1621 |
(types.covariantReturnType(rt1, rt2, Warner.noWarnings) || |
|
812
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1622 |
types.covariantReturnType(rt2, rt1, Warner.noWarnings)) || |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1623 |
checkCommonOverriderIn(s1,s2,site); |
7214
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1624 |
if (!compat) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1625 |
log.error(pos, "types.incompatible.diff.ret", |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1626 |
t1, t2, s2.name + |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1627 |
"(" + types.memberType(t2, s2).getParameterTypes() + ")"); |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1628 |
return s2; |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1629 |
} |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1630 |
} else if (!checkNameClash((ClassSymbol)site.tsym, s1, s2)) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1631 |
log.error(pos, |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1632 |
"name.clash.same.erasure.no.override", |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1633 |
s1, s1.location(), |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1634 |
s2, s2.location()); |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1635 |
return s2; |
10 | 1636 |
} |
1637 |
} |
|
1638 |
} |
|
1639 |
return null; |
|
1640 |
} |
|
812
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1641 |
//WHERE |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1642 |
boolean checkCommonOverriderIn(Symbol s1, Symbol s2, Type site) { |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1643 |
Map<TypeSymbol,Type> supertypes = new HashMap<TypeSymbol,Type>(); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1644 |
Type st1 = types.memberType(site, s1); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1645 |
Type st2 = types.memberType(site, s2); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1646 |
closure(site, supertypes); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1647 |
for (Type t : supertypes.values()) { |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1648 |
for (Scope.Entry e = t.tsym.members().lookup(s1.name); e.scope != null; e = e.next()) { |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1649 |
Symbol s3 = e.sym; |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1650 |
if (s3 == s1 || s3 == s2 || s3.kind != MTH || (s3.flags() & (BRIDGE|SYNTHETIC)) != 0) continue; |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1651 |
Type st3 = types.memberType(site,s3); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1652 |
if (types.overrideEquivalent(st3, st1) && types.overrideEquivalent(st3, st2)) { |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1653 |
if (s3.owner == site.tsym) { |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1654 |
return true; |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1655 |
} |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1656 |
List<Type> tvars1 = st1.getTypeArguments(); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1657 |
List<Type> tvars2 = st2.getTypeArguments(); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1658 |
List<Type> tvars3 = st3.getTypeArguments(); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1659 |
Type rt1 = st1.getReturnType(); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1660 |
Type rt2 = st2.getReturnType(); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1661 |
Type rt13 = types.subst(st3.getReturnType(), tvars3, tvars1); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1662 |
Type rt23 = types.subst(st3.getReturnType(), tvars3, tvars2); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1663 |
boolean compat = |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1664 |
rt13.tag >= CLASS && rt23.tag >= CLASS && |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1665 |
(types.covariantReturnType(rt13, rt1, Warner.noWarnings) && |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1666 |
types.covariantReturnType(rt23, rt2, Warner.noWarnings)); |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1667 |
if (compat) |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1668 |
return true; |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1669 |
} |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1670 |
} |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1671 |
} |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1672 |
return false; |
d60171f70ade
6294779: Problem with interface inheritance and covariant return types
mcimadamore
parents:
661
diff
changeset
|
1673 |
} |
10 | 1674 |
|
1675 |
/** Check that a given method conforms with any method it overrides. |
|
1676 |
* @param tree The tree from which positions are extracted |
|
1677 |
* for errors. |
|
1678 |
* @param m The overriding method. |
|
1679 |
*/ |
|
1680 |
void checkOverride(JCTree tree, MethodSymbol m) { |
|
1681 |
ClassSymbol origin = (ClassSymbol)m.owner; |
|
1682 |
if ((origin.flags() & ENUM) != 0 && names.finalize.equals(m.name)) |
|
1683 |
if (m.overrides(syms.enumFinalFinalize, origin, types, false)) { |
|
1684 |
log.error(tree.pos(), "enum.no.finalize"); |
|
1685 |
return; |
|
1686 |
} |
|
7214
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1687 |
for (Type t = origin.type; t.tag == CLASS; |
10 | 1688 |
t = types.supertype(t)) { |
7214
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1689 |
if (t != origin.type) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1690 |
checkOverride(tree, t, origin, m); |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1691 |
} |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1692 |
for (Type t2 : types.interfaces(t)) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1693 |
checkOverride(tree, t2, origin, m); |
10 | 1694 |
} |
1695 |
} |
|
1696 |
} |
|
1697 |
||
7214
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1698 |
void checkOverride(JCTree tree, Type site, ClassSymbol origin, MethodSymbol m) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1699 |
TypeSymbol c = site.tsym; |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1700 |
Scope.Entry e = c.members().lookup(m.name); |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1701 |
while (e.scope != null) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1702 |
if (m.overrides(e.sym, origin, types, false)) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1703 |
if ((e.sym.flags() & ABSTRACT) == 0) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1704 |
checkOverride(tree, m, (MethodSymbol)e.sym, origin); |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1705 |
} |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1706 |
} |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1707 |
e = e.next(); |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1708 |
} |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1709 |
} |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1710 |
|
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1711 |
private boolean checkNameClash(ClassSymbol origin, Symbol s1, Symbol s2) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1712 |
if (s1.kind == MTH && |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1713 |
s1.isInheritedIn(origin, types) && |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1714 |
(s1.flags() & SYNTHETIC) == 0 && |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1715 |
!s2.isConstructor()) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1716 |
Type er1 = s2.erasure(types); |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1717 |
Type er2 = s1.erasure(types); |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1718 |
if (types.isSameTypes(er1.getParameterTypes(), |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1719 |
er2.getParameterTypes())) { |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1720 |
return false; |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1721 |
} |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1722 |
} |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1723 |
return true; |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1724 |
} |
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1725 |
|
26dfa4a69593
6985719: Alike methods in interfaces (Inheritance and Overriding)
mcimadamore
parents:
6721
diff
changeset
|
1726 |
|
10 | 1727 |
/** Check that all abstract members of given class have definitions. |
1728 |
* @param pos Position to be used for error reporting. |
|
1729 |
* @param c The class. |
|
1730 |
*/ |
|
1731 |
void checkAllDefined(DiagnosticPosition pos, ClassSymbol c) { |
|
1732 |
try { |
|
1733 |
MethodSymbol undef = firstUndef(c, c); |
|
1734 |
if (undef != null) { |
|
1735 |
if ((c.flags() & ENUM) != 0 && |
|
1736 |
types.supertype(c.type).tsym == syms.enumSym && |
|
1737 |
(c.flags() & FINAL) == 0) { |
|
1738 |
// add the ABSTRACT flag to an enum |
|
1739 |
c.flags_field |= ABSTRACT; |
|
1740 |
} else { |
|
1741 |
MethodSymbol undef1 = |
|
1742 |
new MethodSymbol(undef.flags(), undef.name, |
|
1743 |
types.memberType(c.type, undef), undef.owner); |
|
1744 |
log.error(pos, "does.not.override.abstract", |
|
1745 |
c, undef1, undef1.location()); |
|
1746 |
} |
|
1747 |
} |
|
1748 |
} catch (CompletionFailure ex) { |
|
1749 |
completionError(pos, ex); |
|
1750 |
} |
|
1751 |
} |
|
1752 |
//where |
|
1753 |
/** Return first abstract member of class `c' that is not defined |
|
1754 |
* in `impl', null if there is none. |
|
1755 |
*/ |
|
1756 |
private MethodSymbol firstUndef(ClassSymbol impl, ClassSymbol c) { |
|
1757 |
MethodSymbol undef = null; |
|
1758 |
// Do not bother to search in classes that are not abstract, |
|
1759 |
// since they cannot have abstract members. |
|
1760 |
if (c == impl || (c.flags() & (ABSTRACT | INTERFACE)) != 0) { |
|
1761 |
Scope s = c.members(); |
|
1762 |
for (Scope.Entry e = s.elems; |
|
1763 |
undef == null && e != null; |
|
1764 |
e = e.sibling) { |
|
1765 |
if (e.sym.kind == MTH && |
|
1766 |
(e.sym.flags() & (ABSTRACT|IPROXY)) == ABSTRACT) { |
|
1767 |
MethodSymbol absmeth = (MethodSymbol)e.sym; |
|
1768 |
MethodSymbol implmeth = absmeth.implementation(impl, types, true); |
|
1769 |
if (implmeth == null || implmeth == absmeth) |
|
1770 |
undef = absmeth; |
|
1771 |
} |
|
1772 |
} |
|
1773 |
if (undef == null) { |
|
1774 |
Type st = types.supertype(c.type); |
|
1775 |
if (st.tag == CLASS) |
|
1776 |
undef = firstUndef(impl, (ClassSymbol)st.tsym); |
|
1777 |
} |
|
1778 |
for (List<Type> l = types.interfaces(c.type); |
|
1779 |
undef == null && l.nonEmpty(); |
|
1780 |
l = l.tail) { |
|
1781 |
undef = firstUndef(impl, (ClassSymbol)l.head.tsym); |
|
1782 |
} |
|
1783 |
} |
|
1784 |
return undef; |
|
1785 |
} |
|
1786 |
||
6711
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1787 |
void checkNonCyclicDecl(JCClassDecl tree) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1788 |
CycleChecker cc = new CycleChecker(); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1789 |
cc.scan(tree); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1790 |
if (!cc.errorFound && !cc.partialCheck) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1791 |
tree.sym.flags_field |= ACYCLIC; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1792 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1793 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1794 |
|
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1795 |
class CycleChecker extends TreeScanner { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1796 |
|
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1797 |
List<Symbol> seenClasses = List.nil(); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1798 |
boolean errorFound = false; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1799 |
boolean partialCheck = false; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1800 |
|
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1801 |
private void checkSymbol(DiagnosticPosition pos, Symbol sym) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1802 |
if (sym != null && sym.kind == TYP) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1803 |
Env<AttrContext> classEnv = enter.getEnv((TypeSymbol)sym); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1804 |
if (classEnv != null) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1805 |
DiagnosticSource prevSource = log.currentSource(); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1806 |
try { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1807 |
log.useSource(classEnv.toplevel.sourcefile); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1808 |
scan(classEnv.tree); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1809 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1810 |
finally { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1811 |
log.useSource(prevSource.getFile()); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1812 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1813 |
} else if (sym.kind == TYP) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1814 |
checkClass(pos, sym, List.<JCTree>nil()); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1815 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1816 |
} else { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1817 |
//not completed yet |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1818 |
partialCheck = true; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1819 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1820 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1821 |
|
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1822 |
@Override |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1823 |
public void visitSelect(JCFieldAccess tree) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1824 |
super.visitSelect(tree); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1825 |
checkSymbol(tree.pos(), tree.sym); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1826 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1827 |
|
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1828 |
@Override |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1829 |
public void visitIdent(JCIdent tree) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1830 |
checkSymbol(tree.pos(), tree.sym); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1831 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1832 |
|
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1833 |
@Override |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1834 |
public void visitTypeApply(JCTypeApply tree) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1835 |
scan(tree.clazz); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1836 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1837 |
|
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1838 |
@Override |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1839 |
public void visitTypeArray(JCArrayTypeTree tree) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1840 |
scan(tree.elemtype); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1841 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1842 |
|
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1843 |
@Override |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1844 |
public void visitClassDef(JCClassDecl tree) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1845 |
List<JCTree> supertypes = List.nil(); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1846 |
if (tree.getExtendsClause() != null) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1847 |
supertypes = supertypes.prepend(tree.getExtendsClause()); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1848 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1849 |
if (tree.getImplementsClause() != null) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1850 |
for (JCTree intf : tree.getImplementsClause()) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1851 |
supertypes = supertypes.prepend(intf); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1852 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1853 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1854 |
checkClass(tree.pos(), tree.sym, supertypes); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1855 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1856 |
|
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1857 |
void checkClass(DiagnosticPosition pos, Symbol c, List<JCTree> supertypes) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1858 |
if ((c.flags_field & ACYCLIC) != 0) |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1859 |
return; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1860 |
if (seenClasses.contains(c)) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1861 |
errorFound = true; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1862 |
noteCyclic(pos, (ClassSymbol)c); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1863 |
} else if (!c.type.isErroneous()) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1864 |
try { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1865 |
seenClasses = seenClasses.prepend(c); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1866 |
if (c.type.tag == CLASS) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1867 |
if (supertypes.nonEmpty()) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1868 |
scan(supertypes); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1869 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1870 |
else { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1871 |
ClassType ct = (ClassType)c.type; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1872 |
if (ct.supertype_field == null || |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1873 |
ct.interfaces_field == null) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1874 |
//not completed yet |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1875 |
partialCheck = true; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1876 |
return; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1877 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1878 |
checkSymbol(pos, ct.supertype_field.tsym); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1879 |
for (Type intf : ct.interfaces_field) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1880 |
checkSymbol(pos, intf.tsym); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1881 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1882 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1883 |
if (c.owner.kind == TYP) { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1884 |
checkSymbol(pos, c.owner); |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1885 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1886 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1887 |
} finally { |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1888 |
seenClasses = seenClasses.tail; |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1889 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1890 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1891 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1892 |
} |
fc9732adc790
6863465: javac doesn't detect circular subclass dependencies via qualified names
mcimadamore
parents:
6352
diff
changeset
|
1893 |
|
10 | 1894 |
/** Check for cyclic references. Issue an error if the |
1895 |
* symbol of the type referred to has a LOCKED flag set. |
|
1896 |
* |
|
1897 |
* @param pos Position to be used for error reporting. |
|
1898 |
* @param t The type referred to. |
|
1899 |
*/ |
|
1900 |
void checkNonCyclic(DiagnosticPosition pos, Type t) { |
|
1901 |
checkNonCyclicInternal(pos, t); |
|
1902 |
} |
|
1903 |
||
1904 |
||
1905 |
void checkNonCyclic(DiagnosticPosition pos, TypeVar t) { |
|
2219
03b1b17c4b2e
6804733: javac generates spourious diagnostics for ill-formed type-variable bounds
mcimadamore
parents:
1874
diff
changeset
|
1906 |
checkNonCyclic1(pos, t, List.<TypeVar>nil()); |
10 | 1907 |
} |
1908 |
||
2219
03b1b17c4b2e
6804733: javac generates spourious diagnostics for ill-formed type-variable bounds
mcimadamore
parents:
1874
diff
changeset
|
1909 |
private void checkNonCyclic1(DiagnosticPosition pos, Type t, List<TypeVar> seen) { |
10 | 1910 |
final TypeVar tv; |
661
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
508
diff
changeset
|
1911 |
if (t.tag == TYPEVAR && (t.tsym.flags() & UNATTRIBUTED) != 0) |
9b2f1fe5c183
6677785: REGRESSION: StackOverFlowError with Cyclic Class level Type Parameters when used in constructors
mcimadamore
parents:
508
diff
changeset
|
1912 |
return; |
10 | 1913 |
if (seen.contains(t)) { |
1914 |
tv = (TypeVar)t; |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
1915 |
tv.bound = types.createErrorType(t); |
10 | 1916 |
log.error(pos, "cyclic.inheritance", t); |
1917 |
} else if (t.tag == TYPEVAR) { |
|
1918 |
tv = (TypeVar)t; |
|
2219
03b1b17c4b2e
6804733: javac generates spourious diagnostics for ill-formed type-variable bounds
mcimadamore
parents:
1874
diff
changeset
|
1919 |
seen = seen.prepend(tv); |
10 | 1920 |
for (Type b : types.getBounds(tv)) |
1921 |
checkNonCyclic1(pos, b, seen); |
|
1922 |
} |
|
1923 |
} |
|
1924 |
||
1925 |
/** Check for cyclic references. Issue an error if the |
|
1926 |
* symbol of the type referred to has a LOCKED flag set. |
|
1927 |
* |
|
1928 |
* @param pos Position to be used for error reporting. |
|
1929 |
* @param t The type referred to. |
|
1930 |
* @returns True if the check completed on all attributed classes |
|
1931 |
*/ |
|
1932 |
private boolean checkNonCyclicInternal(DiagnosticPosition pos, Type t) { |
|
1933 |
boolean complete = true; // was the check complete? |
|
1934 |
//- System.err.println("checkNonCyclicInternal("+t+");");//DEBUG |
|
1935 |
Symbol c = t.tsym; |
|
1936 |
if ((c.flags_field & ACYCLIC) != 0) return true; |
|
1937 |
||
1938 |
if ((c.flags_field & LOCKED) != 0) { |
|
1939 |
noteCyclic(pos, (ClassSymbol)c); |
|
1940 |
} else if (!c.type.isErroneous()) { |
|
1941 |
try { |
|
1942 |
c.flags_field |= LOCKED; |
|
1943 |
if (c.type.tag == CLASS) { |
|
1944 |
ClassType clazz = (ClassType)c.type; |
|
1945 |
if (clazz.interfaces_field != null) |
|
1946 |
for (List<Type> l=clazz.interfaces_field; l.nonEmpty(); l=l.tail) |
|
1947 |
complete &= checkNonCyclicInternal(pos, l.head); |
|
1948 |
if (clazz.supertype_field != null) { |
|
1949 |
Type st = clazz.supertype_field; |
|
1950 |
if (st != null && st.tag == CLASS) |
|
1951 |
complete &= checkNonCyclicInternal(pos, st); |
|
1952 |
} |
|
1953 |
if (c.owner.kind == TYP) |
|
1954 |
complete &= checkNonCyclicInternal(pos, c.owner.type); |
|
1955 |
} |
|
1956 |
} finally { |
|
1957 |
c.flags_field &= ~LOCKED; |
|
1958 |
} |
|
1959 |
} |
|
1960 |
if (complete) |
|
1961 |
complete = ((c.flags_field & UNATTRIBUTED) == 0) && c.completer == null; |
|
1962 |
if (complete) c.flags_field |= ACYCLIC; |
|
1963 |
return complete; |
|
1964 |
} |
|
1965 |
||
1966 |
/** Note that we found an inheritance cycle. */ |
|
1967 |
private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) { |
|
1968 |
log.error(pos, "cyclic.inheritance", c); |
|
1969 |
for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail) |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
1970 |
l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType); |
10 | 1971 |
Type st = types.supertype(c.type); |
1972 |
if (st.tag == CLASS) |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
1973 |
((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1040
diff
changeset
|
1974 |
c.type = types.createErrorType(c, c.type); |
10 | 1975 |
c.flags_field |= ACYCLIC; |
1976 |
} |
|
1977 |
||
1978 |
/** Check that all methods which implement some |
|
1979 |
* method conform to the method they implement. |
|
1980 |
* @param tree The class definition whose members are checked. |
|
1981 |
*/ |
|
1982 |
void checkImplementations(JCClassDecl tree) { |
|
1983 |
checkImplementations(tree, tree.sym); |
|
1984 |
} |
|
1985 |
//where |
|
1986 |
/** Check that all methods which implement some |
|
1987 |
* method in `ic' conform to the method they implement. |
|
1988 |
*/ |
|
1989 |
void checkImplementations(JCClassDecl tree, ClassSymbol ic) { |
|
1990 |
ClassSymbol origin = tree.sym; |
|
1991 |
for (List<Type> l = types.closure(ic.type); l.nonEmpty(); l = l.tail) { |
|
1992 |
ClassSymbol lc = (ClassSymbol)l.head.tsym; |
|
1993 |
if ((allowGenerics || origin != lc) && (lc.flags() & ABSTRACT) != 0) { |
|
1994 |
for (Scope.Entry e=lc.members().elems; e != null; e=e.sibling) { |
|
1995 |
if (e.sym.kind == MTH && |
|
1996 |
(e.sym.flags() & (STATIC|ABSTRACT)) == ABSTRACT) { |
|
1997 |
MethodSymbol absmeth = (MethodSymbol)e.sym; |
|
1998 |
MethodSymbol implmeth = absmeth.implementation(origin, types, false); |
|
1999 |
if (implmeth != null && implmeth != absmeth && |
|
2000 |
(implmeth.owner.flags() & INTERFACE) == |
|
2001 |
(origin.flags() & INTERFACE)) { |
|
2002 |
// don't check if implmeth is in a class, yet |
|
2003 |
// origin is an interface. This case arises only |
|
2004 |
// if implmeth is declared in Object. The reason is |
|
2005 |
// that interfaces really don't inherit from |
|
2006 |
// Object it's just that the compiler represents |
|
2007 |
// things that way. |
|
2008 |
checkOverride(tree, implmeth, absmeth, origin); |
|
2009 |
} |
|
2010 |
} |
|
2011 |
} |
|
2012 |
} |
|
2013 |
} |
|
2014 |
} |
|
2015 |
||
2016 |
/** Check that all abstract methods implemented by a class are |
|
2017 |
* mutually compatible. |
|
2018 |
* @param pos Position to be used for error reporting. |
|
2019 |
* @param c The class whose interfaces are checked. |
|
2020 |
*/ |
|
2021 |
void checkCompatibleSupertypes(DiagnosticPosition pos, Type c) { |
|
2022 |
List<Type> supertypes = types.interfaces(c); |
|
2023 |
Type supertype = types.supertype(c); |
|
2024 |
if (supertype.tag == CLASS && |
|
2025 |
(supertype.tsym.flags() & ABSTRACT) != 0) |
|
2026 |
supertypes = supertypes.prepend(supertype); |
|
2027 |
for (List<Type> l = supertypes; l.nonEmpty(); l = l.tail) { |
|
2028 |
if (allowGenerics && !l.head.getTypeArguments().isEmpty() && |
|
2029 |
!checkCompatibleAbstracts(pos, l.head, l.head, c)) |
|
2030 |
return; |
|
2031 |
for (List<Type> m = supertypes; m != l; m = m.tail) |
|
2032 |
if (!checkCompatibleAbstracts(pos, l.head, m.head, c)) |
|
2033 |
return; |
|
2034 |
} |
|
2035 |
checkCompatibleConcretes(pos, c); |
|
2036 |
} |
|
2037 |
||
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2038 |
void checkConflicts(DiagnosticPosition pos, Symbol sym, TypeSymbol c) { |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2039 |
for (Type ct = c.type; ct != Type.noType ; ct = types.supertype(ct)) { |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2040 |
for (Scope.Entry e = ct.tsym.members().lookup(sym.name); e.scope == ct.tsym.members(); e = e.next()) { |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2041 |
// VM allows methods and variables with differing types |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2042 |
if (sym.kind == e.sym.kind && |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2043 |
types.isSameType(types.erasure(sym.type), types.erasure(e.sym.type)) && |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2044 |
sym != e.sym && |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2045 |
(sym.flags() & Flags.SYNTHETIC) != (e.sym.flags() & Flags.SYNTHETIC) && |
6147
0074061d0efd
6964669: javac reports error on miranda methods
mcimadamore
parents:
6032
diff
changeset
|
2046 |
(sym.flags() & IPROXY) == 0 && (e.sym.flags() & IPROXY) == 0 && |
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2047 |
(sym.flags() & BRIDGE) == 0 && (e.sym.flags() & BRIDGE) == 0) { |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2048 |
syntheticError(pos, (e.sym.flags() & SYNTHETIC) == 0 ? e.sym : sym); |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2049 |
return; |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2050 |
} |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2051 |
} |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2052 |
} |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2053 |
} |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2054 |
|
7628
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2055 |
/** Check that all non-override equivalent methods accessible from 'site' |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2056 |
* are mutually compatible (JLS 8.4.8/9.4.1). |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2057 |
* |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2058 |
* @param pos Position to be used for error reporting. |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2059 |
* @param site The class whose methods are checked. |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2060 |
* @param sym The method symbol to be checked. |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2061 |
*/ |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2062 |
void checkClashes(DiagnosticPosition pos, Type site, Symbol sym) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2063 |
List<Type> supertypes = types.closure(site); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2064 |
for (List<Type> l = supertypes; l.nonEmpty(); l = l.tail) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2065 |
for (List<Type> m = supertypes; m.nonEmpty(); m = m.tail) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2066 |
checkClashes(pos, l.head, m.head, site, sym); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2067 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2068 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2069 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2070 |
|
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2071 |
/** Reports an error whenever 'sym' seen as a member of type 't1' clashes with |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2072 |
* some unrelated method defined in 't2'. |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2073 |
*/ |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2074 |
private void checkClashes(DiagnosticPosition pos, Type t1, Type t2, Type site, Symbol s1) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2075 |
ClashFilter cf = new ClashFilter(site); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2076 |
s1 = ((MethodSymbol)s1).implementedIn(t1.tsym, types); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2077 |
if (s1 == null) return; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2078 |
Type st1 = types.memberType(site, s1); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2079 |
for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name, cf); e2.scope != null; e2 = e2.next(cf)) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2080 |
Symbol s2 = e2.sym; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2081 |
if (s1 == s2) continue; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2082 |
Type st2 = types.memberType(site, s2); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2083 |
if (!types.overrideEquivalent(st1, st2) && |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2084 |
!checkNameClash((ClassSymbol)site.tsym, s1, s2)) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2085 |
log.error(pos, |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2086 |
"name.clash.same.erasure.no.override", |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2087 |
s1, s1.location(), |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2088 |
s2, s2.location()); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2089 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2090 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2091 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2092 |
//where |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2093 |
private class ClashFilter implements Filter<Symbol> { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2094 |
|
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2095 |
Type site; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2096 |
|
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2097 |
ClashFilter(Type site) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2098 |
this.site = site; |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2099 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2100 |
|
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2101 |
public boolean accepts(Symbol s) { |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2102 |
return s.kind == MTH && |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2103 |
(s.flags() & SYNTHETIC) == 0 && |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2104 |
s.isInheritedIn(site.tsym, types) && |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2105 |
!s.isConstructor(); |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2106 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2107 |
} |
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7214
diff
changeset
|
2108 |
|
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2109 |
/** Report a conflict between a user symbol and a synthetic symbol. |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2110 |
*/ |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2111 |
private void syntheticError(DiagnosticPosition pos, Symbol sym) { |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2112 |
if (!sym.type.isErroneous()) { |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2113 |
if (warnOnSyntheticConflicts) { |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2114 |
log.warning(pos, "synthetic.name.conflict", sym, sym.location()); |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2115 |
} |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2116 |
else { |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2117 |
log.error(pos, "synthetic.name.conflict", sym, sym.location()); |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2118 |
} |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2119 |
} |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2120 |
} |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3149
diff
changeset
|
2121 |
|
10 | 2122 |
/** Check that class c does not implement directly or indirectly |
2123 |
* the same parameterized interface with two different argument lists. |
|
2124 |
* @param pos Position to be used for error reporting. |
|
2125 |
* @param type The type whose interfaces are checked. |
|
2126 |
*/ |
|
2127 |
void checkClassBounds(DiagnosticPosition pos, Type type) { |
|
2128 |
checkClassBounds(pos, new HashMap<TypeSymbol,Type>(), type); |
|
2129 |
} |
|
2130 |
//where |
|
2131 |
/** Enter all interfaces of type `type' into the hash table `seensofar' |
|
2132 |
* with their class symbol as key and their type as value. Make |
|
2133 |
* sure no class is entered with two different types. |
|
2134 |
*/ |
|
2135 |
void checkClassBounds(DiagnosticPosition pos, |
|
2136 |
Map<TypeSymbol,Type> seensofar, |
|
2137 |
Type type) { |
|
2138 |
if (type.isErroneous()) return; |
|
2139 |
for (List<Type> l = types.interfaces(type); l.nonEmpty(); l = l.tail) { |
|
2140 |
Type it = l.head; |
|
2141 |
Type oldit = seensofar.put(it.tsym, it); |
|
2142 |
if (oldit != null) { |
|
2143 |
List<Type> oldparams = oldit.allparams(); |
|
2144 |
List<Type> newparams = it.allparams(); |
|
2145 |
if (!types.containsTypeEquivalent(oldparams, newparams)) |
|
2146 |
log.error(pos, "cant.inherit.diff.arg", |
|
2147 |
it.tsym, Type.toString(oldparams), |
|
2148 |
Type.toString(newparams)); |
|
2149 |
} |
|
2150 |
checkClassBounds(pos, seensofar, it); |
|
2151 |
} |
|
2152 |
Type st = types.supertype(type); |
|
2153 |
if (st != null) checkClassBounds(pos, seensofar, st); |
|
2154 |
} |
|
2155 |
||
2156 |
/** Enter interface into into set. |
|
2157 |
* If it existed already, issue a "repeated interface" error. |
|
2158 |
*/ |
|
2159 |
void checkNotRepeated(DiagnosticPosition pos, Type it, Set<Type> its) { |
|
2160 |
if (its.contains(it)) |
|
2161 |
log.error(pos, "repeated.interface"); |
|
2162 |
else { |
|
2163 |
its.add(it); |
|
2164 |
} |
|
2165 |
} |
|
2166 |
||
2167 |
/* ************************************************************************* |
|
2168 |
* Check annotations |
|
2169 |
**************************************************************************/ |
|
2170 |
||
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2171 |
/** |
6347
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6345
diff
changeset
|
2172 |
* Recursively validate annotations values |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2173 |
*/ |
6347
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6345
diff
changeset
|
2174 |
void validateAnnotationTree(JCTree tree) { |
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6345
diff
changeset
|
2175 |
class AnnotationValidator extends TreeScanner { |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2176 |
@Override |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2177 |
public void visitAnnotation(JCAnnotation tree) { |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2178 |
super.visitAnnotation(tree); |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2179 |
validateAnnotation(tree); |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2180 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2181 |
} |
6347
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6345
diff
changeset
|
2182 |
tree.accept(new AnnotationValidator()); |
6342
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2183 |
} |
228b73431edb
6881115: javac permits nested anno w/o mandatory attrs => IncompleteAnnotationException
mcimadamore
parents:
6151
diff
changeset
|
2184 |
|
10 | 2185 |
/** Annotation types are restricted to primitives, String, an |
2186 |
* enum, an annotation, Class, Class<?>, Class<? extends |
|
2187 |
* Anything>, arrays of the preceding. |
|
2188 |
*/ |
|
2189 |
void validateAnnotationType(JCTree restype) { |
|
2190 |
// restype may be null if an error occurred, so don't bother validating it |
|
2191 |
if (restype != null) { |
|
2192 |
validateAnnotationType(restype.pos(), restype.type); |
|
2193 |
} |
|
2194 |
} |
|
2195 |
||
2196 |
void validateAnnotationType(DiagnosticPosition pos, Type type) { |
|
2197 |
if (type.isPrimitive()) return; |
|
2198 |
if (types.isSameType(type, syms.stringType)) return; |
|
2199 |
if ((type.tsym.flags() & Flags.ENUM) != 0) return; |
|
2200 |
if ((type.tsym.flags() & Flags.ANNOTATION) != 0) return; |
|
2201 |
if (types.lowerBound(type).tsym == syms.classType.tsym) return; |
|
2202 |
if (types.isArray(type) && !types.isArray(types.elemtype(type))) { |
|
2203 |
validateAnnotationType(pos, types.elemtype(type)); |
|
2204 |
return; |
|
2205 |
} |
|
2206 |
log.error(pos, "invalid.annotation.member.type"); |
|
2207 |
} |
|
2208 |
||
2209 |
/** |
|
2210 |
* "It is also a compile-time error if any method declared in an |
|
2211 |
* annotation type has a signature that is override-equivalent to |
|
2212 |
* that of any public or protected method declared in class Object |
|
2213 |
* or in the interface annotation.Annotation." |
|
2214 |
* |
|
2215 |
* @jls3 9.6 Annotation Types |
|
2216 |
*/ |
|
2217 |
void validateAnnotationMethod(DiagnosticPosition pos, MethodSymbol m) { |
|
2218 |
for (Type sup = syms.annotationType; sup.tag == CLASS; sup = types.supertype(sup)) { |
|
2219 |
Scope s = sup.tsym.members(); |
|
2220 |
for (Scope.Entry e = s.lookup(m.name); e.scope != null; e = e.next()) { |
|
2221 |
if (e.sym.kind == MTH && |
|
2222 |
(e.sym.flags() & (PUBLIC | PROTECTED)) != 0 && |
|
2223 |
types.overrideEquivalent(m.type, e.sym.type)) |
|
2224 |
log.error(pos, "intf.annotation.member.clash", e.sym, sup); |
|
2225 |
} |
|
2226 |
} |
|
2227 |
} |
|
2228 |
||
2229 |
/** Check the annotations of a symbol. |
|
2230 |
*/ |
|
2231 |
public void validateAnnotations(List<JCAnnotation> annotations, Symbol s) { |
|
2232 |
if (skipAnnotations) return; |
|
2233 |
for (JCAnnotation a : annotations) |
|
2234 |
validateAnnotation(a, s); |
|
2235 |
} |
|
2236 |
||
2237 |
/** Check an annotation of a symbol. |
|
2238 |
*/ |
|
2239 |
public void validateAnnotation(JCAnnotation a, Symbol s) { |
|
6347
947437d52cc1
6976649: javac does not enforce required annotation elements in arrays
mcimadamore
parents:
6345
diff
changeset
|
2240 |
validateAnnotationTree(a); |
10 | 2241 |
|
2242 |
if (!annotationApplicable(a, s)) |
|
2243 |
log.error(a.pos(), "annotation.type.not.applicable"); |
|
2244 |
||
2245 |
if (a.annotationType.type.tsym == syms.overrideType.tsym) { |
|
2246 |
if (!isOverrider(s)) |
|
2247 |
log.error(a.pos(), "method.does.not.override.superclass"); |
|
2248 |
} |
|
2249 |
} |
|
2250 |
||
2251 |
/** Is s a method symbol that overrides a method in a superclass? */ |
|
2252 |
boolean isOverrider(Symbol s) { |
|
2253 |
if (s.kind != MTH || s.isStatic()) |
|
2254 |
return false; |
|
2255 |
MethodSymbol m = (MethodSymbol)s; |
|
2256 |
TypeSymbol owner = (TypeSymbol)m.owner; |
|
2257 |
for (Type sup : types.closure(owner.type)) { |
|
2258 |
if (sup == owner.type) |
|
2259 |
continue; // skip "this" |
|
2260 |
Scope scope = sup.tsym.members(); |
|
2261 |
for (Scope.Entry e = scope.lookup(m.name); e.scope != null; e = e.next()) { |
|
2262 |
if (!e.sym.isStatic() && m.overrides(e.sym, owner, types, true)) |
|
2263 |
return true; |
|
2264 |
} |
|
2265 |
} |
|
2266 |
return false; |
|
2267 |
} |
|
2268 |
||
2269 |
/** Is the annotation applicable to the symbol? */ |
|
2270 |
boolean annotationApplicable(JCAnnotation a, Symbol s) { |
|
2271 |
Attribute.Compound atTarget = |
|
2272 |
a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); |
|
2273 |
if (atTarget == null) return true; |
|
2274 |
Attribute atValue = atTarget.member(names.value); |
|
2275 |
if (!(atValue instanceof Attribute.Array)) return true; // error recovery |
|
2276 |
Attribute.Array arr = (Attribute.Array) atValue; |
|
2277 |
for (Attribute app : arr.values) { |
|
2278 |
if (!(app instanceof Attribute.Enum)) return true; // recovery |
|
2279 |
Attribute.Enum e = (Attribute.Enum) app; |
|
2280 |
if (e.value.name == names.TYPE) |
|
2281 |
{ if (s.kind == TYP) return true; } |
|
2282 |
else if (e.value.name == names.FIELD) |
|
2283 |
{ if (s.kind == VAR && s.owner.kind != MTH) return true; } |
|
2284 |
else if (e.value.name == names.METHOD) |
|
2285 |
{ if (s.kind == MTH && !s.isConstructor()) return true; } |
|
2286 |
else if (e.value.name == names.PARAMETER) |
|
2287 |
{ if (s.kind == VAR && |
|
2288 |
s.owner.kind == MTH && |
|
2289 |
(s.flags() & PARAMETER) != 0) |
|
2290 |
return true; |
|
2291 |
} |
|
2292 |
else if (e.value.name == names.CONSTRUCTOR) |
|
2293 |
{ if (s.kind == MTH && s.isConstructor()) return true; } |
|
2294 |
else if (e.value.name == names.LOCAL_VARIABLE) |
|
2295 |
{ if (s.kind == VAR && s.owner.kind == MTH && |
|
2296 |
(s.flags() & PARAMETER) == 0) |
|
2297 |
return true; |
|
2298 |
} |
|
2299 |
else if (e.value.name == names.ANNOTATION_TYPE) |
|
2300 |
{ if (s.kind == TYP && (s.flags() & ANNOTATION) != 0) |
|
2301 |
return true; |
|
2302 |
} |
|
2303 |
else if (e.value.name == names.PACKAGE) |
|
2304 |
{ if (s.kind == PCK) return true; } |
|
3149 | 2305 |
else if (e.value.name == names.TYPE_USE) |
2306 |
{ if (s.kind == TYP || |
|
2307 |
s.kind == VAR || |
|
2308 |
(s.kind == MTH && !s.isConstructor() && |
|
2309 |
s.type.getReturnType().tag != VOID)) |
|
2310 |
return true; |
|
2311 |
} |
|
10 | 2312 |
else |
2313 |
return true; // recovery |
|
2314 |
} |
|
2315 |
return false; |
|
2316 |
} |
|
2317 |
||
2318 |
/** Check an annotation value. |
|
2319 |
*/ |
|
2320 |
public void validateAnnotation(JCAnnotation a) { |
|
2321 |
if (a.type.isErroneous()) return; |
|
2322 |
||
6345
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2323 |
// collect an inventory of the members (sorted alphabetically) |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2324 |
Set<MethodSymbol> members = new TreeSet<MethodSymbol>(new Comparator<Symbol>() { |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2325 |
public int compare(Symbol t, Symbol t1) { |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2326 |
return t.name.compareTo(t1.name); |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2327 |
} |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2328 |
}); |
10 | 2329 |
for (Scope.Entry e = a.annotationType.type.tsym.members().elems; |
2330 |
e != null; |
|
2331 |
e = e.sibling) |
|
2332 |
if (e.sym.kind == MTH) |
|
2333 |
members.add((MethodSymbol) e.sym); |
|
2334 |
||
2335 |
// count them off as they're annotated |
|
2336 |
for (JCTree arg : a.args) { |
|
2337 |
if (arg.getTag() != JCTree.ASSIGN) continue; // recovery |
|
2338 |
JCAssign assign = (JCAssign) arg; |
|
2339 |
Symbol m = TreeInfo.symbol(assign.lhs); |
|
2340 |
if (m == null || m.type.isErroneous()) continue; |
|
2341 |
if (!members.remove(m)) |
|
4867
7f4efc9b2f9f
6919944: incorrect position given for duplicate annotation value error
jjg
parents:
3780
diff
changeset
|
2342 |
log.error(assign.lhs.pos(), "duplicate.annotation.member.value", |
10 | 2343 |
m.name, a.type); |
2344 |
} |
|
2345 |
||
2346 |
// all the remaining ones better have default values |
|
6345
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2347 |
ListBuffer<Name> missingDefaults = ListBuffer.lb(); |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2348 |
for (MethodSymbol m : members) { |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2349 |
if (m.defaultValue == null && !m.type.isErroneous()) { |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2350 |
missingDefaults.append(m.name); |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2351 |
} |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2352 |
} |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2353 |
if (missingDefaults.nonEmpty()) { |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2354 |
String key = (missingDefaults.size() > 1) |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2355 |
? "annotation.missing.default.value.1" |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2356 |
: "annotation.missing.default.value"; |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2357 |
log.error(a.pos(), key, a.type, missingDefaults); |
7d98c298aafd
6975231: Regression test for 6881115 is failing with compiler output not matching expected output
mcimadamore
parents:
6342
diff
changeset
|
2358 |
} |
10 | 2359 |
|
2360 |
// special case: java.lang.annotation.Target must not have |
|
2361 |
// repeated values in its value member |
|
2362 |
if (a.annotationType.type.tsym != syms.annotationTargetType.tsym || |
|
2363 |
a.args.tail == null) |
|
2364 |
return; |
|
2365 |
||
2366 |
if (a.args.head.getTag() != JCTree.ASSIGN) return; // error recovery |
|
2367 |
JCAssign assign = (JCAssign) a.args.head; |
|
2368 |
Symbol m = TreeInfo.symbol(assign.lhs); |
|
2369 |
if (m.name != names.value) return; |
|
2370 |
JCTree rhs = assign.rhs; |
|
2371 |
if (rhs.getTag() != JCTree.NEWARRAY) return; |
|
2372 |
JCNewArray na = (JCNewArray) rhs; |
|
2373 |
Set<Symbol> targets = new HashSet<Symbol>(); |
|
2374 |
for (JCTree elem : na.elems) { |
|
2375 |
if (!targets.add(TreeInfo.symbol(elem))) { |
|
2376 |
log.error(elem.pos(), "repeated.annotation.target"); |
|
2377 |
} |
|
2378 |
} |
|
2379 |
} |
|
2380 |
||
2381 |
void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) { |
|
2382 |
if (allowAnnotations && |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2383 |
lint.isEnabled(LintCategory.DEP_ANN) && |
10 | 2384 |
(s.flags() & DEPRECATED) != 0 && |
2385 |
!syms.deprecatedType.isErroneous() && |
|
2386 |
s.attribute(syms.deprecatedType.tsym) == null) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2387 |
log.warning(LintCategory.DEP_ANN, |
6151
dd513881e71d
6957438: improve code for generating warning messages containing option names
jjg
parents:
6148
diff
changeset
|
2388 |
pos, "missing.deprecated.annotation"); |
10 | 2389 |
} |
2390 |
} |
|
2391 |
||
2392 |
/* ************************************************************************* |
|
2393 |
* Check for recursive annotation elements. |
|
2394 |
**************************************************************************/ |
|
2395 |
||
2396 |
/** Check for cycles in the graph of annotation elements. |
|
2397 |
*/ |
|
2398 |
void checkNonCyclicElements(JCClassDecl tree) { |
|
2399 |
if ((tree.sym.flags_field & ANNOTATION) == 0) return; |
|
8032 | 2400 |
Assert.check((tree.sym.flags_field & LOCKED) == 0); |
10 | 2401 |
try { |
2402 |
tree.sym.flags_field |= LOCKED; |
|
2403 |
for (JCTree def : tree.defs) { |
|
2404 |
if (def.getTag() != JCTree.METHODDEF) continue; |
|
2405 |
JCMethodDecl meth = (JCMethodDecl)def; |
|
2406 |
checkAnnotationResType(meth.pos(), meth.restype.type); |
|
2407 |
} |
|
2408 |
} finally { |
|
2409 |
tree.sym.flags_field &= ~LOCKED; |
|
2410 |
tree.sym.flags_field |= ACYCLIC_ANN; |
|
2411 |
} |
|
2412 |
} |
|
2413 |
||
2414 |
void checkNonCyclicElementsInternal(DiagnosticPosition pos, TypeSymbol tsym) { |
|
2415 |
if ((tsym.flags_field & ACYCLIC_ANN) != 0) |
|
2416 |
return; |
|
2417 |
if ((tsym.flags_field & LOCKED) != 0) { |
|
2418 |
log.error(pos, "cyclic.annotation.element"); |
|
2419 |
return; |
|
2420 |
} |
|
2421 |
try { |
|
2422 |
tsym.flags_field |= LOCKED; |
|
2423 |
for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) { |
|
2424 |
Symbol s = e.sym; |
|
2425 |
if (s.kind != Kinds.MTH) |
|
2426 |
continue; |
|
2427 |
checkAnnotationResType(pos, ((MethodSymbol)s).type.getReturnType()); |
|
2428 |
} |
|
2429 |
} finally { |
|
2430 |
tsym.flags_field &= ~LOCKED; |
|
2431 |
tsym.flags_field |= ACYCLIC_ANN; |
|
2432 |
} |
|
2433 |
} |
|
2434 |
||
2435 |
void checkAnnotationResType(DiagnosticPosition pos, Type type) { |
|
2436 |
switch (type.tag) { |
|
2437 |
case TypeTags.CLASS: |
|
2438 |
if ((type.tsym.flags() & ANNOTATION) != 0) |
|
2439 |
checkNonCyclicElementsInternal(pos, type.tsym); |
|
2440 |
break; |
|
2441 |
case TypeTags.ARRAY: |
|
2442 |
checkAnnotationResType(pos, types.elemtype(type)); |
|
2443 |
break; |
|
2444 |
default: |
|
2445 |
break; // int etc |
|
2446 |
} |
|
2447 |
} |
|
2448 |
||
2449 |
/* ************************************************************************* |
|
2450 |
* Check for cycles in the constructor call graph. |
|
2451 |
**************************************************************************/ |
|
2452 |
||
2453 |
/** Check for cycles in the graph of constructors calling other |
|
2454 |
* constructors. |
|
2455 |
*/ |
|
2456 |
void checkCyclicConstructors(JCClassDecl tree) { |
|
2457 |
Map<Symbol,Symbol> callMap = new HashMap<Symbol, Symbol>(); |
|
2458 |
||
2459 |
// enter each constructor this-call into the map |
|
2460 |
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { |
|
2461 |
JCMethodInvocation app = TreeInfo.firstConstructorCall(l.head); |
|
2462 |
if (app == null) continue; |
|
2463 |
JCMethodDecl meth = (JCMethodDecl) l.head; |
|
2464 |
if (TreeInfo.name(app.meth) == names._this) { |
|
2465 |
callMap.put(meth.sym, TreeInfo.symbol(app.meth)); |
|
2466 |
} else { |
|
2467 |
meth.sym.flags_field |= ACYCLIC; |
|
2468 |
} |
|
2469 |
} |
|
2470 |
||
2471 |
// Check for cycles in the map |
|
2472 |
Symbol[] ctors = new Symbol[0]; |
|
2473 |
ctors = callMap.keySet().toArray(ctors); |
|
2474 |
for (Symbol caller : ctors) { |
|
2475 |
checkCyclicConstructor(tree, caller, callMap); |
|
2476 |
} |
|
2477 |
} |
|
2478 |
||
2479 |
/** Look in the map to see if the given constructor is part of a |
|
2480 |
* call cycle. |
|
2481 |
*/ |
|
2482 |
private void checkCyclicConstructor(JCClassDecl tree, Symbol ctor, |
|
2483 |
Map<Symbol,Symbol> callMap) { |
|
2484 |
if (ctor != null && (ctor.flags_field & ACYCLIC) == 0) { |
|
2485 |
if ((ctor.flags_field & LOCKED) != 0) { |
|
2486 |
log.error(TreeInfo.diagnosticPositionFor(ctor, tree), |
|
2487 |
"recursive.ctor.invocation"); |
|
2488 |
} else { |
|
2489 |
ctor.flags_field |= LOCKED; |
|
2490 |
checkCyclicConstructor(tree, callMap.remove(ctor), callMap); |
|
2491 |
ctor.flags_field &= ~LOCKED; |
|
2492 |
} |
|
2493 |
ctor.flags_field |= ACYCLIC; |
|
2494 |
} |
|
2495 |
} |
|
2496 |
||
2497 |
/* ************************************************************************* |
|
2498 |
* Miscellaneous |
|
2499 |
**************************************************************************/ |
|
2500 |
||
2501 |
/** |
|
2502 |
* Return the opcode of the operator but emit an error if it is an |
|
2503 |
* error. |
|
2504 |
* @param pos position for error reporting. |
|
2505 |
* @param operator an operator |
|
2506 |
* @param tag a tree tag |
|
2507 |
* @param left type of left hand side |
|
2508 |
* @param right type of right hand side |
|
2509 |
*/ |
|
2510 |
int checkOperator(DiagnosticPosition pos, |
|
2511 |
OperatorSymbol operator, |
|
2512 |
int tag, |
|
2513 |
Type left, |
|
2514 |
Type right) { |
|
2515 |
if (operator.opcode == ByteCodes.error) { |
|
2516 |
log.error(pos, |
|
2517 |
"operator.cant.be.applied", |
|
2518 |
treeinfo.operatorName(tag), |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
938
diff
changeset
|
2519 |
List.of(left, right)); |
10 | 2520 |
} |
2521 |
return operator.opcode; |
|
2522 |
} |
|
2523 |
||
2524 |
||
2525 |
/** |
|
2526 |
* Check for division by integer constant zero |
|
2527 |
* @param pos Position for error reporting. |
|
2528 |
* @param operator The operator for the expression |
|
2529 |
* @param operand The right hand operand for the expression |
|
2530 |
*/ |
|
2531 |
void checkDivZero(DiagnosticPosition pos, Symbol operator, Type operand) { |
|
2532 |
if (operand.constValue() != null |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2533 |
&& lint.isEnabled(LintCategory.DIVZERO) |
10 | 2534 |
&& operand.tag <= LONG |
2535 |
&& ((Number) (operand.constValue())).longValue() == 0) { |
|
2536 |
int opc = ((OperatorSymbol)operator).opcode; |
|
2537 |
if (opc == ByteCodes.idiv || opc == ByteCodes.imod |
|
2538 |
|| opc == ByteCodes.ldiv || opc == ByteCodes.lmod) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2539 |
log.warning(LintCategory.DIVZERO, pos, "div.zero"); |
10 | 2540 |
} |
2541 |
} |
|
2542 |
} |
|
2543 |
||
2544 |
/** |
|
2545 |
* Check for empty statements after if |
|
2546 |
*/ |
|
2547 |
void checkEmptyIf(JCIf tree) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2548 |
if (tree.thenpart.getTag() == JCTree.SKIP && tree.elsepart == null && lint.isEnabled(LintCategory.EMPTY)) |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2549 |
log.warning(LintCategory.EMPTY, tree.thenpart.pos(), "empty.if"); |
10 | 2550 |
} |
2551 |
||
2552 |
/** Check that symbol is unique in given scope. |
|
2553 |
* @param pos Position for error reporting. |
|
2554 |
* @param sym The symbol. |
|
2555 |
* @param s The scope. |
|
2556 |
*/ |
|
2557 |
boolean checkUnique(DiagnosticPosition pos, Symbol sym, Scope s) { |
|
2558 |
if (sym.type.isErroneous()) |
|
2559 |
return true; |
|
2560 |
if (sym.owner.name == names.any) return false; |
|
2561 |
for (Scope.Entry e = s.lookup(sym.name); e.scope == s; e = e.next()) { |
|
2562 |
if (sym != e.sym && |
|
2563 |
sym.kind == e.sym.kind && |
|
2564 |
sym.name != names.error && |
|
2509
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2565 |
(sym.kind != MTH || types.hasSameArgs(types.erasure(sym.type), types.erasure(e.sym.type)))) { |
10 | 2566 |
if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS)) |
2567 |
varargsDuplicateError(pos, sym, e.sym); |
|
2509
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2568 |
else if (sym.kind == MTH && !types.overrideEquivalent(sym.type, e.sym.type)) |
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2569 |
duplicateErasureError(pos, sym, e.sym); |
10 | 2570 |
else |
2571 |
duplicateError(pos, e.sym); |
|
2572 |
return false; |
|
2573 |
} |
|
2574 |
} |
|
2575 |
return true; |
|
2576 |
} |
|
2509
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2577 |
//where |
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2578 |
/** Report duplicate declaration error. |
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2579 |
*/ |
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2580 |
void duplicateErasureError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) { |
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2581 |
if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) { |
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2582 |
log.error(pos, "name.clash.same.erasure", sym1, sym2); |
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2583 |
} |
c8a1744c87fd
6182950: methods clash algorithm should not depend on return type
mcimadamore
parents:
2223
diff
changeset
|
2584 |
} |
10 | 2585 |
|
2586 |
/** Check that single-type import is not already imported or top-level defined, |
|
2587 |
* but make an exception for two single-type imports which denote the same type. |
|
2588 |
* @param pos Position for error reporting. |
|
2589 |
* @param sym The symbol. |
|
2590 |
* @param s The scope |
|
2591 |
*/ |
|
2592 |
boolean checkUniqueImport(DiagnosticPosition pos, Symbol sym, Scope s) { |
|
2593 |
return checkUniqueImport(pos, sym, s, false); |
|
2594 |
} |
|
2595 |
||
2596 |
/** Check that static single-type import is not already imported or top-level defined, |
|
2597 |
* but make an exception for two single-type imports which denote the same type. |
|
2598 |
* @param pos Position for error reporting. |
|
2599 |
* @param sym The symbol. |
|
2600 |
* @param s The scope |
|
2601 |
* @param staticImport Whether or not this was a static import |
|
2602 |
*/ |
|
2603 |
boolean checkUniqueStaticImport(DiagnosticPosition pos, Symbol sym, Scope s) { |
|
2604 |
return checkUniqueImport(pos, sym, s, true); |
|
2605 |
} |
|
2606 |
||
2607 |
/** Check that single-type import is not already imported or top-level defined, |
|
2608 |
* but make an exception for two single-type imports which denote the same type. |
|
2609 |
* @param pos Position for error reporting. |
|
2610 |
* @param sym The symbol. |
|
2611 |
* @param s The scope. |
|
2612 |
* @param staticImport Whether or not this was a static import |
|
2613 |
*/ |
|
2614 |
private boolean checkUniqueImport(DiagnosticPosition pos, Symbol sym, Scope s, boolean staticImport) { |
|
2615 |
for (Scope.Entry e = s.lookup(sym.name); e.scope != null; e = e.next()) { |
|
2616 |
// is encountered class entered via a class declaration? |
|
2617 |
boolean isClassDecl = e.scope == s; |
|
2618 |
if ((isClassDecl || sym != e.sym) && |
|
2619 |
sym.kind == e.sym.kind && |
|
2620 |
sym.name != names.error) { |
|
2621 |
if (!e.sym.type.isErroneous()) { |
|
2622 |
String what = e.sym.toString(); |
|
2623 |
if (!isClassDecl) { |
|
2624 |
if (staticImport) |
|
2625 |
log.error(pos, "already.defined.static.single.import", what); |
|
2626 |
else |
|
2627 |
log.error(pos, "already.defined.single.import", what); |
|
2628 |
} |
|
2629 |
else if (sym != e.sym) |
|
2630 |
log.error(pos, "already.defined.this.unit", what); |
|
2631 |
} |
|
2632 |
return false; |
|
2633 |
} |
|
2634 |
} |
|
2635 |
return true; |
|
2636 |
} |
|
2637 |
||
2638 |
/** Check that a qualified name is in canonical form (for import decls). |
|
2639 |
*/ |
|
2640 |
public void checkCanonical(JCTree tree) { |
|
2641 |
if (!isCanonical(tree)) |
|
2642 |
log.error(tree.pos(), "import.requires.canonical", |
|
2643 |
TreeInfo.symbol(tree)); |
|
2644 |
} |
|
2645 |
// where |
|
2646 |
private boolean isCanonical(JCTree tree) { |
|
2647 |
while (tree.getTag() == JCTree.SELECT) { |
|
2648 |
JCFieldAccess s = (JCFieldAccess) tree; |
|
2649 |
if (s.sym.owner != TreeInfo.symbol(s.selected)) |
|
2650 |
return false; |
|
2651 |
tree = s.selected; |
|
2652 |
} |
|
2653 |
return true; |
|
2654 |
} |
|
2655 |
||
2656 |
private class ConversionWarner extends Warner { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2657 |
final String uncheckedKey; |
10 | 2658 |
final Type found; |
2659 |
final Type expected; |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2660 |
public ConversionWarner(DiagnosticPosition pos, String uncheckedKey, Type found, Type expected) { |
10 | 2661 |
super(pos); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2662 |
this.uncheckedKey = uncheckedKey; |
10 | 2663 |
this.found = found; |
2664 |
this.expected = expected; |
|
2665 |
} |
|
2666 |
||
3780
368edd3d2082
6874249: Check has duplicate local variable and field for "source"
jjg
parents:
3765
diff
changeset
|
2667 |
@Override |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2668 |
public void warn(LintCategory lint) { |
10 | 2669 |
boolean warned = this.warned; |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2670 |
super.warn(lint); |
10 | 2671 |
if (warned) return; // suppress redundant diagnostics |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2672 |
switch (lint) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2673 |
case UNCHECKED: |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2674 |
Check.this.warnUnchecked(pos(), "prob.found.req", diags.fragment(uncheckedKey), found, expected); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2675 |
break; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2676 |
case VARARGS: |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2677 |
if (method != null && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2678 |
method.attribute(syms.trustMeType.tsym) != null && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2679 |
isTrustMeAllowedOnMethod(method) && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2680 |
!types.isReifiable(method.type.getParameterTypes().last())) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2681 |
Check.this.warnUnsafeVararg(pos(), "varargs.unsafe.use.varargs.param", method.params.last()); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2682 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2683 |
break; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2684 |
default: |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2685 |
throw new AssertionError("Unexpected lint: " + lint); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7628
diff
changeset
|
2686 |
} |
10 | 2687 |
} |
2688 |
} |
|
2689 |
||
2690 |
public Warner castWarner(DiagnosticPosition pos, Type found, Type expected) { |
|
2691 |
return new ConversionWarner(pos, "unchecked.cast.to.type", found, expected); |
|
2692 |
} |
|
2693 |
||
2694 |
public Warner convertWarner(DiagnosticPosition pos, Type found, Type expected) { |
|
2695 |
return new ConversionWarner(pos, "unchecked.assign", found, expected); |
|
2696 |
} |
|
2697 |
} |