< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java

Print this page

 173     JCMethodDecl currentMethodDef;
 174 
 175     /** The current method symbol.
 176      */
 177     MethodSymbol currentMethodSym;
 178 
 179     /** The currently enclosing outermost class definition.
 180      */
 181     JCClassDecl outermostClassDef;
 182 
 183     /** The currently enclosing outermost member definition.
 184      */
 185     JCTree outermostMemberDef;
 186 
 187     /** A map from local variable symbols to their translation (as per LambdaToMethod).
 188      * This is required when a capturing local class is created from a lambda (in which
 189      * case the captured symbols should be replaced with the translated lambda symbols).
 190      */
 191     Map<Symbol, Symbol> lambdaTranslationMap = null;
 192 




 193     /** A navigator class for assembling a mapping from local class symbols
 194      *  to class definition trees.
 195      *  There is only one case; all other cases simply traverse down the tree.
 196      */
 197     class ClassMap extends TreeScanner {
 198 
 199         /** All encountered class defs are entered into classdefs table.
 200          */
 201         public void visitClassDef(JCClassDecl tree) {
 202             classdefs.put(tree.sym, tree);
 203             super.visitClassDef(tree);
 204         }
 205     }
 206     ClassMap classMap = new ClassMap();
 207 
 208     /** Map a class symbol to its definition.
 209      *  @param c    The class symbol of which we want to determine the definition.
 210      */
 211     JCClassDecl classDef(ClassSymbol c) {
 212         // First lookup the class in the classdefs table.

 889 
 890     /** Look up a method in a given scope.
 891      */
 892     private MethodSymbol lookupMethod(DiagnosticPosition pos, Name name, Type qual, List<Type> args) {
 893         return rs.resolveInternalMethod(pos, attrEnv, qual, name, args, List.nil());
 894     }
 895 
 896     /** Anon inner classes are used as access constructor tags.
 897      * accessConstructorTag will use an existing anon class if one is available,
 898      * and synthesize a class (with makeEmptyClass) if one is not available.
 899      * However, there is a small possibility that an existing class will not
 900      * be generated as expected if it is inside a conditional with a constant
 901      * expression. If that is found to be the case, create an empty class tree here.
 902      */
 903     private void checkAccessConstructorTags() {
 904         for (List<ClassSymbol> l = accessConstrTags; l.nonEmpty(); l = l.tail) {
 905             ClassSymbol c = l.head;
 906             if (isTranslatedClassAvailable(c))
 907                 continue;
 908             // Create class definition tree.
 909             JCClassDecl cdec = makeEmptyClass(STATIC | SYNTHETIC,
 910                     c.outermostClass(), c.flatname, false);
 911             swapAccessConstructorTag(c, cdec.sym);
 912             translated.append(cdec);
 913         }
 914     }
 915     // where
 916     private boolean isTranslatedClassAvailable(ClassSymbol c) {
 917         for (JCTree tree: translated) {
 918             if (tree.hasTag(CLASSDEF)
 919                     && ((JCClassDecl) tree).sym == c) {
 920                 return true;
 921             }
 922         }
 923         return false;
 924     }
 925 
 926     void swapAccessConstructorTag(ClassSymbol oldCTag, ClassSymbol newCTag) {
 927         for (MethodSymbol methodSymbol : accessConstrs.values()) {
 928             Assert.check(methodSymbol.type.hasTag(METHOD));
 929             MethodType oldMethodType =

1373                 accessConstrs.put(constr, aconstr);
1374                 accessed.append(constr);
1375             }
1376             return aconstr;
1377         } else {
1378             return constr;
1379         }
1380     }
1381 
1382     /** Return an anonymous class nested in this toplevel class.
1383      */
1384     ClassSymbol accessConstructorTag() {
1385         ClassSymbol topClass = currentClass.outermostClass();
1386         ModuleSymbol topModle = topClass.packge().modle;
1387         for (int i = 1; ; i++) {
1388             Name flatname = names.fromString("" + topClass.getQualifiedName() +
1389                                             target.syntheticNameChar() +
1390                                             i);
1391             ClassSymbol ctag = chk.getCompiled(topModle, flatname);
1392             if (ctag == null)
1393                 ctag = makeEmptyClass(STATIC | SYNTHETIC, topClass).sym;
1394             else if (!ctag.isAnonymous())
1395                 continue;
1396             // keep a record of all tags, to verify that all are generated as required
1397             accessConstrTags = accessConstrTags.prepend(ctag);
1398             return ctag;
1399         }
1400     }
1401 
1402     /** Add all required access methods for a private symbol to enclosing class.
1403      *  @param sym       The symbol.
1404      */
1405     void makeAccessible(Symbol sym) {
1406         JCClassDecl cdef = classDef(sym.owner.enclClass());
1407         if (cdef == null) Assert.error("class def not found: " + sym + " in " + sym.owner);
1408         if (sym.name == names.init) {
1409             cdef.defs = cdef.defs.prepend(
1410                 accessConstructorDef(cdef.pos, sym, accessConstrs.get(sym)));
1411         } else {
1412             MethodSymbol[] accessors = accessSyms.get(sym);
1413             for (int i = 0; i < AccessCode.numberOfAccessCodes; i++) {

1617     JCVariableDecl outerThisDef(int pos, MethodSymbol owner) {
1618         ClassSymbol c = owner.enclClass();
1619         boolean isMandated =
1620             // Anonymous constructors
1621             (owner.isConstructor() && owner.isAnonymous()) ||
1622             // Constructors of non-private inner member classes
1623             (owner.isConstructor() && c.isInner() &&
1624              !c.isPrivate() && !c.isStatic());
1625         long flags =
1626             FINAL | (isMandated ? MANDATED : SYNTHETIC) | PARAMETER;
1627         VarSymbol outerThis = makeOuterThisVarSymbol(owner, flags);
1628         owner.extraParams = owner.extraParams.prepend(outerThis);
1629         return makeOuterThisVarDecl(pos, outerThis);
1630     }
1631 
1632     /** Definition for this$n field.
1633      *  @param pos        The source code position of the definition.
1634      *  @param owner      The class in which the definition goes.
1635      */
1636     JCVariableDecl outerThisDef(int pos, ClassSymbol owner) {
1637         VarSymbol outerThis = makeOuterThisVarSymbol(owner, FINAL | SYNTHETIC);
1638         return makeOuterThisVarDecl(pos, outerThis);
1639     }
1640 
1641     /** Return a list of trees that load the free variables in given list,
1642      *  in reverse order.
1643      *  @param pos          The source code position to be used for the trees.
1644      *  @param freevars     The list of free variables.
1645      */
1646     List<JCExpression> loadFreevars(DiagnosticPosition pos, List<VarSymbol> freevars) {
1647         List<JCExpression> args = List.nil();
1648         for (List<VarSymbol> l = freevars; l.nonEmpty(); l = l.tail)
1649             args = args.prepend(loadFreevar(pos, l.head));
1650         return args;
1651     }
1652 //where
1653         JCExpression loadFreevar(DiagnosticPosition pos, VarSymbol v) {
1654             return access(v, make.at(pos).Ident(v), null, false);
1655         }
1656 
1657     /** Construct a tree simulating the expression {@code C.this}.

1950     }
1951 
1952 /**************************************************************************
1953  * Code for .class
1954  *************************************************************************/
1955 
1956     /** Return the symbol of a class to contain a cache of
1957      *  compiler-generated statics such as class$ and the
1958      *  $assertionsDisabled flag.  We create an anonymous nested class
1959      *  (unless one already exists) and return its symbol.  However,
1960      *  for backward compatibility in 1.4 and earlier we use the
1961      *  top-level class itself.
1962      */
1963     private ClassSymbol outerCacheClass() {
1964         ClassSymbol clazz = outermostClassDef.sym;
1965         Scope s = clazz.members();
1966         for (Symbol sym : s.getSymbols(NON_RECURSIVE))
1967             if (sym.kind == TYP &&
1968                 sym.name == names.empty &&
1969                 (sym.flags() & INTERFACE) == 0) return (ClassSymbol) sym;
1970         return makeEmptyClass(STATIC | SYNTHETIC, clazz).sym;
1971     }
1972 
1973     /** Create an attributed tree of the form left.name(). */
1974     private JCMethodInvocation makeCall(JCExpression left, Name name, List<JCExpression> args) {
1975         Assert.checkNonNull(left.type);
1976         Symbol funcsym = lookupMethod(make_pos, name, left.type,
1977                                       TreeInfo.types(args));
1978         return make.App(make.Select(left, funcsym), args);
1979     }
1980 
1981     /** The tree simulating a T.class expression.
1982      *  @param clazz      The tree identifying type T.
1983      */
1984     private JCExpression classOf(JCTree clazz) {
1985         return classOfType(clazz.type, clazz.pos());
1986     }
1987 
1988     private JCExpression classOfType(Type type, DiagnosticPosition pos) {
1989         switch (type.getTag()) {
1990         case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:

2002                 VarSymbol sym = new VarSymbol(
2003                         STATIC | PUBLIC | FINAL, names._class,
2004                         syms.classType, type.tsym);
2005                 return make_at(pos).Select(make.Type(type), sym);
2006         default:
2007             throw new AssertionError();
2008         }
2009     }
2010 
2011 /**************************************************************************
2012  * Code for enabling/disabling assertions.
2013  *************************************************************************/
2014 
2015     private ClassSymbol assertionsDisabledClassCache;
2016 
2017     /**Used to create an auxiliary class to hold $assertionsDisabled for interfaces.
2018      */
2019     private ClassSymbol assertionsDisabledClass() {
2020         if (assertionsDisabledClassCache != null) return assertionsDisabledClassCache;
2021 
2022         assertionsDisabledClassCache = makeEmptyClass(STATIC | SYNTHETIC, outermostClassDef.sym).sym;
2023 
2024         return assertionsDisabledClassCache;
2025     }
2026 
2027     // This code is not particularly robust if the user has
2028     // previously declared a member named '$assertionsDisabled'.
2029     // The same faulty idiom also appears in the translation of
2030     // class literals above.  We should report an error if a
2031     // previous declaration is not synthetic.
2032 
2033     private JCExpression assertFlagTest(DiagnosticPosition pos) {
2034         // Outermost class may be either true class or an interface.
2035         ClassSymbol outermostClass = outermostClassDef.sym;
2036 
2037         //only classes can hold a non-public field, look for a usable one:
2038         ClassSymbol container = !currentClass.isInterface() ? currentClass :
2039                 assertionsDisabledClass();
2040 
2041         VarSymbol assertDisabledSym =
2042             (VarSymbol)lookupSynthetic(dollarAssertionsDisabled,

2867         } else {
2868             Map<Symbol, Symbol> prevLambdaTranslationMap =
2869                     lambdaTranslationMap;
2870             try {
2871                 lambdaTranslationMap = (tree.sym.flags() & SYNTHETIC) != 0 &&
2872                         tree.sym.name.startsWith(names.lambda) ?
2873                         makeTranslationMap(tree) : null;
2874                 super.visitMethodDef(tree);
2875             } finally {
2876                 lambdaTranslationMap = prevLambdaTranslationMap;
2877             }
2878         }
2879         if (tree.name == names.init && ((tree.sym.flags_field & Flags.COMPACT_RECORD_CONSTRUCTOR) != 0 ||
2880                 (tree.sym.flags_field & (GENERATEDCONSTR | RECORD)) == (GENERATEDCONSTR | RECORD))) {
2881             // lets find out if there is any field waiting to be initialized
2882             ListBuffer<VarSymbol> fields = new ListBuffer<>();
2883             for (Symbol sym : currentClass.getEnclosedElements()) {
2884                 if (sym.kind == Kinds.Kind.VAR && ((sym.flags() & RECORD) != 0))
2885                     fields.append((VarSymbol) sym);
2886             }

2887             for (VarSymbol field: fields) {
2888                 if ((field.flags_field & Flags.UNINITIALIZED_FIELD) != 0) {
2889                     VarSymbol param = tree.params.stream().filter(p -> p.name == field.name).findFirst().get().sym;
2890                     make.at(tree.pos);
2891                     tree.body.stats = tree.body.stats.append(
2892                             make.Exec(
2893                                     make.Assign(
2894                                             make.Select(make.This(field.owner.erasure(types)), field),
2895                                             make.Ident(param)).setType(field.erasure(types))));
2896                     // we don't need the flag at the field anymore
2897                     field.flags_field &= ~Flags.UNINITIALIZED_FIELD;
2898                 }
2899             }







2900         }
2901         result = tree;
2902     }
2903     //where
2904         private Map<Symbol, Symbol> makeTranslationMap(JCMethodDecl tree) {
2905             Map<Symbol, Symbol> translationMap = new HashMap<>();
2906             for (JCVariableDecl vd : tree.params) {
2907                 Symbol p = vd.sym;
2908                 if (p != p.baseSymbol()) {
2909                     translationMap.put(p.baseSymbol(), p);
2910                 }
2911             }
2912             return translationMap;
2913         }
2914 
2915     public void visitTypeCast(JCTypeCast tree) {
2916         tree.clazz = translate(tree.clazz);
2917         if (tree.type.isPrimitive() != tree.expr.type.isPrimitive())
2918             tree.expr = translate(tree.expr, tree.type);
2919         else

2941         Symbol constructor = accessConstructor(tree.pos(), tree.constructor);
2942         if (constructor != tree.constructor) {
2943             tree.args = tree.args.append(makeNull());
2944             tree.constructor = constructor;
2945         }
2946 
2947         // If created class has an outer instance, and new is qualified, pass
2948         // qualifier as first argument. If new is not qualified, pass the
2949         // correct outer instance as first argument.
2950         if (c.hasOuterInstance()) {
2951             JCExpression thisArg;
2952             if (tree.encl != null) {
2953                 thisArg = attr.makeNullCheck(translate(tree.encl));
2954                 thisArg.type = tree.encl.type;
2955             } else if (c.isDirectlyOrIndirectlyLocal()) {
2956                 // local class
2957                 thisArg = makeThis(tree.pos(), c.type.getEnclosingType().tsym);
2958             } else {
2959                 // nested class
2960                 thisArg = makeOwnerThis(tree.pos(), c, false);











2961             }
2962             tree.args = tree.args.prepend(thisArg);
2963         }
2964         tree.encl = null;
2965 
2966         // If we have an anonymous class, create its flat version, rather
2967         // than the class or interface following new.
2968         if (tree.def != null) {
2969             Map<Symbol, Symbol> prevLambdaTranslationMap = lambdaTranslationMap;
2970             try {
2971                 lambdaTranslationMap = null;
2972                 translate(tree.def);
2973             } finally {
2974                 lambdaTranslationMap = prevLambdaTranslationMap;
2975             }
2976 
2977             tree.clazz = access(make_at(tree.clazz.pos()).Ident(tree.def.sym));
2978             tree.def = null;
2979         } else {
2980             tree.clazz = access(c, tree.clazz, enclOp, false);

 173     JCMethodDecl currentMethodDef;
 174 
 175     /** The current method symbol.
 176      */
 177     MethodSymbol currentMethodSym;
 178 
 179     /** The currently enclosing outermost class definition.
 180      */
 181     JCClassDecl outermostClassDef;
 182 
 183     /** The currently enclosing outermost member definition.
 184      */
 185     JCTree outermostMemberDef;
 186 
 187     /** A map from local variable symbols to their translation (as per LambdaToMethod).
 188      * This is required when a capturing local class is created from a lambda (in which
 189      * case the captured symbols should be replaced with the translated lambda symbols).
 190      */
 191     Map<Symbol, Symbol> lambdaTranslationMap = null;
 192 
 193     /** A hash table mapping local classes to a set of outer this fields
 194      */
 195     public Map<ClassSymbol, Set<JCExpression>> initializerOuterThis = new WeakHashMap<>();
 196 
 197     /** A navigator class for assembling a mapping from local class symbols
 198      *  to class definition trees.
 199      *  There is only one case; all other cases simply traverse down the tree.
 200      */
 201     class ClassMap extends TreeScanner {
 202 
 203         /** All encountered class defs are entered into classdefs table.
 204          */
 205         public void visitClassDef(JCClassDecl tree) {
 206             classdefs.put(tree.sym, tree);
 207             super.visitClassDef(tree);
 208         }
 209     }
 210     ClassMap classMap = new ClassMap();
 211 
 212     /** Map a class symbol to its definition.
 213      *  @param c    The class symbol of which we want to determine the definition.
 214      */
 215     JCClassDecl classDef(ClassSymbol c) {
 216         // First lookup the class in the classdefs table.

 893 
 894     /** Look up a method in a given scope.
 895      */
 896     private MethodSymbol lookupMethod(DiagnosticPosition pos, Name name, Type qual, List<Type> args) {
 897         return rs.resolveInternalMethod(pos, attrEnv, qual, name, args, List.nil());
 898     }
 899 
 900     /** Anon inner classes are used as access constructor tags.
 901      * accessConstructorTag will use an existing anon class if one is available,
 902      * and synthesize a class (with makeEmptyClass) if one is not available.
 903      * However, there is a small possibility that an existing class will not
 904      * be generated as expected if it is inside a conditional with a constant
 905      * expression. If that is found to be the case, create an empty class tree here.
 906      */
 907     private void checkAccessConstructorTags() {
 908         for (List<ClassSymbol> l = accessConstrTags; l.nonEmpty(); l = l.tail) {
 909             ClassSymbol c = l.head;
 910             if (isTranslatedClassAvailable(c))
 911                 continue;
 912             // Create class definition tree.
 913             JCClassDecl cdec = makeEmptyClass(STATIC | SYNTHETIC | IDENTITY_TYPE,
 914                     c.outermostClass(), c.flatname, false);
 915             swapAccessConstructorTag(c, cdec.sym);
 916             translated.append(cdec);
 917         }
 918     }
 919     // where
 920     private boolean isTranslatedClassAvailable(ClassSymbol c) {
 921         for (JCTree tree: translated) {
 922             if (tree.hasTag(CLASSDEF)
 923                     && ((JCClassDecl) tree).sym == c) {
 924                 return true;
 925             }
 926         }
 927         return false;
 928     }
 929 
 930     void swapAccessConstructorTag(ClassSymbol oldCTag, ClassSymbol newCTag) {
 931         for (MethodSymbol methodSymbol : accessConstrs.values()) {
 932             Assert.check(methodSymbol.type.hasTag(METHOD));
 933             MethodType oldMethodType =

1377                 accessConstrs.put(constr, aconstr);
1378                 accessed.append(constr);
1379             }
1380             return aconstr;
1381         } else {
1382             return constr;
1383         }
1384     }
1385 
1386     /** Return an anonymous class nested in this toplevel class.
1387      */
1388     ClassSymbol accessConstructorTag() {
1389         ClassSymbol topClass = currentClass.outermostClass();
1390         ModuleSymbol topModle = topClass.packge().modle;
1391         for (int i = 1; ; i++) {
1392             Name flatname = names.fromString("" + topClass.getQualifiedName() +
1393                                             target.syntheticNameChar() +
1394                                             i);
1395             ClassSymbol ctag = chk.getCompiled(topModle, flatname);
1396             if (ctag == null)
1397                 ctag = makeEmptyClass(STATIC | SYNTHETIC | IDENTITY_TYPE, topClass).sym;
1398             else if (!ctag.isAnonymous())
1399                 continue;
1400             // keep a record of all tags, to verify that all are generated as required
1401             accessConstrTags = accessConstrTags.prepend(ctag);
1402             return ctag;
1403         }
1404     }
1405 
1406     /** Add all required access methods for a private symbol to enclosing class.
1407      *  @param sym       The symbol.
1408      */
1409     void makeAccessible(Symbol sym) {
1410         JCClassDecl cdef = classDef(sym.owner.enclClass());
1411         if (cdef == null) Assert.error("class def not found: " + sym + " in " + sym.owner);
1412         if (sym.name == names.init) {
1413             cdef.defs = cdef.defs.prepend(
1414                 accessConstructorDef(cdef.pos, sym, accessConstrs.get(sym)));
1415         } else {
1416             MethodSymbol[] accessors = accessSyms.get(sym);
1417             for (int i = 0; i < AccessCode.numberOfAccessCodes; i++) {

1621     JCVariableDecl outerThisDef(int pos, MethodSymbol owner) {
1622         ClassSymbol c = owner.enclClass();
1623         boolean isMandated =
1624             // Anonymous constructors
1625             (owner.isConstructor() && owner.isAnonymous()) ||
1626             // Constructors of non-private inner member classes
1627             (owner.isConstructor() && c.isInner() &&
1628              !c.isPrivate() && !c.isStatic());
1629         long flags =
1630             FINAL | (isMandated ? MANDATED : SYNTHETIC) | PARAMETER;
1631         VarSymbol outerThis = makeOuterThisVarSymbol(owner, flags);
1632         owner.extraParams = owner.extraParams.prepend(outerThis);
1633         return makeOuterThisVarDecl(pos, outerThis);
1634     }
1635 
1636     /** Definition for this$n field.
1637      *  @param pos        The source code position of the definition.
1638      *  @param owner      The class in which the definition goes.
1639      */
1640     JCVariableDecl outerThisDef(int pos, ClassSymbol owner) {
1641         VarSymbol outerThis = makeOuterThisVarSymbol(owner, FINAL | SYNTHETIC | (owner.isValueClass() ? STRICT : 0));
1642         return makeOuterThisVarDecl(pos, outerThis);
1643     }
1644 
1645     /** Return a list of trees that load the free variables in given list,
1646      *  in reverse order.
1647      *  @param pos          The source code position to be used for the trees.
1648      *  @param freevars     The list of free variables.
1649      */
1650     List<JCExpression> loadFreevars(DiagnosticPosition pos, List<VarSymbol> freevars) {
1651         List<JCExpression> args = List.nil();
1652         for (List<VarSymbol> l = freevars; l.nonEmpty(); l = l.tail)
1653             args = args.prepend(loadFreevar(pos, l.head));
1654         return args;
1655     }
1656 //where
1657         JCExpression loadFreevar(DiagnosticPosition pos, VarSymbol v) {
1658             return access(v, make.at(pos).Ident(v), null, false);
1659         }
1660 
1661     /** Construct a tree simulating the expression {@code C.this}.

1954     }
1955 
1956 /**************************************************************************
1957  * Code for .class
1958  *************************************************************************/
1959 
1960     /** Return the symbol of a class to contain a cache of
1961      *  compiler-generated statics such as class$ and the
1962      *  $assertionsDisabled flag.  We create an anonymous nested class
1963      *  (unless one already exists) and return its symbol.  However,
1964      *  for backward compatibility in 1.4 and earlier we use the
1965      *  top-level class itself.
1966      */
1967     private ClassSymbol outerCacheClass() {
1968         ClassSymbol clazz = outermostClassDef.sym;
1969         Scope s = clazz.members();
1970         for (Symbol sym : s.getSymbols(NON_RECURSIVE))
1971             if (sym.kind == TYP &&
1972                 sym.name == names.empty &&
1973                 (sym.flags() & INTERFACE) == 0) return (ClassSymbol) sym;
1974         return makeEmptyClass(STATIC | SYNTHETIC | IDENTITY_TYPE, clazz).sym;
1975     }
1976 
1977     /** Create an attributed tree of the form left.name(). */
1978     private JCMethodInvocation makeCall(JCExpression left, Name name, List<JCExpression> args) {
1979         Assert.checkNonNull(left.type);
1980         Symbol funcsym = lookupMethod(make_pos, name, left.type,
1981                                       TreeInfo.types(args));
1982         return make.App(make.Select(left, funcsym), args);
1983     }
1984 
1985     /** The tree simulating a T.class expression.
1986      *  @param clazz      The tree identifying type T.
1987      */
1988     private JCExpression classOf(JCTree clazz) {
1989         return classOfType(clazz.type, clazz.pos());
1990     }
1991 
1992     private JCExpression classOfType(Type type, DiagnosticPosition pos) {
1993         switch (type.getTag()) {
1994         case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:

2006                 VarSymbol sym = new VarSymbol(
2007                         STATIC | PUBLIC | FINAL, names._class,
2008                         syms.classType, type.tsym);
2009                 return make_at(pos).Select(make.Type(type), sym);
2010         default:
2011             throw new AssertionError();
2012         }
2013     }
2014 
2015 /**************************************************************************
2016  * Code for enabling/disabling assertions.
2017  *************************************************************************/
2018 
2019     private ClassSymbol assertionsDisabledClassCache;
2020 
2021     /**Used to create an auxiliary class to hold $assertionsDisabled for interfaces.
2022      */
2023     private ClassSymbol assertionsDisabledClass() {
2024         if (assertionsDisabledClassCache != null) return assertionsDisabledClassCache;
2025 
2026         assertionsDisabledClassCache = makeEmptyClass(STATIC | SYNTHETIC | IDENTITY_TYPE, outermostClassDef.sym).sym;
2027 
2028         return assertionsDisabledClassCache;
2029     }
2030 
2031     // This code is not particularly robust if the user has
2032     // previously declared a member named '$assertionsDisabled'.
2033     // The same faulty idiom also appears in the translation of
2034     // class literals above.  We should report an error if a
2035     // previous declaration is not synthetic.
2036 
2037     private JCExpression assertFlagTest(DiagnosticPosition pos) {
2038         // Outermost class may be either true class or an interface.
2039         ClassSymbol outermostClass = outermostClassDef.sym;
2040 
2041         //only classes can hold a non-public field, look for a usable one:
2042         ClassSymbol container = !currentClass.isInterface() ? currentClass :
2043                 assertionsDisabledClass();
2044 
2045         VarSymbol assertDisabledSym =
2046             (VarSymbol)lookupSynthetic(dollarAssertionsDisabled,

2871         } else {
2872             Map<Symbol, Symbol> prevLambdaTranslationMap =
2873                     lambdaTranslationMap;
2874             try {
2875                 lambdaTranslationMap = (tree.sym.flags() & SYNTHETIC) != 0 &&
2876                         tree.sym.name.startsWith(names.lambda) ?
2877                         makeTranslationMap(tree) : null;
2878                 super.visitMethodDef(tree);
2879             } finally {
2880                 lambdaTranslationMap = prevLambdaTranslationMap;
2881             }
2882         }
2883         if (tree.name == names.init && ((tree.sym.flags_field & Flags.COMPACT_RECORD_CONSTRUCTOR) != 0 ||
2884                 (tree.sym.flags_field & (GENERATEDCONSTR | RECORD)) == (GENERATEDCONSTR | RECORD))) {
2885             // lets find out if there is any field waiting to be initialized
2886             ListBuffer<VarSymbol> fields = new ListBuffer<>();
2887             for (Symbol sym : currentClass.getEnclosedElements()) {
2888                 if (sym.kind == Kinds.Kind.VAR && ((sym.flags() & RECORD) != 0))
2889                     fields.append((VarSymbol) sym);
2890             }
2891             ListBuffer<JCStatement> initializers = new ListBuffer<>();
2892             for (VarSymbol field: fields) {
2893                 if ((field.flags_field & Flags.UNINITIALIZED_FIELD) != 0) {
2894                     VarSymbol param = tree.params.stream().filter(p -> p.name == field.name).findFirst().get().sym;
2895                     make.at(tree.pos);
2896                     initializers.add(make.Exec(
2897                             make.Assign(
2898                                     make.Select(make.This(field.owner.erasure(types)), field),
2899                                     make.Ident(param)).setType(field.erasure(types))));


2900                     field.flags_field &= ~Flags.UNINITIALIZED_FIELD;
2901                 }
2902             }
2903             if (initializers.nonEmpty()) {
2904                 if (tree.sym.owner.isValueClass()) {
2905                     TreeInfo.mapSuperCalls(tree.body, supercall -> make.Block(0, initializers.toList().append(supercall)));
2906                 } else {
2907                     tree.body.stats = tree.body.stats.appendList(initializers);
2908                 }
2909             }
2910         }
2911         result = tree;
2912     }
2913     //where
2914         private Map<Symbol, Symbol> makeTranslationMap(JCMethodDecl tree) {
2915             Map<Symbol, Symbol> translationMap = new HashMap<>();
2916             for (JCVariableDecl vd : tree.params) {
2917                 Symbol p = vd.sym;
2918                 if (p != p.baseSymbol()) {
2919                     translationMap.put(p.baseSymbol(), p);
2920                 }
2921             }
2922             return translationMap;
2923         }
2924 
2925     public void visitTypeCast(JCTypeCast tree) {
2926         tree.clazz = translate(tree.clazz);
2927         if (tree.type.isPrimitive() != tree.expr.type.isPrimitive())
2928             tree.expr = translate(tree.expr, tree.type);
2929         else

2951         Symbol constructor = accessConstructor(tree.pos(), tree.constructor);
2952         if (constructor != tree.constructor) {
2953             tree.args = tree.args.append(makeNull());
2954             tree.constructor = constructor;
2955         }
2956 
2957         // If created class has an outer instance, and new is qualified, pass
2958         // qualifier as first argument. If new is not qualified, pass the
2959         // correct outer instance as first argument.
2960         if (c.hasOuterInstance()) {
2961             JCExpression thisArg;
2962             if (tree.encl != null) {
2963                 thisArg = attr.makeNullCheck(translate(tree.encl));
2964                 thisArg.type = tree.encl.type;
2965             } else if (c.isDirectlyOrIndirectlyLocal()) {
2966                 // local class
2967                 thisArg = makeThis(tree.pos(), c.type.getEnclosingType().tsym);
2968             } else {
2969                 // nested class
2970                 thisArg = makeOwnerThis(tree.pos(), c, false);
2971                 if (currentMethodSym != null &&
2972                         ((currentMethodSym.flags_field & (STATIC | BLOCK)) == BLOCK) &&
2973                         currentMethodSym.owner.isValueClass()) {
2974                     // instance initializer in a value class
2975                     Set<JCExpression> outerThisSet = initializerOuterThis.get(currentClass);
2976                     if (outerThisSet == null) {
2977                         outerThisSet = new HashSet<>();
2978                     }
2979                     outerThisSet.add(thisArg);
2980                     initializerOuterThis.put(currentClass, outerThisSet);
2981                 }
2982             }
2983             tree.args = tree.args.prepend(thisArg);
2984         }
2985         tree.encl = null;
2986 
2987         // If we have an anonymous class, create its flat version, rather
2988         // than the class or interface following new.
2989         if (tree.def != null) {
2990             Map<Symbol, Symbol> prevLambdaTranslationMap = lambdaTranslationMap;
2991             try {
2992                 lambdaTranslationMap = null;
2993                 translate(tree.def);
2994             } finally {
2995                 lambdaTranslationMap = prevLambdaTranslationMap;
2996             }
2997 
2998             tree.clazz = access(make_at(tree.clazz.pos()).Ident(tree.def.sym));
2999             tree.def = null;
3000         } else {
3001             tree.clazz = access(c, tree.clazz, enclOp, false);
< prev index next >