@@ -207,7 +207,7 @@ public ResolvedType resolve(TypeBindings typeBindings, Type jdkType)
207
207
* @throws IllegalArgumentException If this type can be extended in general, but not into specified sub-class
208
208
* @throws UnsupportedOperationException If this type can not be sub-classed
209
209
*/
210
- public ResolvedType resolveSubtype (ResolvedType supertype , Class <?> subtype )
210
+ public ResolvedType resolveSubtype (ResolvedType supertype , final Class <?> subtype )
211
211
throws IllegalArgumentException , UnsupportedOperationException
212
212
{
213
213
// first: if it's a recursive reference, find out referred-to type
@@ -216,15 +216,15 @@ public ResolvedType resolveSubtype(ResolvedType supertype, Class<?> subtype)
216
216
supertype = refType ;
217
217
}
218
218
// Then, trivial check for case where subtype is supertype...
219
- if (supertype .getErasedType () == subtype ) {
219
+ final Class <?> superclass = supertype .getErasedType ();
220
+ if (superclass == subtype ) { // unlikely but cheap check so let's just do it
220
221
return supertype ;
221
222
}
222
-
223
+ // First: can not sub-class primitives, or array types
223
224
if (!supertype .canCreateSubtypes ()) {
224
225
throw new UnsupportedOperationException ("Can not subtype primitive or array types (type " +supertype .getFullDescription ()+")" );
225
226
}
226
- // In general, must be able to subtype as per JVM rules:
227
- Class <?> superclass = supertype .getErasedType ();
227
+ // And in general must be able to subtype as per JVM rules:
228
228
if (!superclass .isAssignableFrom (subtype )) {
229
229
throw new IllegalArgumentException ("Can not sub-class " +supertype .getBriefDescription ()
230
230
+" into " +subtype .getName ());
@@ -257,18 +257,18 @@ public ResolvedType resolveSubtype(ResolvedType supertype, Class<?> subtype)
257
257
resolvedSubtype = _fromClass (null , subtype ,
258
258
TypeBindings .create (subtype , resolvedParams ));
259
259
}
260
- ResolvedType rawSupertype = resolvedSubtype .findSupertype (superclass );
261
- if (rawSupertype == null ) { // sanity check, should never occur
260
+ ResolvedType resolvedSupertype = resolvedSubtype .findSupertype (superclass );
261
+ if (resolvedSupertype == null ) { // sanity check, should never occur
262
262
throw new IllegalArgumentException ("Internal error: unable to locate supertype (" +subtype .getName ()+") for type " +supertype .getBriefDescription ());
263
263
}
264
264
// Ok, then, let's find and verify type assignments
265
- _resolveTypePlaceholders (supertype , rawSupertype );
265
+ _resolveTypePlaceholders (supertype , resolvedSupertype );
266
266
// And then re-construct, if necessary
267
267
if (paramCount == 0 ) { // if no type parameters, fine as is
268
268
return resolvedSubtype ;
269
269
}
270
270
// but with type parameters, need to reconstruct
271
- ResolvedType [] typeParams = new ResolvedType [paramCount ];
271
+ final ResolvedType [] typeParams = new ResolvedType [paramCount ];
272
272
for (int i = 0 ; i < paramCount ; ++i ) {
273
273
ResolvedType t = placeholders [i ].actualType ();
274
274
// Is it ok for it to be left unassigned? For now let's not allow that
@@ -515,11 +515,14 @@ private ResolvedType _fromVariable(ClassStack context, TypeVariable<?> variable,
515
515
/**
516
516
* Method called to verify that types match; and if there are any placeholders,
517
517
* replace them in <code>actualType</code>.
518
+ *
519
+ * @param sourceType Original base type used for specification/refinement
520
+ * @param actualType Base type instance after re-resolving, possibly containing type placeholders
518
521
*/
519
- private void _resolveTypePlaceholders (ResolvedType expectedType , ResolvedType actualType )
522
+ private void _resolveTypePlaceholders (ResolvedType sourceType , ResolvedType actualType )
520
523
throws IllegalArgumentException
521
524
{
522
- List <ResolvedType > expectedTypes = expectedType .getTypeParameters ();
525
+ List <ResolvedType > expectedTypes = sourceType .getTypeParameters ();
523
526
List <ResolvedType > actualTypes = actualType .getTypeParameters ();
524
527
for (int i = 0 , len = expectedTypes .size (); i < len ; ++i ) {
525
528
ResolvedType exp = expectedTypes .get (i );
0 commit comments