[code-reflection] RFR: Enhance JavaType::type to deal with inner classes

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Jun 17 14:59:30 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.

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

Commit messages:
 - Enhance JavaType::type to deal with inner classes

Changes: https://git.openjdk.org/babylon/pull/443/files
  Webrev: https://webrevs.openjdk.org/?repo=babylon&pr=443&range=00
  Stats: 55 lines in 2 files changed: 55 ins; 0 del; 0 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