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

changeset 562
2881b376a689
parent 550
a6f2911a7c55
child 567
593a59e40bdb
equal deleted inserted replaced
561:e9ef849ae0ed 562:2881b376a689
1470 } 1470 }
1471 1471
1472 // Attribute clazz expression and store 1472 // Attribute clazz expression and store
1473 // symbol + type back into the attributed tree. 1473 // symbol + type back into the attributed tree.
1474 Type clazztype = attribType(clazz, env); 1474 Type clazztype = attribType(clazz, env);
1475 Pair<Scope,Scope> mapping = getSyntheticScopeMapping((ClassType)clazztype); 1475 Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype);
1476 if (!TreeInfo.isDiamond(tree)) { 1476 if (!TreeInfo.isDiamond(tree)) {
1477 clazztype = chk.checkClassType( 1477 clazztype = chk.checkClassType(
1478 tree.clazz.pos(), clazztype, true); 1478 tree.clazz.pos(), clazztype, true);
1479 } 1479 }
1480 chk.validate(clazz, localEnv); 1480 chk.validate(clazz, localEnv);
1638 Type clazztype, 1638 Type clazztype,
1639 Pair<Scope, Scope> mapping, 1639 Pair<Scope, Scope> mapping,
1640 List<Type> argtypes, 1640 List<Type> argtypes,
1641 List<Type> typeargtypes, 1641 List<Type> typeargtypes,
1642 boolean reportErrors) { 1642 boolean reportErrors) {
1643 if (clazztype.isErroneous()) { 1643 if (clazztype.isErroneous() || mapping == erroneousMapping) {
1644 //if the type of the instance creation expression is erroneous 1644 //if the type of the instance creation expression is erroneous,
1645 //return the erroneous type itself 1645 //or something prevented us to form a valid mapping, return the
1646 //(possibly erroneous) type unchanged
1646 return clazztype; 1647 return clazztype;
1647 } 1648 }
1648 else if (clazztype.isInterface()) { 1649 else if (clazztype.isInterface()) {
1649 //if the type of the instance creation expression is an interface 1650 //if the type of the instance creation expression is an interface
1650 //skip the method resolution step (JLS 15.12.2.7). The type to be 1651 //skip the method resolution step (JLS 15.12.2.7). The type to be
1738 * the synthetic scope is added a generic constructor of the kind: 1739 * the synthetic scope is added a generic constructor of the kind:
1739 * <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond 1740 * <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond
1740 * inference. The inferred return type of the synthetic constructor IS 1741 * inference. The inferred return type of the synthetic constructor IS
1741 * the inferred type for the diamond operator. 1742 * the inferred type for the diamond operator.
1742 */ 1743 */
1743 private Pair<Scope, Scope> getSyntheticScopeMapping(ClassType ctype) { 1744 private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) {
1745 if (ctype.tag != CLASS) {
1746 return erroneousMapping;
1747 }
1744 Pair<Scope, Scope> mapping = 1748 Pair<Scope, Scope> mapping =
1745 new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym)); 1749 new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));
1746 List<Type> typevars = ctype.tsym.type.getTypeArguments(); 1750 List<Type> typevars = ctype.tsym.type.getTypeArguments();
1747 for (Scope.Entry e = mapping.fst.lookup(names.init); 1751 for (Scope.Entry e = mapping.fst.lookup(names.init);
1748 e.scope != null; 1752 e.scope != null;
1760 newConstr.type = new ForAll(typevars.prependList(oldTypeargs), newConstr.type); 1764 newConstr.type = new ForAll(typevars.prependList(oldTypeargs), newConstr.type);
1761 mapping.snd.enter(newConstr); 1765 mapping.snd.enter(newConstr);
1762 } 1766 }
1763 return mapping; 1767 return mapping;
1764 } 1768 }
1769
1770 private final Pair<Scope,Scope> erroneousMapping = new Pair<Scope,Scope>(null, null);
1765 1771
1766 /** Make an attributed null check tree. 1772 /** Make an attributed null check tree.
1767 */ 1773 */
1768 public JCExpression makeNullCheck(JCExpression arg) { 1774 public JCExpression makeNullCheck(JCExpression arg) {
1769 // optimization: X.this is never null; skip null check 1775 // optimization: X.this is never null; skip null check

mercurial