2020
2121import java .lang .annotation .Annotation ;
2222import java .lang .reflect .AnnotatedType ;
23- import java .lang .reflect .Array ;
2423import java .lang .reflect .GenericArrayType ;
2524import java .lang .reflect .Type ;
2625import java .util .Arrays ;
@@ -53,14 +52,29 @@ public final class ReflectiveJvmType implements JvmType {
5352 private final Boolean nullable ;
5453 private int cachedHashCode ;
5554
55+ /**
56+ * Use for a bare raw class with no generics, annotations, or nullability information.
57+ * This is the common case for constants and simple value types (e.g. {@code String.class}).
58+ */
5659 public ReflectiveJvmType (Class <?> rawType ) {
5760 this (rawType , Collections .emptyList (), Collections .emptyList ());
5861 }
5962
63+ /**
64+ * Use when the raw class plus its generics and annotations are known but nullability is not
65+ * (nullability defaults to {@code null}, meaning "unknown").
66+ * The component type is derived automatically: for an array raw type, {@code typeVariables}
67+ * are treated as the component type's generics.
68+ */
6069 public ReflectiveJvmType (Class <?> rawType , List <? extends JvmType > typeVariables , List <Annotation > annotations ) {
6170 this (rawType , typeVariables , annotations , deriveComponentType (rawType , typeVariables ), null );
6271 }
6372
73+ /**
74+ * Use when the raw class, generics, annotations, and an explicit nullability are all known.
75+ * The component type is derived automatically, as in
76+ * {@link #ReflectiveJvmType(Class, List, List)}.
77+ */
6478 public ReflectiveJvmType (
6579 Class <?> rawType ,
6680 List <? extends JvmType > typeVariables ,
@@ -70,6 +84,12 @@ public ReflectiveJvmType(
7084 this (rawType , typeVariables , annotations , deriveComponentType (rawType , typeVariables ), nullable );
7185 }
7286
87+ /**
88+ * Canonical constructor that all other {@code Class}-based constructors delegate to.
89+ * Use when the component type must be supplied explicitly rather than derived — for
90+ * example, to preserve a container or array element type taken from an existing
91+ * {@link JvmType} (see {@code SingleElementProperty}).
92+ */
7393 public ReflectiveJvmType (
7494 Class <?> rawType ,
7595 List <? extends JvmType > typeVariables ,
@@ -84,11 +104,16 @@ public ReflectiveJvmType(
84104 this .nullable = nullable ;
85105 }
86106
107+ /**
108+ * Use when building from a reflection-backed type reference. Resolves wildcards to their
109+ * upper bound and derives the raw type, generics, annotations, and component type from the
110+ * JDK {@link AnnotatedType}.
111+ */
87112 public ReflectiveJvmType (ObjectTypeReference <?> typeReference ) {
88113 AnnotatedType originalType = typeReference .getAnnotatedType ();
89114 // Resolve wildcard types to their upper bound
90115 AnnotatedType resolvedType = Types .resolveWildcardType (originalType );
91- this .rawType = resolveRawType (resolvedType );
116+ this .rawType = Types . getActualType (resolvedType );
92117 this .typeVariables = Types .getGenericsTypes (resolvedType ).stream ()
93118 .map (annotatedType -> new ReflectiveJvmType (Types .toTypeReference (annotatedType )))
94119 .collect (Collectors .toList ());
@@ -98,17 +123,6 @@ public ReflectiveJvmType(ObjectTypeReference<?> typeReference) {
98123 this .nullable = null ;
99124 }
100125
101- private static Class <?> resolveRawType (AnnotatedType annotatedType ) {
102- Type type = annotatedType .getType ();
103- if (type instanceof GenericArrayType ) {
104- // For GenericArrayType, we need the array class, not the component class
105- GenericArrayType genericArrayType = (GenericArrayType )type ;
106- Class <?> componentClass = Types .getActualType (genericArrayType .getGenericComponentType ());
107- return Array .newInstance (componentClass , 0 ).getClass ();
108- }
109- return Types .getActualType (annotatedType );
110- }
111-
112126 @ Nullable
113127 private static JvmType resolveComponentType (AnnotatedType annotatedType , Class <?> rawType ) {
114128 Type type = annotatedType .getType ();
0 commit comments