private ResolvedType _fromParamType(ClassStack context, ParameterizedType ptype, TypeBindings parentBindings) { /* First: what is the actual base type? One odd thing is that 'getRawType' * returns Type, not Class<?> as one might expect. But let's assume it is * always of type Class: if not, need to add more code to resolve it... */ Class<?> rawType = (Class<?>) ptype.getRawType(); Type[] params = ptype.getActualTypeArguments(); int len = params.length; ResolvedType[] types = new ResolvedType[len]; for (int i = 0; i < len; ++i) { types[i] = _fromAny(context, params[i], parentBindings); } // Ok: this gives us current bindings for this type: TypeBindings newBindings = TypeBindings.create(rawType, types); return _fromClass(context, rawType, newBindings); }
private ResolvedType _fromParamType(ClassStack context, ParameterizedType ptype, TypeBindings parentBindings) { /* First: what is the actual base type? One odd thing is that 'getRawType' * returns Type, not Class<?> as one might expect. But let's assume it is * always of type Class: if not, need to add more code to resolve it... */ Class<?> rawType = (Class<?>) ptype.getRawType(); Type[] params = ptype.getActualTypeArguments(); int len = params.length; ResolvedType[] types = new ResolvedType[len]; for (int i = 0; i < len; ++i) { types[i] = _fromAny(context, params[i], parentBindings); } // Ok: this gives us current bindings for this type: TypeBindings newBindings = TypeBindings.create(rawType, types); return _fromClass(context, rawType, newBindings); }
/** * Factory method for resolving given generic type, defined by using sub-class * instance of {@link GenericType} */ private ResolvedType _fromGenericType(ClassStack context, GenericType<?> generic, TypeBindings typeBindings) { /* To allow multiple levels of inheritance (just in case someone * wants to go to town with inheritance of GenericType), * we better resolve the whole thing; then dig out * type parameterization... */ ResolvedType type = _fromClass(context, generic.getClass(), typeBindings); ResolvedType genType = type.findSupertype(GenericType.class); if (genType == null) { // sanity check; shouldn't occur throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); } TypeBindings b = genType.getTypeBindings(); ResolvedType[] params = b.typeParameterArray(); if (params.length == 0) { throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); } return params[0]; }
/** * Factory method for resolving given generic type, defined by using sub-class * instance of {@link GenericType} */ private ResolvedType _fromGenericType(ClassStack context, GenericType<?> generic, TypeBindings typeBindings) { /* To allow multiple levels of inheritance (just in case someone * wants to go to town with inheritance of GenericType), * we better resolve the whole thing; then dig out * type parameterization... */ ResolvedType type = _fromClass(context, generic.getClass(), typeBindings); ResolvedType genType = type.findSupertype(GenericType.class); if (genType == null) { // sanity check; shouldn't occur throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); } TypeBindings b = genType.getTypeBindings(); ResolvedType[] params = b.typeParameterArray(); if (params.length == 0) { throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); } return params[0]; }
private ResolvedType _fromAny(ClassStack context, Type mainType, TypeBindings typeBindings) { if (mainType instanceof Class<?>) { return _fromClass(context, (Class<?>) mainType, typeBindings); } if (mainType instanceof ParameterizedType) { return _fromParamType(context, (ParameterizedType) mainType, typeBindings); } if (mainType instanceof ResolvedType) { // Esp. TypePlaceHolder return (ResolvedType) mainType; } if (mainType instanceof GenericType<?>) { return _fromGenericType(context, (GenericType<?>) mainType, typeBindings); } if (mainType instanceof GenericArrayType) { return _fromArrayType(context, (GenericArrayType) mainType, typeBindings); } if (mainType instanceof TypeVariable<?>) { return _fromVariable(context, (TypeVariable<?>) mainType, typeBindings); } if (mainType instanceof WildcardType) { return _fromWildcard(context, (WildcardType) mainType, typeBindings); } // should never get here... throw new IllegalArgumentException("Unrecognized type class: "+mainType.getClass().getName()); }
private ResolvedType _fromAny(ClassStack context, Type mainType, TypeBindings typeBindings) { if (mainType instanceof Class<?>) { return _fromClass(context, (Class<?>) mainType, typeBindings); } if (mainType instanceof ParameterizedType) { return _fromParamType(context, (ParameterizedType) mainType, typeBindings); } if (mainType instanceof ResolvedType) { // Esp. TypePlaceHolder return (ResolvedType) mainType; } if (mainType instanceof GenericType<?>) { return _fromGenericType(context, (GenericType<?>) mainType, typeBindings); } if (mainType instanceof GenericArrayType) { return _fromArrayType(context, (GenericArrayType) mainType, typeBindings); } if (mainType instanceof TypeVariable<?>) { return _fromVariable(context, (TypeVariable<?>) mainType, typeBindings); } if (mainType instanceof WildcardType) { return _fromWildcard(context, (WildcardType) mainType, typeBindings); } // should never get here... throw new IllegalArgumentException("Unrecognized type class: "+mainType.getClass().getName()); }
resolvedSubtype = _fromClass(null, subtype, tbForPlaceholders); ResolvedType resolvedSupertype = resolvedSubtype.findSupertype(superclass); if (resolvedSupertype == null) { // sanity check, should never occur
resolvedSubtype = _fromClass(null, subtype, tbForPlaceholders); ResolvedType resolvedSupertype = resolvedSubtype.findSupertype(superclass); if (resolvedSupertype == null) { // sanity check, should never occur
bindings = TypeBindings.emptyBindings(); if (noParams) { return _fromClass(null, (Class<?>) type, bindings); resolvedParams[i] = _fromAny(null, typeParameters[i], bindings); return _fromClass(null, rawBase, TypeBindings.create(rawBase, resolvedParams));
bindings = TypeBindings.emptyBindings(); if (noParams) { return _fromClass(null, (Class<?>) type, bindings); resolvedParams[i] = _fromAny(null, typeParameters[i], bindings); return _fromClass(null, rawBase, TypeBindings.create(rawBase, resolvedParams));