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 20:49:54 UTC 2023
On Thu, 27 Apr 2023 18:28:41 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:
>> 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.
>
> The source file name is not available until after parsing.
I see that logic in JavaCompiler - I wonder if that's just the way it is, or if there's a deeper reason as to why the sourcefile is set on the toplevel unit *after* parsing (I don't think I can see any, in which case that might be changed if that makes the rest of the code simpler). @lahodaj what do you think?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1179650628
More information about the compiler-dev
mailing list