1550 } |
1550 } |
1551 |
1551 |
1552 // Attribute clazz expression and store |
1552 // Attribute clazz expression and store |
1553 // symbol + type back into the attributed tree. |
1553 // symbol + type back into the attributed tree. |
1554 Type clazztype = attribType(clazz, env); |
1554 Type clazztype = attribType(clazz, env); |
1555 Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype); |
1555 Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype, cdef != null); |
1556 if (!TreeInfo.isDiamond(tree)) { |
1556 if (!TreeInfo.isDiamond(tree)) { |
1557 clazztype = chk.checkClassType( |
1557 clazztype = chk.checkClassType( |
1558 tree.clazz.pos(), clazztype, true); |
1558 tree.clazz.pos(), clazztype, true); |
1559 } |
1559 } |
1560 chk.validate(clazz, localEnv); |
1560 chk.validate(clazz, localEnv); |
1847 * the synthetic scope is added a generic constructor of the kind: |
1847 * the synthetic scope is added a generic constructor of the kind: |
1848 * <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond |
1848 * <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond |
1849 * inference. The inferred return type of the synthetic constructor IS |
1849 * inference. The inferred return type of the synthetic constructor IS |
1850 * the inferred type for the diamond operator. |
1850 * the inferred type for the diamond operator. |
1851 */ |
1851 */ |
1852 private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) { |
1852 private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype, boolean overrideProtectedAccess) { |
1853 if (ctype.tag != CLASS) { |
1853 if (ctype.tag != CLASS) { |
1854 return erroneousMapping; |
1854 return erroneousMapping; |
1855 } |
1855 } |
1856 Pair<Scope, Scope> mapping = |
1856 Pair<Scope, Scope> mapping = |
1857 new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym)); |
1857 new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym)); |
1858 List<Type> typevars = ctype.tsym.type.getTypeArguments(); |
1858 List<Type> typevars = ctype.tsym.type.getTypeArguments(); |
1859 for (Scope.Entry e = mapping.fst.lookup(names.init); |
1859 for (Scope.Entry e = mapping.fst.lookup(names.init); |
1860 e.scope != null; |
1860 e.scope != null; |
1861 e = e.next()) { |
1861 e = e.next()) { |
1862 MethodSymbol newConstr = (MethodSymbol) e.sym.clone(ctype.tsym); |
1862 MethodSymbol newConstr = (MethodSymbol) e.sym.clone(ctype.tsym); |
|
1863 if (overrideProtectedAccess && (newConstr.flags() & PROTECTED) != 0) { |
|
1864 //make protected constructor public (this is required for |
|
1865 //anonymous inner class creation expressions using diamond) |
|
1866 newConstr.flags_field |= PUBLIC; |
|
1867 newConstr.flags_field &= ~PROTECTED; |
|
1868 } |
1863 newConstr.name = names.init; |
1869 newConstr.name = names.init; |
1864 List<Type> oldTypeargs = List.nil(); |
1870 List<Type> oldTypeargs = List.nil(); |
1865 if (newConstr.type.tag == FORALL) { |
1871 if (newConstr.type.tag == FORALL) { |
1866 oldTypeargs = ((ForAll) newConstr.type).tvars; |
1872 oldTypeargs = ((ForAll) newConstr.type).tvars; |
1867 } |
1873 } |