[code-reflection] RFR: Improve JavaType::toString

Maurizio Cimadamore mcimadamore at openjdk.org
Fri May 31 21:06:26 UTC 2024


The string representation of `JavaType` is automatically derived from the type's externalized form. This PR tweaks the implementation of `toString` so that a more meaningful representation is generated, namely one that is consistent with `java.lang.reflect.Type::getTypeName`.

For instance, instead of this:


 .<Outer<java.lang.String>, Outer$Inner<java.lang.Integer>>


This is now generated:


Outer<java.lang.String>$Inner<java.lang.Integer>


I've added another combinatorial test which checks that `Type::getTypeName` of the resolved reflective type matches the string representation of the original `JavaType`.

The main question is around `ClassType::toClassName`. This method is effectively attempting to generate a user-friendly type string from the `JavaType` (note that this method doesn't take into account enclosing types). Should we update this to call `toString` ? Or should we perhaps remove it, and ask clients to use `toString` instead (which now works on all types) ?

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

Commit messages:
 - Initial push

Changes: https://git.openjdk.org/babylon/pull/110/files
  Webrev: https://webrevs.openjdk.org/?repo=babylon&pr=110&range=00
  Stats: 36 lines in 7 files changed: 29 ins; 0 del; 7 mod
  Patch: https://git.openjdk.org/babylon/pull/110.diff
  Fetch: git fetch https://git.openjdk.org/babylon.git pull/110/head:pull/110

PR: https://git.openjdk.org/babylon/pull/110


More information about the babylon-dev mailing list