/** * Factory method for resolving specified Java {@link java.lang.reflect.Type}, given * {@link TypeBindings} needed to resolve any type variables. *<p> * Use of this method is discouraged (use if and only if you really know what you * are doing!); but if used, type bindings passed should come from {@link ResolvedType} * instance of declaring class (or interface). *<p> * NOTE: order of arguments was reversed for 0.8, to avoid problems with * overload varargs method. */ public ResolvedType resolve(TypeBindings typeBindings, Type jdkType) { return _fromAny(null, jdkType, typeBindings); }
/** * Factory method for resolving specified Java {@link java.lang.reflect.Type}, given * {@link TypeBindings} needed to resolve any type variables. *<p> * Use of this method is discouraged (use if and only if you really know what you * are doing!); but if used, type bindings passed should come from {@link ResolvedType} * instance of declaring class (or interface). *<p> * NOTE: order of arguments was reversed for 0.8, to avoid problems with * overload varargs method. */ public ResolvedType resolve(TypeBindings typeBindings, Type jdkType) { return _fromAny(null, jdkType, typeBindings); }
private ResolvedType _fromWildcard(ClassStack context, WildcardType wildType, TypeBindings typeBindings) { /* Similar to challenges with TypeVariable, we may have multiple upper bounds. * But it is also possible that if upper bound defaults to Object, we might want to * consider lower bounds instead? * For now, we won't try anything more advanced; above is just for future reference. */ return _fromAny(context, wildType.getUpperBounds()[0], typeBindings); }
private ResolvedType _fromWildcard(ClassStack context, WildcardType wildType, TypeBindings typeBindings) { /* Similar to challenges with TypeVariable, we may have multiple upper bounds. * But it is also possible that if upper bound defaults to Object, we might want to * consider lower bounds instead? * For now, we won't try anything more advanced; above is just for future reference. */ return _fromAny(context, wildType.getUpperBounds()[0], typeBindings); }
private ResolvedType[] _resolveSuperInterfaces(ClassStack context, Class<?> rawType, TypeBindings typeBindings) { Type[] types = rawType.getGenericInterfaces(); if (types == null || types.length == 0) { return NO_TYPES; } int len = types.length; ResolvedType[] resolved = new ResolvedType[len]; for (int i = 0; i < len; ++i) { resolved[i] = _fromAny(context, types[i], typeBindings); } return resolved; }
private ResolvedType[] _resolveSuperInterfaces(ClassStack context, Class<?> rawType, TypeBindings typeBindings) { Type[] types = rawType.getGenericInterfaces(); if (types == null || types.length == 0) { return NO_TYPES; } int len = types.length; ResolvedType[] resolved = new ResolvedType[len]; for (int i = 0; i < len; ++i) { resolved[i] = _fromAny(context, types[i], typeBindings); } return resolved; }
/** * NOTE: return type changed in 1.0.1 from {@link ResolvedObjectType} to * {@link ResolvedType}, since it was found that other types may * be returned... * * @return Usually a {@link ResolvedObjectType}, but possibly also * {@link ResolvedRecursiveType} */ private ResolvedType _resolveSuperClass(ClassStack context, Class<?> rawType, TypeBindings typeBindings) { Type parent = rawType.getGenericSuperclass(); if (parent == null) { return null; } return _fromAny(context, parent, typeBindings); }
/** * NOTE: return type changed in 1.0.1 from {@link ResolvedObjectType} to * {@link ResolvedType}, since it was found that other types may * be returned... * * @return Usually a {@link ResolvedObjectType}, but possibly also * {@link ResolvedRecursiveType} */ private ResolvedType _resolveSuperClass(ClassStack context, Class<?> rawType, TypeBindings typeBindings) { Type parent = rawType.getGenericSuperclass(); if (parent == null) { return null; } return _fromAny(context, parent, typeBindings); }
private ResolvedType _fromArrayType(ClassStack context, GenericArrayType arrayType, TypeBindings typeBindings) { ResolvedType elementType = _fromAny(context, arrayType.getGenericComponentType(), typeBindings); // Figuring out raw class for generic array is actually bit tricky... Object emptyArray = Array.newInstance(elementType.getErasedType(), 0); return new ResolvedArrayType(emptyArray.getClass(), typeBindings, elementType); }
private ResolvedType _fromArrayType(ClassStack context, GenericArrayType arrayType, TypeBindings typeBindings) { ResolvedType elementType = _fromAny(context, arrayType.getGenericComponentType(), typeBindings); // Figuring out raw class for generic array is actually bit tricky... Object emptyArray = Array.newInstance(elementType.getErasedType(), 0); return new ResolvedArrayType(emptyArray.getClass(), typeBindings, elementType); }
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); }
private ResolvedType _fromVariable(ClassStack context, TypeVariable<?> variable, TypeBindings typeBindings) { // ideally should find it via bindings: String name = variable.getName(); ResolvedType type = typeBindings.findBoundType(name); if (type != null) { return type; } /* but if not, use bounds... note that approach here is simplistic; not taking * into account possible multiple bounds, nor consider upper bounds. */ /* 02-Mar-2011, tatu: As per issue#4, need to avoid self-reference cycles here; * can be handled by (temporarily) adding binding: */ if (typeBindings.hasUnbound(name)) { return sJavaLangObject; } typeBindings = typeBindings.withUnboundVariable(name); Type[] bounds = variable.getBounds(); return _fromAny(context, bounds[0], typeBindings); }
private ResolvedType _fromVariable(ClassStack context, TypeVariable<?> variable, TypeBindings typeBindings) { // ideally should find it via bindings: String name = variable.getName(); ResolvedType type = typeBindings.findBoundType(name); if (type != null) { return type; } /* but if not, use bounds... note that approach here is simplistic; not taking * into account possible multiple bounds, nor consider upper bounds. */ /* 02-Mar-2011, tatu: As per issue#4, need to avoid self-reference cycles here; * can be handled by (temporarily) adding binding: */ if (typeBindings.hasUnbound(name)) { return sJavaLangObject; } typeBindings = typeBindings.withUnboundVariable(name); Type[] bounds = variable.getBounds(); return _fromAny(context, bounds[0], typeBindings); }
private ResolvedType _constructType(ClassStack context, Class<?> rawType, TypeBindings typeBindings) { // Ok: no easy shortcut, let's figure out type of type... if (rawType.isArray()) { ResolvedType elementType = _fromAny(context, rawType.getComponentType(), typeBindings); return new ResolvedArrayType(rawType, typeBindings, elementType); } // Work-around/fix for [#33]: if the type has no type parameters, don't include // typeBindings in the ResolvedType if (!typeBindings.isEmpty() && rawType.getTypeParameters().length == 0) { typeBindings = TypeBindings.emptyBindings(); } // For other types super interfaces are needed... if (rawType.isInterface()) { return new ResolvedInterfaceType(rawType, typeBindings, _resolveSuperInterfaces(context, rawType, typeBindings)); } return new ResolvedObjectType(rawType, typeBindings, _resolveSuperClass(context, rawType, typeBindings), _resolveSuperInterfaces(context, rawType, typeBindings)); }
private ResolvedType _constructType(ClassStack context, Class<?> rawType, TypeBindings typeBindings) { // Ok: no easy shortcut, let's figure out type of type... if (rawType.isArray()) { ResolvedType elementType = _fromAny(context, rawType.getComponentType(), typeBindings); return new ResolvedArrayType(rawType, typeBindings, elementType); } // Work-around/fix for [#33]: if the type has no type parameters, don't include // typeBindings in the ResolvedType if (!typeBindings.isEmpty() && rawType.getTypeParameters().length == 0) { typeBindings = TypeBindings.emptyBindings(); } // For other types super interfaces are needed... if (rawType.isInterface()) { return new ResolvedInterfaceType(rawType, typeBindings, _resolveSuperInterfaces(context, rawType, typeBindings)); } return new ResolvedObjectType(rawType, typeBindings, _resolveSuperClass(context, rawType, typeBindings), _resolveSuperInterfaces(context, rawType, typeBindings)); }
return _fromGenericType(null, (GenericType<?>) type, bindings); ResolvedType rt = _fromAny(null, type, bindings); rawBase = rt.getErasedType(); } else if (type instanceof ResolvedType) { ResolvedType rt = _fromAny(null, type, bindings); rawBase = rt.getErasedType(); ResolvedType[] resolvedParams = new ResolvedType[len]; for (int i = 0; i < len; ++i) { resolvedParams[i] = _fromAny(null, typeParameters[i], bindings);
return _fromGenericType(null, (GenericType<?>) type, bindings); ResolvedType rt = _fromAny(null, type, bindings); rawBase = rt.getErasedType(); } else if (type instanceof ResolvedType) { ResolvedType rt = _fromAny(null, type, bindings); rawBase = rt.getErasedType(); ResolvedType[] resolvedParams = new ResolvedType[len]; for (int i = 0; i < len; ++i) { resolvedParams[i] = _fromAny(null, typeParameters[i], bindings);