RFR: JDK-8306112 Implementation of JEP 445: Flexible Main Methods and Anonymous Main Classes (Preview) [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Apr 27 15:10:23 UTC 2023

On Thu, 27 Apr 2023 13:17:58 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:

>> Add flexible main methods and anonymous main classes to the Java language.
> Jim Laskey has updated the pull request incrementally with one additional commit since the last revision:
>   PreviewFeatures.isEnabled()

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java line 432:

> 430: 
> 431:     // Restructure top level to be an top level anonymous class.
> 432:     public static void constructAnonymousMainClass(JCCompilationUnit tree,

Question: any reason as to why this is done here and not in the parser? Typically we don't want to do tree transformation at parse time, as that messes up clients that want to access the "non-desugared" tree (such as IDE) and expect some mapping between source to AST. But if you do the rewriting in Enter, not much changes, that is, clients such as IDEs would still see something that doesn't resemble the source.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java line 2433:

> 2431:         if (kind.contains(KindSelector.TYP)) {
> 2432:             sym = findType(env, name);
> 2433:             if ((sym.flags() & ANONYMOUS_MAIN_CLASS) != 0) {

If `sym` is also `SYNTHTIC` (which it is) - do you need this? In what case? E.g. if there's a legitimate case for this I'm wondering if we should just test for `SYNTHETIC` rather than `ANONYMOUS_MAIN_CLASS`.

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/VirtualParser.java line 191:

> 189:      * @param <E> return type of parserAction
> 190:      */
> 191:     public static <E> Optional<E> speculativeParse(JavacParser parser,

Since this is never use, and because of the TODO - should we just drop it for the time being?


PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1179286118
PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1179288860
PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1179292509

More information about the compiler-dev mailing list