@@ -74,6 +74,8 @@ public DeclaredType declaredType(final TypeElement typeElement,
74
74
75
75
public boolean sameType (final TypeMirror t , final TypeMirror s );
76
76
77
+ public boolean subtype (final TypeMirror t , final TypeMirror s );
78
+
77
79
public TypeElement typeElement (final CharSequence canonicalName );
78
80
79
81
// Note that Elements#getTypeElement(ModuleElement, CharSequence), to which this basically ultimately delegates, says
@@ -91,49 +93,48 @@ public DeclaredType declaredType(final TypeElement typeElement,
91
93
*/
92
94
93
95
94
- public default ArrayType arrayType (final Class <?> c ) {
95
- if (!c .isArray ()) {
96
- throw new IllegalArgumentException ("c: " + c );
97
- }
98
- return this .arrayTypeOf (this .type (c .getComponentType ()));
99
- }
100
-
101
- public default ArrayType arrayType (final GenericArrayType g ) {
102
- return this .arrayTypeOf (this .type (g .getGenericComponentType ()));
96
+ public default ArrayType arrayType (final Type t ) {
97
+ return switch (t ) {
98
+ case null -> throw new NullPointerException ("t" );
99
+ case Class <?> c when c .isArray () -> this .arrayTypeOf (this .type (c .getComponentType ()));
100
+ case GenericArrayType g -> this .arrayTypeOf (this .type (g .getGenericComponentType ()));
101
+ default -> throw new IllegalArgumentException ("t: " + t );
102
+ };
103
103
}
104
104
105
105
public default DeclaredType declaredType (final CharSequence canonicalName ) {
106
106
return this .declaredType (this .typeElement (canonicalName ));
107
107
}
108
108
109
- public default DeclaredType declaredType (final Class <?> c ) {
110
- if (c .isArray () || c .isPrimitive () || c .isLocalClass () || c .isAnonymousClass ()) {
111
- throw new IllegalArgumentException ("c: " + c );
109
+ public default DeclaredType declaredType (final Type t ) {
110
+ return switch (t ) {
111
+ case null -> throw new NullPointerException ("t" );
112
+ case Class <?> c when c .isArray () || c .isPrimitive () || c .isLocalClass () || c .isAnonymousClass ()
113
+ -> throw new IllegalArgumentException ("t: " + t );
114
+ case Class <?> c -> {
115
+ final Class <?> ec = c .getEnclosingClass ();
116
+ yield ec == null ? this .declaredType (this .typeElement (c )) : this .declaredType (this .declaredType (ec ), this .typeElement (c ));
112
117
}
113
- final Class <?> ec = c .getEnclosingClass ();
114
- return this .declaredType (ec == null ? null : this .declaredType (ec ), this .typeElement (c ));
115
- }
116
-
117
- public default DeclaredType declaredType (final ParameterizedType p ) {
118
- return
119
- this .declaredType (switch (p .getOwnerType ()) {
120
- case null -> null ;
121
- case Class <?> c -> this .declaredType (c );
122
- case ParameterizedType pt -> this .declaredType (pt );
123
- default -> throw new IllegalArgumentException ("p: " + p );
124
- },
125
- this .typeElement ((Class <?>)p .getRawType ()),
126
- this .typeArray (p .getActualTypeArguments ()));
118
+ case ParameterizedType p -> this .declaredType (switch (p .getOwnerType ()) {
119
+ case null -> null ;
120
+ case Class <?> c -> this .declaredType (c );
121
+ case ParameterizedType pt -> this .declaredType (pt );
122
+ default -> throw new IllegalArgumentException ("t: " + t );
123
+ },
124
+ this .typeElement (p .getRawType ()),
125
+ this .typeArray (p .getActualTypeArguments ()));
126
+ default -> throw new IllegalArgumentException ("t: " + t );
127
+ };
127
128
}
128
129
129
130
public default Optional <? extends ConstantDesc > describeConstable (final AnnotatedConstruct a ) {
130
131
return switch (a ) {
131
- case null -> Optional .of (NULL );
132
- case Constable c -> c .describeConstable ();
132
+ case null -> Optional .of (NULL );
133
+ case Constable c -> c .describeConstable ();
133
134
case ConstantDesc cd -> Optional .of (cd ); // future proofing
134
- case TypeMirror t -> Optional .empty ();
135
- case Element e -> Optional .empty ();
136
- default -> throw new IllegalArgumentException ("a: " + a );
135
+ case TypeMirror t -> Optional .empty ();
136
+ case Element e -> Optional .empty ();
137
+ default -> throw new IllegalArgumentException ("a: " + a );
137
138
};
138
139
}
139
140
@@ -146,16 +147,17 @@ public default PrimitiveType primitiveType(final Class<?> c) {
146
147
147
148
public default TypeMirror type (final Type t ) {
148
149
return switch (t ) {
149
- case null -> throw new NullPointerException ();
150
- case Class <?> c when c == void .class -> this .noType (TypeKind .VOID );
151
- case Class <?> c when c .isArray () -> this .arrayType (c );
152
- case Class <?> c when c .isPrimitive () -> this .primitiveType (c );
153
- case Class <?> c -> this .declaredType (c );
154
- case ParameterizedType p -> this .declaredType (p );
155
- case GenericArrayType g -> this .arrayType (g );
156
- case java .lang .reflect .TypeVariable <?> tv -> this .typeVariable (tv );
157
- case java .lang .reflect .WildcardType w -> this .wildcardType (w );
158
- default -> throw new IllegalArgumentException ("t: " + t );
150
+ case null -> throw new NullPointerException ();
151
+ case Class <?> c when c == void .class -> this .noType (TypeKind .VOID );
152
+ case Class <?> c when c .isArray () -> this .arrayType (c );
153
+ case Class <?> c when c .isPrimitive () -> this .primitiveType (c );
154
+ case Class <?> c when c .isLocalClass () || c .isAnonymousClass () -> throw new IllegalArgumentException ("t: " + t );
155
+ case Class <?> c -> this .declaredType (c );
156
+ case ParameterizedType p -> this .declaredType (p );
157
+ case GenericArrayType g -> this .arrayType (g );
158
+ case java .lang .reflect .TypeVariable <?> tv -> this .typeVariable (tv );
159
+ case java .lang .reflect .WildcardType w -> this .wildcardType (w );
160
+ default -> throw new IllegalArgumentException ("t: " + t );
159
161
};
160
162
}
161
163
@@ -167,11 +169,15 @@ public default TypeMirror[] typeArray(final Type[] ts) {
167
169
return rv ;
168
170
}
169
171
170
- public default TypeElement typeElement (final Class <?> c ) {
171
- if (c .isArray () || c .isPrimitive () || c .isLocalClass () || c .isAnonymousClass ()) {
172
- throw new IllegalArgumentException ("c: " + c );
173
- }
174
- return this .typeElement (c .getCanonicalName ());
172
+ public default TypeElement typeElement (final Type t ) {
173
+ return switch (t ) {
174
+ case null -> throw new NullPointerException ("t" );
175
+ case Class <?> c when c .isArray () || c .isPrimitive () || c .isLocalClass () || c .isAnonymousClass ()
176
+ -> throw new IllegalArgumentException ("t: " + t );
177
+ case Class <?> c -> this .typeElement (c .getCanonicalName ());
178
+ case ParameterizedType p -> this .typeElement (p .getRawType ());
179
+ default -> throw new IllegalArgumentException ("t: " + t );
180
+ };
175
181
}
176
182
177
183
public default WildcardType wildcardType (final java .lang .reflect .WildcardType t ) {
0 commit comments