< 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 static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
  99 
 100 import static javax.tools.StandardLocation.CLASS_OUTPUT;
 101 import static javax.tools.StandardLocation.ANNOTATION_PROCESSOR_PATH;
 102 
 103 import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
 104 import com.sun.tools.javac.tree.JCTree.JCRecordPattern;
 105 import com.sun.tools.javac.tree.JCTree.JCSwitch;
 106 import com.sun.tools.javac.tree.JCTree.JCSwitchExpression;
 107 
 108 /** This class could be the main entry point for GJC when GJC is used as a
 109  *  component in a larger software system. It provides operations to

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







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

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

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

1453      * Check for various things to warn about in an attributed parse tree.
1454      */
1455     protected void warn(Env<AttrContext> env, Queue<Env<AttrContext>> results) {
1456         if (compileStates.isDone(env, CompileState.WARN)) {
1457             results.add(env);
1458             return;
1459         }
1460 
1461         if (shouldStop(CompileState.WARN))
1462             return;
1463 
1464         if (verboseCompilePolicy)
1465             printNote("[warn " + env.enclClass.sym + "]");
1466         JavaFileObject prev = log.useSource(
1467                                             env.enclClass.sym.sourcefile != null ?
1468                                             env.enclClass.sym.sourcefile :
1469                                             env.toplevel.sourcefile);
1470         try {
1471             warningAnalyzer.analyzeTree(env);
1472             compileStates.put(env, CompileState.WARN);












1473             results.add(env);
1474         }
1475         finally {
1476             log.useSource(prev);
1477         }
1478     }
1479 
1480     private TaskEvent newAnalyzeTaskEvent(Env<AttrContext> env) {
1481         JCCompilationUnit toplevel = env.toplevel;
1482         ClassSymbol sym;
1483         if (env.enclClass.sym == syms.predefClass) {
1484             if (TreeInfo.isModuleInfo(toplevel)) {
1485                 sym = toplevel.modle.module_info;
1486             } else if (TreeInfo.isPackageInfo(toplevel)) {
1487                 sym = toplevel.packge.package_info;
1488             } else {
1489                 throw new IllegalStateException("unknown env.toplevel");
1490             }
1491         } else {
1492             sym = env.enclClass.sym;

1691                     return;
1692 
1693                 for (JCTree def : cdefs) {
1694                     LambdaToMethod.instance(context).translateTopLevelClass(env, def, localMake);
1695                 }
1696                 compileStates.put(env, CompileState.UNLAMBDA);
1697             }
1698 
1699             //generate code for each class
1700             for (List<JCTree> l = cdefs; l.nonEmpty(); l = l.tail) {
1701                 JCClassDecl cdef = (JCClassDecl)l.head;
1702                 results.add(new Pair<>(env, cdef));
1703             }
1704         }
1705         finally {
1706             log.useSource(prev);
1707         }
1708 
1709     }
1710 














































1711     /** Generates the source or class file for a list of classes.
1712      * The decision to generate a source file or a class file is
1713      * based upon the compiler's options.
1714      * Generation stops if an error occurs while writing files.
1715      */
1716     public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue) {
1717         generate(queue, null);
1718     }
1719 
1720     public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) {
1721         if (shouldStop(CompileState.GENERATE))
1722             return;
1723 
1724         for (Pair<Env<AttrContext>, JCClassDecl> x: queue) {
1725             Env<AttrContext> env = x.fst;
1726             JCClassDecl cdef = x.snd;
1727 
1728             if (verboseCompilePolicy) {
1729                 printNote("[generate " + (sourceOutput ? " source" : "code") + " " + cdef.sym + "]");
1730             }

   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 static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
 105 
 106 import static javax.tools.StandardLocation.CLASS_OUTPUT;
 107 import static javax.tools.StandardLocation.ANNOTATION_PROCESSOR_PATH;
 108 
 109 import com.sun.tools.javac.tree.JCTree.JCModuleDecl;
 110 import com.sun.tools.javac.tree.JCTree.JCRecordPattern;
 111 import com.sun.tools.javac.tree.JCTree.JCSwitch;
 112 import com.sun.tools.javac.tree.JCTree.JCSwitchExpression;
 113 
 114 /** This class could be the main entry point for GJC when GJC is used as a
 115  *  component in a larger software system. It provides operations to

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

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

1467      * Check for various things to warn about in an attributed parse tree.
1468      */
1469     protected void warn(Env<AttrContext> env, Queue<Env<AttrContext>> results) {
1470         if (compileStates.isDone(env, CompileState.WARN)) {
1471             results.add(env);
1472             return;
1473         }
1474 
1475         if (shouldStop(CompileState.WARN))
1476             return;
1477 
1478         if (verboseCompilePolicy)
1479             printNote("[warn " + env.enclClass.sym + "]");
1480         JavaFileObject prev = log.useSource(
1481                                             env.enclClass.sym.sourcefile != null ?
1482                                             env.enclClass.sym.sourcefile :
1483                                             env.toplevel.sourcefile);
1484         try {
1485             warningAnalyzer.analyzeTree(env);
1486             compileStates.put(env, CompileState.WARN);
1487             // Run ReflectMethods here to ensure that it always runs before TransTypes,
1488             // even when TransTypes recursively translates classes from other compilation units
1489             if (!shouldStop(CompileState.TRANSTYPES)
1490                     && env.tree.hasTag(JCTree.Tag.CLASSDEF)
1491                     && (implicitSourcePolicy != ImplicitSourcePolicy.NONE || inputFiles.contains(env.toplevel.sourcefile))
1492                     && (modules.multiModuleMode || env.toplevel.modle == modules.getDefaultModule())
1493                     && Feature.REFLECT_METHODS.allowedInSource(source)) {
1494                 Optional<CodeReflectionTransformer> reflectMethods = reflectMethods();
1495                 if (reflectMethods.isPresent()) {
1496                     env.tree = reflectMethods.get().translateTopLevelClass(context, env.tree, make.forToplevel(env.toplevel));
1497                 }
1498             }
1499             results.add(env);
1500         }
1501         finally {
1502             log.useSource(prev);
1503         }
1504     }
1505 
1506     private TaskEvent newAnalyzeTaskEvent(Env<AttrContext> env) {
1507         JCCompilationUnit toplevel = env.toplevel;
1508         ClassSymbol sym;
1509         if (env.enclClass.sym == syms.predefClass) {
1510             if (TreeInfo.isModuleInfo(toplevel)) {
1511                 sym = toplevel.modle.module_info;
1512             } else if (TreeInfo.isPackageInfo(toplevel)) {
1513                 sym = toplevel.packge.package_info;
1514             } else {
1515                 throw new IllegalStateException("unknown env.toplevel");
1516             }
1517         } else {
1518             sym = env.enclClass.sym;

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