14
14
import org .hibernate .models .internal .util .CollectionHelper ;
15
15
16
16
/**
17
+ * Helper utilities for dealing with {@linkplain TypeDetails}
18
+ *
17
19
* @author Steve Ebersole
18
20
*/
19
21
public class TypeDetailsHelper {
22
+ /**
23
+ * Given an attribute member type and a concrete container type, resolve the type of
24
+ * the attribute relative to that container.
25
+ * <p/>
26
+ * For example, consider
27
+ * <pre class="brush:java">
28
+ * class {@code Item<T>} {
29
+ * T id;
30
+ * }
31
+ * class Hat extends {@code Item<Integer} {
32
+ * ...
33
+ * }
34
+ * </pre>
35
+ * Given this model, a call to resolve the type of {@code id} relative to {@code Hat}
36
+ * will return {@code ClassTypeDetails(Integer)}. A call to resolve the type of {@code id}
37
+ * relative to {@code Item} returns {@code ParameterizedTypeDetails(T)} (roughly Object)
38
+ */
39
+ @ SuppressWarnings ("RedundantLabeledSwitchRuleCodeBlock" )
20
40
public static TypeDetails resolveRelativeType (TypeDetails type , TypeDetails container ) {
21
41
switch ( type .getTypeKind () ) {
22
42
case CLASS , PRIMITIVE , VOID , ARRAY -> {
@@ -67,6 +87,10 @@ public static TypeVariableDetails findTypeVariableDetails2(String identifier, Li
67
87
return null ;
68
88
}
69
89
90
+ /**
91
+ * Overload of {@linkplain #resolveRelativeType(TypeDetails, TypeDetails)}
92
+ */
93
+ @ SuppressWarnings ("RedundantLabeledSwitchRuleCodeBlock" )
70
94
public static TypeDetails resolveRelativeType (TypeDetails memberType , ClassDetails containerType ) {
71
95
switch ( memberType .getTypeKind () ) {
72
96
case CLASS , PRIMITIVE , VOID , ARRAY -> {
@@ -91,6 +115,12 @@ public static TypeDetails resolveRelativeType(TypeDetails memberType, ClassDetai
91
115
}
92
116
}
93
117
118
+ /**
119
+ * Very much the same as {@linkplain #resolveRelativeType(TypeDetails, TypeDetails)}, except that
120
+ * here we resolve the relative type to the corresponding {@link ClassBasedTypeDetails} which
121
+ * gives easy access to the type's {@linkplain ClassBasedTypeDetails#getClassDetails() ClassDetails}
122
+ */
123
+ @ SuppressWarnings ("RedundantLabeledSwitchRuleCodeBlock" )
94
124
public static ClassBasedTypeDetails resolveRelativeClassType (TypeDetails memberType , TypeDetails containerType ) {
95
125
switch ( memberType .getTypeKind () ) {
96
126
case CLASS , PRIMITIVE , VOID , ARRAY -> {
@@ -121,20 +151,24 @@ else if ( typeDetails.getTypeKind() == TypeDetails.Kind.TYPE_VARIABLE ) {
121
151
}
122
152
}
123
153
case TYPE_VARIABLE_REFERENCE -> {
124
- throw new UnsupportedOperationException ( "TypeVariableReferenceDetails not supported for relative type resolution" );
154
+ throw new UnsupportedOperationException ( "TypeVariableReferenceDetails not supported for relative class resolution" );
125
155
}
126
156
case PARAMETERIZED_TYPE -> {
127
- throw new UnsupportedOperationException ( "ParameterizedTypeDetails not supported for relative type resolution" );
157
+ throw new UnsupportedOperationException ( "ParameterizedTypeDetails not supported for relative class resolution" );
128
158
}
129
159
case WILDCARD_TYPE -> {
130
- throw new UnsupportedOperationException ( "WildcardTypeDetails not supported for relative type resolution" );
160
+ throw new UnsupportedOperationException ( "WildcardTypeDetails not supported for relative class resolution" );
131
161
}
132
162
default -> {
133
163
throw new UnsupportedOperationException ( "Unknown TypeDetails kind - " + memberType .getTypeKind () );
134
164
}
135
165
}
136
166
}
137
167
168
+ /**
169
+ * Overload form of {@linkplain #resolveRelativeClassType(TypeDetails, TypeDetails)}
170
+ */
171
+ @ SuppressWarnings ("RedundantLabeledSwitchRuleCodeBlock" )
138
172
public static ClassBasedTypeDetails resolveRelativeClassType (TypeDetails memberType , ClassDetails containerType ) {
139
173
switch ( memberType .getTypeKind () ) {
140
174
case CLASS , PRIMITIVE , VOID , ARRAY -> {
@@ -179,9 +213,12 @@ else if ( typeDetails.getTypeKind() == TypeDetails.Kind.TYPE_VARIABLE ) {
179
213
}
180
214
}
181
215
216
+ /**
217
+ * Given a type, resolve the underlying ClassDetails
218
+ */
182
219
public static ClassDetails resolveRawClass (
183
220
TypeDetails typeDetails ,
184
- SourceModelBuildingContext buildingContext ) {
221
+ @ SuppressWarnings ( "unused" ) SourceModelBuildingContext buildingContext ) {
185
222
switch ( typeDetails .getTypeKind () ) {
186
223
case CLASS , PRIMITIVE , VOID , ARRAY -> {
187
224
return ( (ClassBasedTypeDetails ) typeDetails ).getClassDetails ();
@@ -206,6 +243,9 @@ public static ClassDetails resolveRawClass(
206
243
return ClassDetails .OBJECT_CLASS_DETAILS ;
207
244
}
208
245
246
+ /**
247
+ * Make an array type of the given component type
248
+ */
209
249
public static ArrayTypeDetails arrayOf (TypeDetails constituentType , SourceModelBuildingContext buildingContext ) {
210
250
final ClassDetails arrayClassDetails ;
211
251
if ( constituentType .getTypeKind () == TypeDetails .Kind .PRIMITIVE ) {
0 commit comments