[code-reflection] RFR: Improve resolution of types in `CodeModelToAST`

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Apr 10 11:43:29 UTC 2025


On Thu, 10 Apr 2025 11:37:16 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> The `CodeModelToAST` class features an ad-hoc table of types, which is hard-wired to include all the types that can come up in the code model generated by `OpBuilder`.
> This approach is fragile (if new types are relied upon by `OpBuilder`, they need to be added there), and duplicates type resolution tables that javac has to maintain anyway.
> 
> This PR replaces the ad-hoc type table with more idiomatic javac type lookup logic.

src/jdk.incubator.code/share/classes/jdk/incubator/code/internal/CodeModelToAST.java line 62:

> 60:                 yield new Type.ClassType(enclosing, typeArgs, typeElementToType(ct.rawType()).tsym);
> 61:             }
> 62:             case ClassType ct -> types.erasure(syms.enterClass(attrEnv.toplevel.modle, ct.toClassName()));

note: the module passed here `attrEnv.toplevel.modle` is *not* the module the type we are looking for belongs to. It is the module of the current compilation unit -- in other words, this module is used to determine which packages are visible from the compilation unit.

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/391#discussion_r2037149944


More information about the babylon-dev mailing list