[code-reflection] RFR: Improve JavaType::toString
Paul Sandoz
psandoz at openjdk.org
Fri May 31 22:09:24 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) ?
Alignment with `Type.toString` is very useful for runtime debugging. I think we should remove `ClassType.toClassName`. We should probably rename the `JavaType.ofString` method to avoid confusion.
It occurred to me that the externalized form of a qualified class does not have to duplicate if that helps debugging via code models, we could have:
.<Outer<java.lang.String>, Inner<java.lang.Integer>>
Or even:
$<Outer<java.lang.String>, Inner<java.lang.Integer>>
-------------
Marked as reviewed by psandoz (Lead).
PR Review: https://git.openjdk.org/babylon/pull/110#pullrequestreview-2091772849
More information about the babylon-dev
mailing list