src/share/classes/com/sun/tools/javac/comp/Attr.java

changeset 267
e2722bd43f3a
parent 229
03bcd66bd8e7
child 303
8ec37cf2b37e
equal deleted inserted replaced
263:825f23a4f262 267:e2722bd43f3a
116 allowCovariantReturns = source.allowCovariantReturns(); 116 allowCovariantReturns = source.allowCovariantReturns();
117 allowAnonOuterThis = source.allowAnonOuterThis(); 117 allowAnonOuterThis = source.allowAnonOuterThis();
118 relax = (options.get("-retrofit") != null || 118 relax = (options.get("-retrofit") != null ||
119 options.get("-relax") != null); 119 options.get("-relax") != null);
120 useBeforeDeclarationWarning = options.get("useBeforeDeclarationWarning") != null; 120 useBeforeDeclarationWarning = options.get("useBeforeDeclarationWarning") != null;
121 allowInvokedynamic = options.get("invokedynamic") != null;
121 } 122 }
122 123
123 /** Switch: relax some constraints for retrofit mode. 124 /** Switch: relax some constraints for retrofit mode.
124 */ 125 */
125 boolean relax; 126 boolean relax;
146 147
147 /** Switch: allow references to surrounding object from anonymous 148 /** Switch: allow references to surrounding object from anonymous
148 * objects during constructor call? 149 * objects during constructor call?
149 */ 150 */
150 boolean allowAnonOuterThis; 151 boolean allowAnonOuterThis;
152
153 /** Switch: allow invokedynamic syntax
154 */
155 boolean allowInvokedynamic;
151 156
152 /** 157 /**
153 * Switch: warn about use of variable before declaration? 158 * Switch: warn about use of variable before declaration?
154 * RFE: 6425594 159 * RFE: 6425594
155 */ 160 */
436 l.head.pos(), types.upperBound(attribTree(l.head, env, VAL, Infer.anyPoly)))); 441 l.head.pos(), types.upperBound(attribTree(l.head, env, VAL, Infer.anyPoly))));
437 return argtypes.toList(); 442 return argtypes.toList();
438 } 443 }
439 444
440 /** Attribute a type argument list, returning a list of types. 445 /** Attribute a type argument list, returning a list of types.
441 */ 446 * Caller is responsible for calling checkRefTypes.
442 List<Type> attribTypes(List<JCExpression> trees, Env<AttrContext> env) { 447 */
448 List<Type> attribAnyTypes(List<JCExpression> trees, Env<AttrContext> env) {
443 ListBuffer<Type> argtypes = new ListBuffer<Type>(); 449 ListBuffer<Type> argtypes = new ListBuffer<Type>();
444 for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail) 450 for (List<JCExpression> l = trees; l.nonEmpty(); l = l.tail)
445 argtypes.append(chk.checkRefType(l.head.pos(), attribType(l.head, env))); 451 argtypes.append(attribType(l.head, env));
446 return argtypes.toList(); 452 return argtypes.toList();
447 } 453 }
448 454
455 /** Attribute a type argument list, returning a list of types.
456 * Check that all the types are references.
457 */
458 List<Type> attribTypes(List<JCExpression> trees, Env<AttrContext> env) {
459 List<Type> types = attribAnyTypes(trees, env);
460 return chk.checkRefTypes(trees, types);
461 }
449 462
450 /** 463 /**
451 * Attribute type variables (of generic classes or methods). 464 * Attribute type variables (of generic classes or methods).
452 * Compound types are attributed later in attribBounds. 465 * Compound types are attributed later in attribBounds.
453 * @param typarams the type variables to enter 466 * @param typarams the type variables to enter
1192 // The types of the actual method arguments. 1205 // The types of the actual method arguments.
1193 List<Type> argtypes; 1206 List<Type> argtypes;
1194 1207
1195 // The types of the actual method type arguments. 1208 // The types of the actual method type arguments.
1196 List<Type> typeargtypes = null; 1209 List<Type> typeargtypes = null;
1210 boolean typeargtypesNonRefOK = false;
1197 1211
1198 Name methName = TreeInfo.name(tree.meth); 1212 Name methName = TreeInfo.name(tree.meth);
1199 1213
1200 boolean isConstructorCall = 1214 boolean isConstructorCall =
1201 methName == names._this || methName == names._super; 1215 methName == names._this || methName == names._super;
1279 result = tree.type = syms.voidType; 1293 result = tree.type = syms.voidType;
1280 } else { 1294 } else {
1281 // Otherwise, we are seeing a regular method call. 1295 // Otherwise, we are seeing a regular method call.
1282 // Attribute the arguments, yielding list of argument types, ... 1296 // Attribute the arguments, yielding list of argument types, ...
1283 argtypes = attribArgs(tree.args, localEnv); 1297 argtypes = attribArgs(tree.args, localEnv);
1284 typeargtypes = attribTypes(tree.typeargs, localEnv); 1298 typeargtypes = attribAnyTypes(tree.typeargs, localEnv);
1285 1299
1286 // ... and attribute the method using as a prototype a methodtype 1300 // ... and attribute the method using as a prototype a methodtype
1287 // whose formal argument types is exactly the list of actual 1301 // whose formal argument types is exactly the list of actual
1288 // arguments (this will also set the method symbol). 1302 // arguments (this will also set the method symbol).
1289 Type mpt = newMethTemplate(argtypes, typeargtypes); 1303 Type mpt = newMethTemplate(argtypes, typeargtypes);
1314 ClassType(restype.getEnclosingType(), 1328 ClassType(restype.getEnclosingType(),
1315 List.<Type>of(new WildcardType(types.erasure(qualifier), 1329 List.<Type>of(new WildcardType(types.erasure(qualifier),
1316 BoundKind.EXTENDS, 1330 BoundKind.EXTENDS,
1317 syms.boundClass)), 1331 syms.boundClass)),
1318 restype.tsym); 1332 restype.tsym);
1333 }
1334
1335 // as a special case, MethodHandle.<T>invoke(abc) and InvokeDynamic.<T>foo(abc)
1336 // has type <T>, and T can be a primitive type.
1337 if (tree.meth.getTag() == JCTree.SELECT && !typeargtypes.isEmpty()) {
1338 Type selt = ((JCFieldAccess) tree.meth).selected.type;
1339 if ((selt == syms.methodHandleType && methName == names.invoke) || selt == syms.invokeDynamicType) {
1340 assert types.isSameType(restype, typeargtypes.head) : mtype;
1341 typeargtypesNonRefOK = true;
1342 }
1343 }
1344
1345 if (!typeargtypesNonRefOK) {
1346 chk.checkRefTypes(tree.typeargs, typeargtypes);
1319 } 1347 }
1320 1348
1321 // Check that value of resulting type is admissible in the 1349 // Check that value of resulting type is admissible in the
1322 // current context. Also, capture the return type 1350 // current context. Also, capture the return type
1323 result = check(tree, capture(restype), VAL, pkind, pt); 1351 result = check(tree, capture(restype), VAL, pkind, pt);

mercurial