25 |
25 |
26 package com.sun.tools.javac.comp; |
26 package com.sun.tools.javac.comp; |
27 |
27 |
28 import com.sun.tools.javac.tree.JCTree; |
28 import com.sun.tools.javac.tree.JCTree; |
29 import com.sun.tools.javac.tree.JCTree.JCTypeCast; |
29 import com.sun.tools.javac.tree.JCTree.JCTypeCast; |
|
30 import com.sun.tools.javac.tree.TreeInfo; |
30 import com.sun.tools.javac.util.*; |
31 import com.sun.tools.javac.util.*; |
31 import com.sun.tools.javac.util.List; |
32 import com.sun.tools.javac.util.List; |
32 import com.sun.tools.javac.code.*; |
33 import com.sun.tools.javac.code.*; |
33 import com.sun.tools.javac.code.Type.*; |
34 import com.sun.tools.javac.code.Type.*; |
34 import com.sun.tools.javac.code.Type.ForAll.ConstraintKind; |
35 import com.sun.tools.javac.code.Type.ForAll.ConstraintKind; |
536 } |
537 } |
537 } |
538 } |
538 |
539 |
539 /** |
540 /** |
540 * Compute a synthetic method type corresponding to the requested polymorphic |
541 * Compute a synthetic method type corresponding to the requested polymorphic |
541 * method signature. If no explicit return type is supplied, a provisional |
542 * method signature. The target return type is computed from the immediately |
542 * return type is computed (just Object in case of non-transitional 292) |
543 * enclosing scope surrounding the polymorphic-signature call. |
543 */ |
544 */ |
544 Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site, |
545 Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site, |
545 Name name, |
546 Name name, |
546 MethodSymbol spMethod, // sig. poly. method or null if none |
547 MethodSymbol spMethod, // sig. poly. method or null if none |
547 List<Type> argtypes, |
548 List<Type> argtypes) { |
548 List<Type> typeargtypes) { |
|
549 final Type restype; |
549 final Type restype; |
550 if (rs.allowTransitionalJSR292 && typeargtypes.nonEmpty()) { |
550 |
551 restype = typeargtypes.head; |
551 //The return type for a polymorphic signature call is computed from |
552 } else { |
552 //the enclosing tree E, as follows: if E is a cast, then use the |
553 //The return type for a polymorphic signature call is computed from |
553 //target type of the cast expression as a return type; if E is an |
554 //the enclosing tree E, as follows: if E is a cast, then use the |
554 //expression statement, the return type is 'void' - otherwise the |
555 //target type of the cast expression as a return type; if E is an |
555 //return type is simply 'Object'. A correctness check ensures that |
556 //expression statement, the return type is 'void' - otherwise the |
556 //env.next refers to the lexically enclosing environment in which |
557 //return type is simply 'Object'. A correctness check ensures that |
557 //the polymorphic signature call environment is nested. |
558 //env.next refers to the lexically enclosing environment in which |
558 |
559 //the polymorphic signature call environment is nested. |
559 switch (env.next.tree.getTag()) { |
560 |
560 case JCTree.TYPECAST: |
561 switch (env.next.tree.getTag()) { |
561 JCTypeCast castTree = (JCTypeCast)env.next.tree; |
562 case JCTree.TYPECAST: |
562 restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ? |
563 JCTypeCast castTree = (JCTypeCast)env.next.tree; |
563 castTree.clazz.type : |
564 restype = (castTree.expr == env.tree) ? |
564 syms.objectType; |
565 castTree.clazz.type : |
565 break; |
566 syms.objectType; |
566 case JCTree.EXEC: |
567 break; |
567 JCTree.JCExpressionStatement execTree = |
568 case JCTree.EXEC: |
568 (JCTree.JCExpressionStatement)env.next.tree; |
569 JCTree.JCExpressionStatement execTree = |
569 restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ? |
570 (JCTree.JCExpressionStatement)env.next.tree; |
570 syms.voidType : |
571 restype = (execTree.expr == env.tree) ? |
571 syms.objectType; |
572 syms.voidType : |
572 break; |
573 syms.objectType; |
573 default: |
574 break; |
574 restype = syms.objectType; |
575 default: |
|
576 restype = syms.objectType; |
|
577 } |
|
578 } |
575 } |
579 |
576 |
580 List<Type> paramtypes = Type.map(argtypes, implicitArgType); |
577 List<Type> paramtypes = Type.map(argtypes, implicitArgType); |
581 List<Type> exType = spMethod != null ? |
578 List<Type> exType = spMethod != null ? |
582 spMethod.getThrownTypes() : |
579 spMethod.getThrownTypes() : |