< prev index next >

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

Print this page

   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.main;
  27 
  28 import java.io.*;


  29 import java.nio.file.FileSystemNotFoundException;
  30 import java.nio.file.InvalidPathException;
  31 import java.nio.file.ReadOnlyFileSystemException;
  32 import java.util.Collection;
  33 import java.util.Comparator;
  34 import java.util.EnumSet;
  35 import java.util.HashMap;
  36 import java.util.HashSet;
  37 import java.util.LinkedHashMap;
  38 import java.util.LinkedHashSet;
  39 import java.util.Map;
  40 import java.util.MissingResourceException;

  41 import java.util.Queue;
  42 import java.util.ResourceBundle;

  43 import java.util.Set;
  44 import java.util.function.Function;
  45 import java.util.function.ToIntFunction;
  46 
  47 import javax.annotation.processing.Processor;
  48 import javax.lang.model.SourceVersion;
  49 import javax.lang.model.element.ElementVisitor;
  50 import javax.tools.DiagnosticListener;
  51 import javax.tools.JavaFileManager;
  52 import javax.tools.JavaFileObject;
  53 import javax.tools.JavaFileObject.Kind;
  54 import javax.tools.StandardLocation;
  55 
  56 import com.sun.source.util.TaskEvent;
  57 import com.sun.tools.javac.api.MultiTaskListener;
  58 import com.sun.tools.javac.code.*;
  59 import com.sun.tools.javac.code.Lint.LintCategory;
  60 import com.sun.tools.javac.code.Source.Feature;
  61 import com.sun.tools.javac.code.Symbol.ClassSymbol;
  62 import com.sun.tools.javac.code.Symbol.CompletionFailure;

  70 import com.sun.tools.javac.platform.PlatformDescription;
  71 import com.sun.tools.javac.processing.*;
  72 import com.sun.tools.javac.tree.*;
  73 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
  74 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
  75 import com.sun.tools.javac.tree.JCTree.JCExpression;
  76 import com.sun.tools.javac.tree.JCTree.JCLambda;
  77 import com.sun.tools.javac.tree.JCTree.JCMemberReference;
  78 import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
  79 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
  80 import com.sun.tools.javac.util.*;
  81 import com.sun.tools.javac.util.Context.Key;
  82 import com.sun.tools.javac.util.DefinedBy.Api;
  83 import com.sun.tools.javac.util.JCDiagnostic.Factory;
  84 import com.sun.tools.javac.util.Log.DiagnosticHandler;
  85 import com.sun.tools.javac.util.Log.DiscardDiagnosticHandler;
  86 import com.sun.tools.javac.util.Log.WriterKind;
  87 
  88 import static com.sun.tools.javac.code.Kinds.Kind.*;
  89 


  90 import com.sun.tools.javac.resources.CompilerProperties.Errors;
  91 import com.sun.tools.javac.resources.CompilerProperties.Fragments;
  92 import com.sun.tools.javac.resources.CompilerProperties.Notes;
  93 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
  94 
  95 import static com.sun.tools.javac.code.TypeTag.CLASS;
  96 import static com.sun.tools.javac.main.Option.*;
  97 import com.sun.tools.javac.tree.JCTree.JCBindingPattern;
  98 import com.sun.tools.javac.tree.JCTree.JCInstanceOf;
  99 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
 100 
 101 import static javax.tools.StandardLocation.CLASS_OUTPUT;
 102 import static javax.tools.StandardLocation.ANNOTATION_PROCESSOR_PATH;
 103 
 104 import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
 105 import com.sun.tools.javac.tree.JCTree.JCRecordPattern;
 106 import com.sun.tools.javac.tree.JCTree.JCSwitch;
 107 import com.sun.tools.javac.tree.JCTree.JCSwitchExpression;
 108 
 109 /** This class could be the main entry point for GJC when GJC is used as a

 750                 tree = (tree == null) ? make.Ident(names.fromString(s))
 751                                       : make.Select(tree, names.fromString(s));
 752             }
 753             JCCompilationUnit toplevel =
 754                 make.TopLevel(List.nil());
 755             toplevel.modle = msym;
 756             toplevel.packge = msym.unnamedPackage;
 757             return attr.attribIdent(tree, toplevel);
 758         } finally {
 759             log.useSource(prev);
 760         }
 761     }
 762 
 763     /** Generate code and emit a class file for a given class
 764      *  @param env    The attribution environment of the outermost class
 765      *                containing this class.
 766      *  @param cdef   The class definition from which code is generated.
 767      */
 768     JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
 769         try {







 770             if (gen.genClass(env, cdef) && (errorCount() == 0))
 771                 return writer.writeClass(cdef.sym);
 772         } catch (ClassWriter.PoolOverflow ex) {
 773             log.error(cdef.pos(), Errors.LimitPool);
 774         } catch (ClassWriter.StringOverflow ex) {
 775             log.error(cdef.pos(),
 776                       Errors.LimitStringOverflow(ex.value.substring(0, 20)));
 777         } catch (CompletionFailure ex) {
 778             chk.completionError(cdef.pos(), ex);
 779         }
 780         return null;
 781     }
 782 
 783     /** Emit plain Java source for a class.
 784      *  @param env    The attribution environment of the outermost class
 785      *                containing this class.
 786      *  @param cdef   The class definition to be printed.
 787      */
 788     JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
 789         JavaFileObject outFile

1032         Set<JavaFileObject> filesSoFar = new HashSet<>();
1033         for (JavaFileObject fileObject : fileObjects) {
1034             if (!filesSoFar.contains(fileObject)) {
1035                 filesSoFar.add(fileObject);
1036                 trees.append(parse(fileObject));
1037             }
1038         }
1039         return trees.toList();
1040     }
1041 
1042    /**
1043     * Returns true iff the compilation will continue after annotation processing
1044     * is done.
1045     */
1046     public boolean continueAfterProcessAnnotations() {
1047         return !shouldStop(CompileState.ATTR);
1048     }
1049 
1050     public List<JCCompilationUnit> initModules(List<JCCompilationUnit> roots) {
1051         modules.initModules(roots);

1052         if (roots.isEmpty()) {
1053             enterDone();
1054         }
1055         return roots;
1056     }
1057 
1058     /**
1059      * Enter the symbols found in a list of parse trees.
1060      * As a side-effect, this puts elements on the "todo" list.
1061      * Also stores a list of all top level classes in rootClasses.
1062      */
1063     public List<JCCompilationUnit> enterTrees(List<JCCompilationUnit> roots) {
1064         //enter symbols for all files
1065         if (!taskListener.isEmpty()) {
1066             for (JCCompilationUnit unit: roots) {
1067                 TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
1068                 taskListener.started(e);
1069             }
1070         }
1071 

1644 
1645             make.at(Position.FIRSTPOS);
1646             TreeMaker localMake = make.forToplevel(env.toplevel);
1647 
1648             if (env.tree.hasTag(JCTree.Tag.PACKAGEDEF) || env.tree.hasTag(JCTree.Tag.MODULEDEF)) {
1649                 if (!(sourceOutput)) {
1650                     if (shouldStop(CompileState.LOWER))
1651                         return;
1652                     List<JCTree> def = lower.translateTopLevelClass(env, env.tree, localMake);
1653                     if (def.head != null) {
1654                         Assert.check(def.tail.isEmpty());
1655                         results.add(new Pair<>(env, (JCClassDecl)def.head));
1656                     }
1657                 }
1658                 return;
1659             }
1660 
1661             if (shouldStop(CompileState.TRANSTYPES))
1662                 return;
1663 







1664             env.tree = transTypes.translateTopLevelClass(env.tree, localMake);
1665             compileStates.put(env, CompileState.TRANSTYPES);
1666 
1667             if (shouldStop(CompileState.TRANSPATTERNS))
1668                 return;
1669 
1670             if (scanner.hasPatterns) {
1671                 env.tree = TransPatterns.instance(context).translateTopLevelClass(env, env.tree, localMake);
1672             }
1673 
1674             compileStates.put(env, CompileState.TRANSPATTERNS);
1675 
1676             if (shouldStop(CompileState.LOWER))
1677                 return;
1678 
1679             if (sourceOutput) {
1680                 //emit standard Java source file, only for compilation
1681                 //units enumerated explicitly on the command line
1682                 JCClassDecl cdef = (JCClassDecl)env.tree;
1683                 if (untranslated instanceof JCClassDecl classDecl &&

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     }
1727 
1728     public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) {
1729         if (shouldStop(CompileState.GENERATE))
1730             return;
1731 
1732         for (Pair<Env<AttrContext>, JCClassDecl> x: queue) {
1733             Env<AttrContext> env = x.fst;
1734             JCClassDecl cdef = x.snd;
1735 
1736             if (verboseCompilePolicy) {
1737                 printNote("[generate " + (sourceOutput ? " source" : "code") + " " + cdef.sym + "]");
1738             }

   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.main;
  27 
  28 import java.io.*;
  29 import java.lang.module.Configuration;
  30 import java.lang.reflect.Method;
  31 import java.nio.file.FileSystemNotFoundException;
  32 import java.nio.file.InvalidPathException;
  33 import java.nio.file.ReadOnlyFileSystemException;
  34 import java.util.Collection;
  35 import java.util.Comparator;
  36 import java.util.EnumSet;
  37 import java.util.HashMap;
  38 import java.util.HashSet;
  39 import java.util.LinkedHashMap;
  40 import java.util.LinkedHashSet;
  41 import java.util.Map;
  42 import java.util.MissingResourceException;
  43 import java.util.Optional;
  44 import java.util.Queue;
  45 import java.util.ResourceBundle;
  46 import java.util.ServiceLoader;
  47 import java.util.Set;
  48 import java.util.function.Function;
  49 import java.util.function.ToIntFunction;
  50 
  51 import javax.annotation.processing.Processor;
  52 import javax.lang.model.SourceVersion;
  53 import javax.lang.model.element.ElementVisitor;
  54 import javax.tools.DiagnosticListener;
  55 import javax.tools.JavaFileManager;
  56 import javax.tools.JavaFileObject;
  57 import javax.tools.JavaFileObject.Kind;
  58 import javax.tools.StandardLocation;
  59 
  60 import com.sun.source.util.TaskEvent;
  61 import com.sun.tools.javac.api.MultiTaskListener;
  62 import com.sun.tools.javac.code.*;
  63 import com.sun.tools.javac.code.Lint.LintCategory;
  64 import com.sun.tools.javac.code.Source.Feature;
  65 import com.sun.tools.javac.code.Symbol.ClassSymbol;
  66 import com.sun.tools.javac.code.Symbol.CompletionFailure;

  74 import com.sun.tools.javac.platform.PlatformDescription;
  75 import com.sun.tools.javac.processing.*;
  76 import com.sun.tools.javac.tree.*;
  77 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
  78 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
  79 import com.sun.tools.javac.tree.JCTree.JCExpression;
  80 import com.sun.tools.javac.tree.JCTree.JCLambda;
  81 import com.sun.tools.javac.tree.JCTree.JCMemberReference;
  82 import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
  83 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
  84 import com.sun.tools.javac.util.*;
  85 import com.sun.tools.javac.util.Context.Key;
  86 import com.sun.tools.javac.util.DefinedBy.Api;
  87 import com.sun.tools.javac.util.JCDiagnostic.Factory;
  88 import com.sun.tools.javac.util.Log.DiagnosticHandler;
  89 import com.sun.tools.javac.util.Log.DiscardDiagnosticHandler;
  90 import com.sun.tools.javac.util.Log.WriterKind;
  91 
  92 import static com.sun.tools.javac.code.Kinds.Kind.*;
  93 
  94 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
  95 
  96 import com.sun.tools.javac.resources.CompilerProperties.Errors;
  97 import com.sun.tools.javac.resources.CompilerProperties.Fragments;
  98 import com.sun.tools.javac.resources.CompilerProperties.Notes;
  99 import com.sun.tools.javac.resources.CompilerProperties.Warnings;
 100 
 101 import static com.sun.tools.javac.code.TypeTag.CLASS;
 102 import static com.sun.tools.javac.main.Option.*;
 103 import com.sun.tools.javac.tree.JCTree.JCBindingPattern;
 104 import com.sun.tools.javac.tree.JCTree.JCInstanceOf;
 105 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
 106 
 107 import static javax.tools.StandardLocation.CLASS_OUTPUT;
 108 import static javax.tools.StandardLocation.ANNOTATION_PROCESSOR_PATH;
 109 
 110 import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
 111 import com.sun.tools.javac.tree.JCTree.JCRecordPattern;
 112 import com.sun.tools.javac.tree.JCTree.JCSwitch;
 113 import com.sun.tools.javac.tree.JCTree.JCSwitchExpression;
 114 
 115 /** This class could be the main entry point for GJC when GJC is used as a

 756                 tree = (tree == null) ? make.Ident(names.fromString(s))
 757                                       : make.Select(tree, names.fromString(s));
 758             }
 759             JCCompilationUnit toplevel =
 760                 make.TopLevel(List.nil());
 761             toplevel.modle = msym;
 762             toplevel.packge = msym.unnamedPackage;
 763             return attr.attribIdent(tree, toplevel);
 764         } finally {
 765             log.useSource(prev);
 766         }
 767     }
 768 
 769     /** Generate code and emit a class file for a given class
 770      *  @param env    The attribution environment of the outermost class
 771      *                containing this class.
 772      *  @param cdef   The class definition from which code is generated.
 773      */
 774     JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
 775         try {
 776             if (Feature.REFLECT_METHODS.allowedInSource(source)) {
 777                 Optional<CodeReflectionTransformer> reflectMethods = reflectMethods();
 778                 if (reflectMethods.isPresent()) {
 779                     reflectMethods.get().genCode(context, cdef);
 780                 }
 781             }
 782 
 783             if (gen.genClass(env, cdef) && (errorCount() == 0))
 784                 return writer.writeClass(cdef.sym);
 785         } catch (ClassWriter.PoolOverflow ex) {
 786             log.error(cdef.pos(), Errors.LimitPool);
 787         } catch (ClassWriter.StringOverflow ex) {
 788             log.error(cdef.pos(),
 789                       Errors.LimitStringOverflow(ex.value.substring(0, 20)));
 790         } catch (CompletionFailure ex) {
 791             chk.completionError(cdef.pos(), ex);
 792         }
 793         return null;
 794     }
 795 
 796     /** Emit plain Java source for a class.
 797      *  @param env    The attribution environment of the outermost class
 798      *                containing this class.
 799      *  @param cdef   The class definition to be printed.
 800      */
 801     JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
 802         JavaFileObject outFile

1045         Set<JavaFileObject> filesSoFar = new HashSet<>();
1046         for (JavaFileObject fileObject : fileObjects) {
1047             if (!filesSoFar.contains(fileObject)) {
1048                 filesSoFar.add(fileObject);
1049                 trees.append(parse(fileObject));
1050             }
1051         }
1052         return trees.toList();
1053     }
1054 
1055    /**
1056     * Returns true iff the compilation will continue after annotation processing
1057     * is done.
1058     */
1059     public boolean continueAfterProcessAnnotations() {
1060         return !shouldStop(CompileState.ATTR);
1061     }
1062 
1063     public List<JCCompilationUnit> initModules(List<JCCompilationUnit> roots) {
1064         modules.initModules(roots);
1065 
1066         if (roots.isEmpty()) {
1067             enterDone();
1068         }
1069         return roots;
1070     }
1071 
1072     /**
1073      * Enter the symbols found in a list of parse trees.
1074      * As a side-effect, this puts elements on the "todo" list.
1075      * Also stores a list of all top level classes in rootClasses.
1076      */
1077     public List<JCCompilationUnit> enterTrees(List<JCCompilationUnit> roots) {
1078         //enter symbols for all files
1079         if (!taskListener.isEmpty()) {
1080             for (JCCompilationUnit unit: roots) {
1081                 TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
1082                 taskListener.started(e);
1083             }
1084         }
1085 

1658 
1659             make.at(Position.FIRSTPOS);
1660             TreeMaker localMake = make.forToplevel(env.toplevel);
1661 
1662             if (env.tree.hasTag(JCTree.Tag.PACKAGEDEF) || env.tree.hasTag(JCTree.Tag.MODULEDEF)) {
1663                 if (!(sourceOutput)) {
1664                     if (shouldStop(CompileState.LOWER))
1665                         return;
1666                     List<JCTree> def = lower.translateTopLevelClass(env, env.tree, localMake);
1667                     if (def.head != null) {
1668                         Assert.check(def.tail.isEmpty());
1669                         results.add(new Pair<>(env, (JCClassDecl)def.head));
1670                     }
1671                 }
1672                 return;
1673             }
1674 
1675             if (shouldStop(CompileState.TRANSTYPES))
1676                 return;
1677 
1678             if (Feature.REFLECT_METHODS.allowedInSource(source)) {
1679                 Optional<CodeReflectionTransformer> reflectMethods = reflectMethods();
1680                 if (reflectMethods.isPresent()) {
1681                     env.tree = reflectMethods.get().translateTopLevelClass(context, env.tree, localMake);
1682                 }
1683             }
1684 
1685             env.tree = transTypes.translateTopLevelClass(env.tree, localMake);
1686             compileStates.put(env, CompileState.TRANSTYPES);
1687 
1688             if (shouldStop(CompileState.TRANSPATTERNS))
1689                 return;
1690 
1691             if (scanner.hasPatterns) {
1692                 env.tree = TransPatterns.instance(context).translateTopLevelClass(env, env.tree, localMake);
1693             }
1694 
1695             compileStates.put(env, CompileState.TRANSPATTERNS);
1696 
1697             if (shouldStop(CompileState.LOWER))
1698                 return;
1699 
1700             if (sourceOutput) {
1701                 //emit standard Java source file, only for compilation
1702                 //units enumerated explicitly on the command line
1703                 JCClassDecl cdef = (JCClassDecl)env.tree;
1704                 if (untranslated instanceof JCClassDecl classDecl &&

1720                     return;
1721 
1722                 for (JCTree def : cdefs) {
1723                     LambdaToMethod.instance(context).translateTopLevelClass(env, def, localMake);
1724                 }
1725                 compileStates.put(env, CompileState.UNLAMBDA);
1726             }
1727 
1728             //generate code for each class
1729             for (List<JCTree> l = cdefs; l.nonEmpty(); l = l.tail) {
1730                 JCClassDecl cdef = (JCClassDecl)l.head;
1731                 results.add(new Pair<>(env, cdef));
1732             }
1733         }
1734         finally {
1735             log.useSource(prev);
1736         }
1737 
1738     }
1739 
1740     Optional<CodeReflectionTransformer> reflectMethods() {
1741         return CodeReflectionSupport.CODE_LAYER != null ?
1742                 ServiceLoader.load(CodeReflectionSupport.CODE_LAYER, CodeReflectionTransformer.class).findFirst() :
1743                 Optional.empty();
1744     }
1745 
1746     public static class CodeReflectionSupport {
1747         public static final ModuleLayer CODE_LAYER;
1748 
1749         static {
1750             if (ModuleLayer.boot().findModule("jdk.incubator.code").isPresent()) {
1751                 // we are in an exploded build, so just use the boot layer
1752                 CODE_LAYER = ModuleLayer.boot();
1753             } else if (java.lang.module.ModuleFinder.ofSystem().find("jdk.incubator.code").isPresent()) {
1754                 // The incubating jdk.incubator.code module is installed, but not in the boot layer
1755                 // The module needs to be resolved so the jdk.compiler module can find and use the service provider
1756                 // for CodeReflectionTransformer
1757                 ModuleLayer parent = ModuleLayer.boot();
1758                 // Create a new configuration from the boot layer configuration with the resolved jdk.incubator.code module
1759                 Configuration cf = parent.configuration()
1760                         .resolve(java.lang.module.ModuleFinder.of(), java.lang.module.ModuleFinder.ofSystem(), Set.of("jdk.incubator.code"));
1761                 ClassLoader scl = ClassLoader.getSystemClassLoader();
1762                 // Create the code module layer using the new configuration and the system class loader
1763                 CODE_LAYER = parent.defineModulesWithOneLoader(cf, scl);
1764                 Module codeReflectionModule = CODE_LAYER.findModule("jdk.incubator.code").get();
1765                 Module jdkCompilerModule = JavaCompiler.class.getModule();
1766                 // Add exports to all jdk.compiler packages so that the jdk.incubator.code module can use them
1767                 for (String packageName : jdkCompilerModule.getPackages()) {
1768                     jdkCompilerModule.addExports(packageName, codeReflectionModule);
1769                 }
1770                 // Add exports to all java.base packages so that the jdk.incubator.code module can use them
1771                 // We need to do so by calling a method in java.base reflectively
1772                 try {
1773                     Class<?> codeModuleLayerInit = Class.forName("jdk.internal.access.code.CodeModuleLayerInit");
1774                     Method initLayerMethod = codeModuleLayerInit.getDeclaredMethod("initCodeModuleLayer", ModuleLayer.class);
1775                     initLayerMethod.invoke(null, CODE_LAYER);
1776                 } catch (ReflectiveOperationException ex) {
1777                     throw new AssertionError(ex);
1778                 }
1779             } else {
1780                 // If we run in bootstrap mode, there might be no jdk.incubator.code
1781                 CODE_LAYER = null;
1782             }
1783         }
1784     }
1785 
1786     /** Generates the source or class file for a list of classes.
1787      * The decision to generate a source file or a class file is
1788      * based upon the compiler's options.
1789      * Generation stops if an error occurs while writing files.
1790      */
1791     public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue) {
1792         generate(queue, null);
1793     }
1794 
1795     public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) {
1796         if (shouldStop(CompileState.GENERATE))
1797             return;
1798 
1799         for (Pair<Env<AttrContext>, JCClassDecl> x: queue) {
1800             Env<AttrContext> env = x.fst;
1801             JCClassDecl cdef = x.snd;
1802 
1803             if (verboseCompilePolicy) {
1804                 printNote("[generate " + (sourceOutput ? " source" : "code") + " " + cdef.sym + "]");
1805             }
< prev index next >