< prev index next >

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

Print this page

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

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







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

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

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