[code-reflection] RFR: Enhance JavaType::type to deal with inner classes [v2]
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Jun 18 10:14:32 UTC 2025
> In some cases, the `JavaType::type(Type)` factory loses information about enclosing/enclosed type.
> This is due to the fact that, when the type in question contains some generic parameterization, the enclosing/enclosed relationship is reified in the `ParameterizedType` class.
> However, if the type is non-generic, it is modelled as a simple `Class` -- and the enclosing/enclosed relationship is lost.
>
> This PR enhances the factory to recover the enclosing type using the reflective information available:
> * the class is a non-static member class. The enclosing type is the class in which the class is declared
> * the class is a local class, defined in a method `m`. If `m` is non-static, the enclosing type is the class declaring `m`
> * the class is a local class, defined in a constructor of class `C`. The enclosing type is `C`
> * otherwise, there's no enclosing type.
>
> Note that there are some [known pathological cases](https://bugs.openjdk.org/browse/JDK-8162500) where the enclosing class information cannot be reconstructed from the information we have available in the bytecode, but this should not be a big issue for the time being.
Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
Add test for deeply nested member classes
-------------
Changes:
- all: https://git.openjdk.org/babylon/pull/443/files
- new: https://git.openjdk.org/babylon/pull/443/files/f9c613b4..043a3fd5
Webrevs:
- full: https://webrevs.openjdk.org/?repo=babylon&pr=443&range=01
- incr: https://webrevs.openjdk.org/?repo=babylon&pr=443&range=00-01
Stats: 19 lines in 1 file changed: 18 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/babylon/pull/443.diff
Fetch: git fetch https://git.openjdk.org/babylon.git pull/443/head:pull/443
PR: https://git.openjdk.org/babylon/pull/443
More information about the babylon-dev
mailing list