author | jlahoda |
Tue, 20 Jan 2015 12:00:25 +0100 | |
changeset 28590 | 9069a3bf5900 |
parent 27857 | 7e913a535736 |
child 29842 | 826ac2519523 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, 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 javax.tools.JavaFileObject; |
|
29 |
||
30 |
import com.sun.tools.javac.code.*; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
31 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
10 | 32 |
import com.sun.tools.javac.tree.*; |
33 |
import com.sun.tools.javac.util.*; |
|
27857 | 34 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
10 | 35 |
|
24895
dd091d389fbf
8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents:
24604
diff
changeset
|
36 |
import com.sun.tools.javac.code.Symbol.*; |
10 | 37 |
import com.sun.tools.javac.code.Type.*; |
38 |
import com.sun.tools.javac.tree.JCTree.*; |
|
39 |
||
40 |
import static com.sun.tools.javac.code.Flags.*; |
|
41 |
import static com.sun.tools.javac.code.Kinds.*; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
42 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
43 |
import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24396
diff
changeset
|
44 |
|
27857 | 45 |
/** Resolves field, method and constructor header, and constructs corresponding Symbols. |
10 | 46 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
47 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
48 |
* If you write code that depends on this, you do so at your own risk. |
10 | 49 |
* This code and its internal interfaces are subject to change or |
50 |
* deletion without notice.</b> |
|
51 |
*/ |
|
27857 | 52 |
public class MemberEnter extends JCTree.Visitor { |
22163 | 53 |
protected static final Context.Key<MemberEnter> memberEnterKey = new Context.Key<>(); |
10 | 54 |
|
55 |
/** A switch to determine whether we check for package/class conflicts |
|
56 |
*/ |
|
57 |
final static boolean checkClash = true; |
|
58 |
||
59 |
private final Enter enter; |
|
60 |
private final Log log; |
|
61 |
private final Check chk; |
|
62 |
private final Attr attr; |
|
63 |
private final Symtab syms; |
|
64 |
private final Annotate annotate; |
|
65 |
private final Types types; |
|
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
66 |
private final DeferredLintHandler deferredLintHandler; |
10 | 67 |
|
68 |
public static MemberEnter instance(Context context) { |
|
69 |
MemberEnter instance = context.get(memberEnterKey); |
|
70 |
if (instance == null) |
|
71 |
instance = new MemberEnter(context); |
|
72 |
return instance; |
|
73 |
} |
|
74 |
||
75 |
protected MemberEnter(Context context) { |
|
76 |
context.put(memberEnterKey, this); |
|
77 |
enter = Enter.instance(context); |
|
78 |
log = Log.instance(context); |
|
79 |
chk = Check.instance(context); |
|
80 |
attr = Attr.instance(context); |
|
81 |
syms = Symtab.instance(context); |
|
82 |
annotate = Annotate.instance(context); |
|
83 |
types = Types.instance(context); |
|
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
84 |
deferredLintHandler = DeferredLintHandler.instance(context); |
10 | 85 |
} |
86 |
||
87 |
/** Construct method type from method signature. |
|
88 |
* @param typarams The method's type parameters. |
|
89 |
* @param params The method's value parameters. |
|
90 |
* @param res The method's result type, |
|
91 |
* null if it is a constructor. |
|
15385 | 92 |
* @param recvparam The method's receiver parameter, |
93 |
* null if none given; TODO: or already set here? |
|
10 | 94 |
* @param thrown The method's thrown exceptions. |
95 |
* @param env The method's (local) environment. |
|
96 |
*/ |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
97 |
Type signature(MethodSymbol msym, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
98 |
List<JCTypeParameter> typarams, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
99 |
List<JCVariableDecl> params, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
100 |
JCTree res, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
101 |
JCVariableDecl recvparam, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
102 |
List<JCExpression> thrown, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
103 |
Env<AttrContext> env) { |
10 | 104 |
|
105 |
// Enter and attribute type parameters. |
|
106 |
List<Type> tvars = enter.classEnter(typarams, env); |
|
107 |
attr.attribTypeVariables(typarams, env); |
|
108 |
||
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
109 |
// Enter and attribute value parameters. |
22163 | 110 |
ListBuffer<Type> argbuf = new ListBuffer<>(); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
111 |
for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) { |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
112 |
memberEnter(l.head, env); |
10 | 113 |
argbuf.append(l.head.vartype.type); |
114 |
} |
|
115 |
||
116 |
// Attribute result type, if one is given. |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
117 |
Type restype = res == null ? syms.voidType : attr.attribType(res, env); |
10 | 118 |
|
15385 | 119 |
// Attribute receiver type, if one is given. |
120 |
Type recvtype; |
|
121 |
if (recvparam!=null) { |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
122 |
memberEnter(recvparam, env); |
15385 | 123 |
recvtype = recvparam.vartype.type; |
124 |
} else { |
|
125 |
recvtype = null; |
|
126 |
} |
|
127 |
||
10 | 128 |
// Attribute thrown exceptions. |
22163 | 129 |
ListBuffer<Type> thrownbuf = new ListBuffer<>(); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
130 |
for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail) { |
10 | 131 |
Type exc = attr.attribType(l.head, env); |
18909
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
132 |
if (!exc.hasTag(TYPEVAR)) { |
10 | 133 |
exc = chk.checkClassType(l.head.pos(), exc); |
18909
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
134 |
} else if (exc.tsym.owner == msym) { |
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
135 |
//mark inference variables in 'throws' clause |
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
136 |
exc.tsym.flags_field |= THROWS; |
8f9fc5d876e4
8012242: Lambda compatibility and checked exceptions
mcimadamore
parents:
18643
diff
changeset
|
137 |
} |
10 | 138 |
thrownbuf.append(exc); |
139 |
} |
|
15385 | 140 |
MethodType mtype = new MethodType(argbuf.toList(), |
10 | 141 |
restype, |
142 |
thrownbuf.toList(), |
|
143 |
syms.methodClass); |
|
15385 | 144 |
mtype.recvtype = recvtype; |
145 |
||
10 | 146 |
return tvars.isEmpty() ? mtype : new ForAll(tvars, mtype); |
147 |
} |
|
148 |
||
149 |
/* ******************************************************************** |
|
150 |
* Visitor methods for member enter |
|
151 |
*********************************************************************/ |
|
152 |
||
153 |
/** Visitor argument: the current environment |
|
154 |
*/ |
|
155 |
protected Env<AttrContext> env; |
|
156 |
||
157 |
/** Enter field and method definitions and process import |
|
158 |
* clauses, catching any completion failure exceptions. |
|
159 |
*/ |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
160 |
protected void memberEnter(JCTree tree, Env<AttrContext> env) { |
10 | 161 |
Env<AttrContext> prevEnv = this.env; |
162 |
try { |
|
163 |
this.env = env; |
|
164 |
tree.accept(this); |
|
165 |
} catch (CompletionFailure ex) { |
|
166 |
chk.completionError(tree.pos(), ex); |
|
167 |
} finally { |
|
168 |
this.env = prevEnv; |
|
169 |
} |
|
170 |
} |
|
171 |
||
172 |
/** Enter members from a list of trees. |
|
173 |
*/ |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
174 |
void memberEnter(List<? extends JCTree> trees, Env<AttrContext> env) { |
10 | 175 |
for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
176 |
memberEnter(l.head, env); |
10 | 177 |
} |
178 |
||
179 |
public void visitMethodDef(JCMethodDecl tree) { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
180 |
WriteableScope enclScope = enter.enterScope(env); |
10 | 181 |
MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner); |
182 |
m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree); |
|
183 |
tree.sym = m; |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
184 |
|
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
185 |
//if this is a default method, add the DEFAULT flag to the enclosing interface |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
186 |
if ((tree.mods.flags & DEFAULT) != 0) { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
187 |
m.enclClass().flags_field |= DEFAULT; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
188 |
} |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
189 |
|
10 | 190 |
Env<AttrContext> localEnv = methodEnv(tree, env); |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
191 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
192 |
try { |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
193 |
// Compute the method type |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
194 |
m.type = signature(m, tree.typarams, tree.params, |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
195 |
tree.restype, tree.recvparam, |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
196 |
tree.thrown, |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
197 |
localEnv); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
198 |
} finally { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
199 |
deferredLintHandler.setPos(prevLintPos); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
200 |
} |
10 | 201 |
|
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
202 |
if (types.isSignaturePolymorphic(m)) { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
203 |
m.flags_field |= SIGNATURE_POLYMORPHIC; |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
204 |
} |
18389
a425d0819f36
8016569: javac, add new flag for polymorphic method signatures
vromero
parents:
18010
diff
changeset
|
205 |
|
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
206 |
// Set m.params |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
207 |
ListBuffer<VarSymbol> params = new ListBuffer<>(); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
208 |
JCVariableDecl lastParam = null; |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
209 |
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
210 |
JCVariableDecl param = lastParam = l.head; |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
211 |
params.append(Assert.checkNonNull(param.sym)); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
212 |
} |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
213 |
m.params = params.toList(); |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
214 |
|
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
215 |
// mark the method varargs, if necessary |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
216 |
if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
217 |
m.flags_field |= Flags.VARARGS; |
10 | 218 |
|
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
219 |
localEnv.info.scope.leave(); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
220 |
if (chk.checkUnique(tree.pos(), m, enclScope)) { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
221 |
enclScope.enter(m); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
222 |
} |
10 | 223 |
|
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
224 |
annotate.annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
225 |
// Visit the signature of the method. Note that |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
226 |
// TypeAnnotate doesn't descend into the body. |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
227 |
annotate.annotateTypeLater(tree, localEnv, m, tree.pos()); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
228 |
|
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
229 |
if (tree.defaultValue != null) |
28590
9069a3bf5900
8069094: SuppressWarnings(\"deprecation\") not respected on default clause on annotation declarations
jlahoda
parents:
27857
diff
changeset
|
230 |
annotateDefaultValueLater(tree.defaultValue, localEnv, m, tree.pos()); |
10 | 231 |
} |
232 |
||
233 |
/** Create a fresh environment for method bodies. |
|
234 |
* @param tree The method definition. |
|
235 |
* @param env The environment current outside of the method definition. |
|
236 |
*/ |
|
237 |
Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) { |
|
238 |
Env<AttrContext> localEnv = |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
239 |
env.dup(tree, env.info.dup(env.info.scope.dupUnshared(tree.sym))); |
10 | 240 |
localEnv.enclMethod = tree; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
241 |
if (tree.sym.type != null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
242 |
//when this is called in the enter stage, there's no type to be set |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
243 |
localEnv.info.returnResult = attr.new ResultInfo(KindSelector.VAL, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
244 |
tree.sym.type.getReturnType()); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14051
diff
changeset
|
245 |
} |
10 | 246 |
if ((tree.mods.flags & STATIC) != 0) localEnv.info.staticLevel++; |
247 |
return localEnv; |
|
248 |
} |
|
249 |
||
250 |
public void visitVarDef(JCVariableDecl tree) { |
|
251 |
Env<AttrContext> localEnv = env; |
|
252 |
if ((tree.mods.flags & STATIC) != 0 || |
|
253 |
(env.info.scope.owner.flags() & INTERFACE) != 0) { |
|
254 |
localEnv = env.dup(tree, env.info.dup()); |
|
255 |
localEnv.info.staticLevel++; |
|
256 |
} |
|
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
257 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); |
8236
0d8646b7c602
6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
8225
diff
changeset
|
258 |
try { |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
259 |
if (TreeInfo.isEnumInit(tree)) { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
260 |
attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
261 |
} else { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
262 |
attr.attribType(tree.vartype, localEnv); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
263 |
if (TreeInfo.isReceiverParam(tree)) |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
264 |
checkReceiver(tree, localEnv); |
21498
58c2486db8d0
8006732: support correct bytecode storage of type annotations in multicatch
emc
parents:
21040
diff
changeset
|
265 |
} |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
266 |
} finally { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
267 |
deferredLintHandler.setPos(prevLintPos); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
268 |
} |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
269 |
|
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
270 |
if ((tree.mods.flags & VARARGS) != 0) { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
271 |
//if we are entering a varargs parameter, we need to |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
272 |
//replace its type (a plain array type) with the more |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
273 |
//precise VarargsType --- we need to do it this way |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
274 |
//because varargs is represented in the tree as a |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
275 |
//modifier on the parameter declaration, and not as a |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
276 |
//distinct type of array node. |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
277 |
ArrayType atype = (ArrayType)tree.vartype.type; |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
278 |
tree.vartype.type = atype.makeVarargs(); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
279 |
} |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
280 |
WriteableScope enclScope = enter.enterScope(env); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
281 |
VarSymbol v = |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
282 |
new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
283 |
v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
284 |
tree.sym = v; |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
285 |
if (tree.init != null) { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
286 |
v.flags_field |= HASINIT; |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
287 |
if ((v.flags_field & FINAL) != 0 && |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
288 |
needsLazyConstValue(tree.init)) { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
289 |
Env<AttrContext> initEnv = getInitEnv(tree, env); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
290 |
initEnv.info.enclVar = v; |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
291 |
v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); |
12916
021c069e8e27
7160084: javac fails to compile an apparently valid class/interface combination
mcimadamore
parents:
12335
diff
changeset
|
292 |
} |
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
293 |
} |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
294 |
if (chk.checkUnique(tree.pos(), v, enclScope)) { |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
295 |
chk.checkTransparentVar(tree.pos(), v, enclScope); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
296 |
enclScope.enter(v); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
297 |
} |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
298 |
|
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
299 |
annotate.annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); |
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
300 |
annotate.annotateTypeLater(tree.vartype, localEnv, v, tree.pos()); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26266
diff
changeset
|
301 |
|
27231
c1ca668b421e
8054448: (ann) Cannot reference field of inner class in an anonymous class
jfranck
parents:
27224
diff
changeset
|
302 |
v.pos = tree.pos; |
10 | 303 |
} |
17578 | 304 |
// where |
305 |
void checkType(JCTree tree, Type type, String diag) { |
|
306 |
if (!tree.type.isErroneous() && !types.isSameType(tree.type, type)) { |
|
307 |
log.error(tree, diag, type, tree.type); |
|
308 |
} |
|
309 |
} |
|
24903
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
310 |
void checkReceiver(JCVariableDecl tree, Env<AttrContext> localEnv) { |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
311 |
attr.attribExpr(tree.nameexpr, localEnv); |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
312 |
MethodSymbol m = localEnv.enclMethod.sym; |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
313 |
if (m.isConstructor()) { |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
314 |
Type outertype = m.owner.owner.type; |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
315 |
if (outertype.hasTag(TypeTag.METHOD)) { |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
316 |
// we have a local inner class |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
317 |
outertype = m.owner.owner.owner.type; |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
318 |
} |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
319 |
if (outertype.hasTag(TypeTag.CLASS)) { |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
320 |
checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
321 |
checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
322 |
} else { |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
323 |
log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
324 |
} |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
325 |
} else { |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
326 |
checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
327 |
checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
328 |
} |
41e1812d6b4c
8027886: javac allows illegal receiver parameters
pgovereau
parents:
24895
diff
changeset
|
329 |
} |
10 | 330 |
|
19656
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
331 |
public boolean needsLazyConstValue(JCTree tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
332 |
InitTreeVisitor initTreeVisitor = new InitTreeVisitor(); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
333 |
tree.accept(initTreeVisitor); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
334 |
return initTreeVisitor.result; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
335 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
336 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
337 |
/** Visitor class for expressions which might be constant expressions. |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
338 |
*/ |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
339 |
static class InitTreeVisitor extends JCTree.Visitor { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
340 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
341 |
private boolean result = true; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
342 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
343 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
344 |
public void visitTree(JCTree tree) {} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
345 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
346 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
347 |
public void visitNewClass(JCNewClass that) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
348 |
result = false; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
349 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
350 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
351 |
@Override |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
352 |
public void visitNewArray(JCNewArray that) { |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
353 |
result = false; |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
354 |
} |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
355 |
|
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
356 |
@Override |
19656
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
357 |
public void visitLambda(JCLambda that) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
358 |
result = false; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
359 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
360 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
361 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
362 |
public void visitReference(JCMemberReference that) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
363 |
result = false; |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
364 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
365 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
366 |
@Override |
19942
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
367 |
public void visitApply(JCMethodInvocation that) { |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
368 |
result = false; |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
369 |
} |
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
370 |
|
e9dae0e41075
8021112: Spurious unchecked warning reported by javac
jlahoda
parents:
19941
diff
changeset
|
371 |
@Override |
19656
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
372 |
public void visitSelect(JCFieldAccess tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
373 |
tree.selected.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
374 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
375 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
376 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
377 |
public void visitConditional(JCConditional tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
378 |
tree.cond.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
379 |
tree.truepart.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
380 |
tree.falsepart.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
381 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
382 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
383 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
384 |
public void visitParens(JCParens tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
385 |
tree.expr.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
386 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
387 |
|
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
388 |
@Override |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
389 |
public void visitTypeCast(JCTypeCast tree) { |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
390 |
tree.expr.accept(this); |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
391 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
392 |
} |
7f0afbdbf142
8023112: javac should not use lazy constant evaluation approach for method references
vromero
parents:
19651
diff
changeset
|
393 |
|
10 | 394 |
/** Create a fresh environment for a variable's initializer. |
395 |
* If the variable is a field, the owner of the environment's scope |
|
396 |
* is be the variable itself, otherwise the owner is the method |
|
397 |
* enclosing the variable definition. |
|
398 |
* |
|
399 |
* @param tree The variable definition. |
|
400 |
* @param env The environment current outside of the variable definition. |
|
401 |
*/ |
|
402 |
Env<AttrContext> initEnv(JCVariableDecl tree, Env<AttrContext> env) { |
|
403 |
Env<AttrContext> localEnv = env.dupto(new AttrContextEnv(tree, env.info.dup())); |
|
404 |
if (tree.sym.owner.kind == TYP) { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25007
diff
changeset
|
405 |
localEnv.info.scope = env.info.scope.dupUnshared(tree.sym); |
10 | 406 |
} |
407 |
if ((tree.mods.flags & STATIC) != 0 || |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14369
diff
changeset
|
408 |
((env.enclClass.sym.flags() & INTERFACE) != 0 && env.enclMethod == null)) |
10 | 409 |
localEnv.info.staticLevel++; |
410 |
return localEnv; |
|
411 |
} |
|
412 |
||
413 |
/** Default member enter visitor method: do nothing |
|
414 |
*/ |
|
415 |
public void visitTree(JCTree tree) { |
|
416 |
} |
|
417 |
||
418 |
public void visitErroneous(JCErroneous tree) { |
|
6929
81a6a7c1bef1
6988407: javac crashes running processor on errant code; it used to print error message
jjg
parents:
6721
diff
changeset
|
419 |
if (tree.errs != null) |
81a6a7c1bef1
6988407: javac crashes running processor on errant code; it used to print error message
jjg
parents:
6721
diff
changeset
|
420 |
memberEnter(tree.errs, env); |
10 | 421 |
} |
422 |
||
423 |
public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) { |
|
424 |
Env<AttrContext> mEnv = methodEnv(tree, env); |
|
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
17999
diff
changeset
|
425 |
mEnv.info.lint = mEnv.info.lint.augment(tree.sym); |
10 | 426 |
for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) |
427 |
mEnv.info.scope.enterIfAbsent(l.head.type.tsym); |
|
428 |
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) |
|
429 |
mEnv.info.scope.enterIfAbsent(l.head.sym); |
|
430 |
return mEnv; |
|
431 |
} |
|
432 |
||
433 |
public Env<AttrContext> getInitEnv(JCVariableDecl tree, Env<AttrContext> env) { |
|
434 |
Env<AttrContext> iEnv = initEnv(tree, env); |
|
435 |
return iEnv; |
|
436 |
} |
|
437 |
||
438 |
/** Queue processing of an attribute default value. */ |
|
439 |
void annotateDefaultValueLater(final JCExpression defaultValue, |
|
440 |
final Env<AttrContext> localEnv, |
|
28590
9069a3bf5900
8069094: SuppressWarnings(\"deprecation\") not respected on default clause on annotation declarations
jlahoda
parents:
27857
diff
changeset
|
441 |
final MethodSymbol m, |
9069a3bf5900
8069094: SuppressWarnings(\"deprecation\") not respected on default clause on annotation declarations
jlahoda
parents:
27857
diff
changeset
|
442 |
final DiagnosticPosition deferPos) { |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
443 |
annotate.normal(new Annotate.Worker() { |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12917
diff
changeset
|
444 |
@Override |
10 | 445 |
public String toString() { |
446 |
return "annotate " + m.owner + "." + |
|
447 |
m + " default " + defaultValue; |
|
448 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12917
diff
changeset
|
449 |
|
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12917
diff
changeset
|
450 |
@Override |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
451 |
public void run() { |
10 | 452 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
28590
9069a3bf5900
8069094: SuppressWarnings(\"deprecation\") not respected on default clause on annotation declarations
jlahoda
parents:
27857
diff
changeset
|
453 |
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(deferPos); |
10 | 454 |
try { |
455 |
enterDefaultValue(defaultValue, localEnv, m); |
|
456 |
} finally { |
|
28590
9069a3bf5900
8069094: SuppressWarnings(\"deprecation\") not respected on default clause on annotation declarations
jlahoda
parents:
27857
diff
changeset
|
457 |
deferredLintHandler.setPos(prevLintPos); |
10 | 458 |
log.useSource(prev); |
459 |
} |
|
460 |
} |
|
461 |
}); |
|
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
462 |
annotate.validate(new Annotate.Worker() { //validate annotations |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
463 |
@Override |
21040
3e32f68d2151
8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents:
21018
diff
changeset
|
464 |
public void run() { |
21018
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
465 |
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
466 |
try { |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
467 |
// if default value is an annotation, check it is a well-formed |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
468 |
// annotation value (e.g. no duplicate values, no missing values, etc.) |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
469 |
chk.validateAnnotationTree(defaultValue); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
470 |
} finally { |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
471 |
log.useSource(prev); |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
472 |
} |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
473 |
} |
95d225149128
8014016: javac is too late detecting invalid annotation usage
jlahoda
parents:
21015
diff
changeset
|
474 |
}); |
10 | 475 |
} |
476 |
||
477 |
/** Enter a default value for an attribute method. */ |
|
478 |
private void enterDefaultValue(final JCExpression defaultValue, |
|
479 |
final Env<AttrContext> localEnv, |
|
480 |
final MethodSymbol m) { |
|
481 |
m.defaultValue = annotate.enterAttributeValue(m.type.getReturnType(), |
|
482 |
defaultValue, |
|
483 |
localEnv); |
|
484 |
} |
|
485 |
||
486 |
} |