< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java

Print this page

1602             }
1603             @Override
1604             public void visitRecordPattern(JCRecordPattern that) {
1605                 hasPatterns = true;
1606                 super.visitRecordPattern(that);
1607             }
1608             @Override
1609             public void visitSwitch(JCSwitch tree) {
1610                 hasPatterns |= tree.patternSwitch;
1611                 super.visitSwitch(tree);
1612             }
1613             @Override
1614             public void visitSwitchExpression(JCSwitchExpression tree) {
1615                 hasPatterns |= tree.patternSwitch;
1616                 super.visitSwitchExpression(tree);
1617             }
1618         }
1619         ScanNested scanner = new ScanNested();
1620         scanner.scan(env.tree);
1621         for (Env<AttrContext> dep: scanner.dependencies) {
1622         if (!compileStates.isDone(dep, CompileState.WARN))
1623             desugaredEnvs.put(dep, desugar(warn(flow(attribute(dep)))));
1624         }
1625 
1626         //We need to check for error another time as more classes might
1627         //have been attributed and analyzed at this stage
1628         if (shouldStop(CompileState.TRANSTYPES))
1629             return;
1630 
1631         if (verboseCompilePolicy)
1632             printNote("[desugar " + env.enclClass.sym + "]");
1633 
1634         JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ?
1635                                   env.enclClass.sym.sourcefile :
1636                                   env.toplevel.sourcefile);
1637         try {
1638             //save tree prior to rewriting
1639             JCTree untranslated = env.tree;
1640 
1641             make.at(Position.FIRSTPOS);
1642             TreeMaker localMake = make.forToplevel(env.toplevel);
1643 

1683                 return;
1684             }
1685 
1686             //translate out inner classes
1687             List<JCTree> cdefs = lower.translateTopLevelClass(env, env.tree, localMake);
1688             compileStates.put(env, CompileState.LOWER);
1689 
1690             if (shouldStop(CompileState.LOWER))
1691                 return;
1692 
1693             if (scanner.hasLambdas) {
1694                 if (shouldStop(CompileState.UNLAMBDA))
1695                     return;
1696 
1697                 for (JCTree def : cdefs) {
1698                     LambdaToMethod.instance(context).translateTopLevelClass(env, def, localMake);
1699                 }
1700                 compileStates.put(env, CompileState.UNLAMBDA);
1701             }
1702 







1703             //generate code for each class
1704             for (List<JCTree> l = cdefs; l.nonEmpty(); l = l.tail) {
1705                 JCClassDecl cdef = (JCClassDecl)l.head;
1706                 results.add(new Pair<>(env, cdef));
1707             }
1708         }
1709         finally {
1710             log.useSource(prev);
1711         }
1712 
1713     }
1714 
1715     /** Generates the source or class file for a list of classes.
1716      * The decision to generate a source file or a class file is
1717      * based upon the compiler's options.
1718      * Generation stops if an error occurs while writing files.
1719      */
1720     public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue) {
1721         generate(queue, null);
1722     }

1602             }
1603             @Override
1604             public void visitRecordPattern(JCRecordPattern that) {
1605                 hasPatterns = true;
1606                 super.visitRecordPattern(that);
1607             }
1608             @Override
1609             public void visitSwitch(JCSwitch tree) {
1610                 hasPatterns |= tree.patternSwitch;
1611                 super.visitSwitch(tree);
1612             }
1613             @Override
1614             public void visitSwitchExpression(JCSwitchExpression tree) {
1615                 hasPatterns |= tree.patternSwitch;
1616                 super.visitSwitchExpression(tree);
1617             }
1618         }
1619         ScanNested scanner = new ScanNested();
1620         scanner.scan(env.tree);
1621         for (Env<AttrContext> dep: scanner.dependencies) {
1622             if (!compileStates.isDone(dep, CompileState.WARN))
1623                 desugaredEnvs.put(dep, desugar(warn(flow(attribute(dep)))));
1624         }
1625 
1626         //We need to check for error another time as more classes might
1627         //have been attributed and analyzed at this stage
1628         if (shouldStop(CompileState.TRANSTYPES))
1629             return;
1630 
1631         if (verboseCompilePolicy)
1632             printNote("[desugar " + env.enclClass.sym + "]");
1633 
1634         JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ?
1635                                   env.enclClass.sym.sourcefile :
1636                                   env.toplevel.sourcefile);
1637         try {
1638             //save tree prior to rewriting
1639             JCTree untranslated = env.tree;
1640 
1641             make.at(Position.FIRSTPOS);
1642             TreeMaker localMake = make.forToplevel(env.toplevel);
1643 

1683                 return;
1684             }
1685 
1686             //translate out inner classes
1687             List<JCTree> cdefs = lower.translateTopLevelClass(env, env.tree, localMake);
1688             compileStates.put(env, CompileState.LOWER);
1689 
1690             if (shouldStop(CompileState.LOWER))
1691                 return;
1692 
1693             if (scanner.hasLambdas) {
1694                 if (shouldStop(CompileState.UNLAMBDA))
1695                     return;
1696 
1697                 for (JCTree def : cdefs) {
1698                     LambdaToMethod.instance(context).translateTopLevelClass(env, def, localMake);
1699                 }
1700                 compileStates.put(env, CompileState.UNLAMBDA);
1701             }
1702 
1703             if (shouldStop(CompileState.STRICT_FIELDS_PROXIES))
1704                 return;
1705             for (JCTree def : cdefs) {
1706                 LocalProxyVarsGen.instance(context).translateTopLevelClass(def, localMake);
1707             }
1708             compileStates.put(env, CompileState.STRICT_FIELDS_PROXIES);
1709 
1710             //generate code for each class
1711             for (List<JCTree> l = cdefs; l.nonEmpty(); l = l.tail) {
1712                 JCClassDecl cdef = (JCClassDecl)l.head;
1713                 results.add(new Pair<>(env, cdef));
1714             }
1715         }
1716         finally {
1717             log.useSource(prev);
1718         }
1719 
1720     }
1721 
1722     /** Generates the source or class file for a list of classes.
1723      * The decision to generate a source file or a class file is
1724      * based upon the compiler's options.
1725      * Generation stops if an error occurs while writing files.
1726      */
1727     public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue) {
1728         generate(queue, null);
1729     }
< prev index next >