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