Skip to content

Commit 092b38b

Browse files
committed
Yet another simplification, adding comments, improved naming
1 parent 50b74b2 commit 092b38b

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/main/java/com/fasterxml/classmate/TypeResolver.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public ResolvedType resolve(TypeBindings typeBindings, Type jdkType)
207207
* @throws IllegalArgumentException If this type can be extended in general, but not into specified sub-class
208208
* @throws UnsupportedOperationException If this type can not be sub-classed
209209
*/
210-
public ResolvedType resolveSubtype(ResolvedType supertype, Class<?> subtype)
210+
public ResolvedType resolveSubtype(ResolvedType supertype, final Class<?> subtype)
211211
throws IllegalArgumentException, UnsupportedOperationException
212212
{
213213
// first: if it's a recursive reference, find out referred-to type
@@ -216,15 +216,15 @@ public ResolvedType resolveSubtype(ResolvedType supertype, Class<?> subtype)
216216
supertype = refType;
217217
}
218218
// 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
220221
return supertype;
221222
}
222-
223+
// First: can not sub-class primitives, or array types
223224
if (!supertype.canCreateSubtypes()) {
224225
throw new UnsupportedOperationException("Can not subtype primitive or array types (type "+supertype.getFullDescription()+")");
225226
}
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:
228228
if (!superclass.isAssignableFrom(subtype)) {
229229
throw new IllegalArgumentException("Can not sub-class "+supertype.getBriefDescription()
230230
+" into "+subtype.getName());
@@ -257,18 +257,18 @@ public ResolvedType resolveSubtype(ResolvedType supertype, Class<?> subtype)
257257
resolvedSubtype = _fromClass(null, subtype,
258258
TypeBindings.create(subtype, resolvedParams));
259259
}
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
262262
throw new IllegalArgumentException("Internal error: unable to locate supertype ("+subtype.getName()+") for type "+supertype.getBriefDescription());
263263
}
264264
// Ok, then, let's find and verify type assignments
265-
_resolveTypePlaceholders(supertype, rawSupertype);
265+
_resolveTypePlaceholders(supertype, resolvedSupertype);
266266
// And then re-construct, if necessary
267267
if (paramCount == 0) { // if no type parameters, fine as is
268268
return resolvedSubtype;
269269
}
270270
// but with type parameters, need to reconstruct
271-
ResolvedType[] typeParams = new ResolvedType[paramCount];
271+
final ResolvedType[] typeParams = new ResolvedType[paramCount];
272272
for (int i = 0; i < paramCount; ++i) {
273273
ResolvedType t = placeholders[i].actualType();
274274
// 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,
515515
/**
516516
* Method called to verify that types match; and if there are any placeholders,
517517
* 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
518521
*/
519-
private void _resolveTypePlaceholders(ResolvedType expectedType, ResolvedType actualType)
522+
private void _resolveTypePlaceholders(ResolvedType sourceType, ResolvedType actualType)
520523
throws IllegalArgumentException
521524
{
522-
List<ResolvedType> expectedTypes = expectedType.getTypeParameters();
525+
List<ResolvedType> expectedTypes = sourceType.getTypeParameters();
523526
List<ResolvedType> actualTypes = actualType.getTypeParameters();
524527
for (int i = 0, len = expectedTypes.size(); i < len; ++i) {
525528
ResolvedType exp = expectedTypes.get(i);

0 commit comments

Comments
 (0)