[code-reflection] RFR: Improve JavaType::toString
Maurizio Cimadamore
mcimadamore at openjdk.org
Tue Jun 4 17:58:21 UTC 2024
On Fri, 31 May 2024 21:00:04 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> 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) ?
Given what has been discussed here, I would propose to keep this PR as is, then:
* in a different PR, rename occurrences of `ofString` to `ofExternalizedString`
* keep mulling over `toClassName`, maybe rewrite it to what I suggested (e.g. compute the "real" class name)
-------------
PR Comment: https://git.openjdk.org/babylon/pull/110#issuecomment-2148098103
More information about the babylon-dev
mailing list