/** * Return a {@link Serializable} variant of {@link Field#getGenericType()}. */ @Nullable public static Type forField(Field field) { return forTypeProvider(new FieldTypeProvider(field)); }
other = unwrap((Type) other); return forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, -1)); result[i] = forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, i));
@Test public void forField() throws Exception { Type type = SerializableTypeWrapper.forField(Fields.class.getField("parameterizedType")); assertThat(type.toString(), equalTo("java.util.List<java.lang.String>")); assertSerializable(type); }
/** * Return the underling Java {@link Type} being managed. */ public Type getType() { return SerializableTypeWrapper.unwrap(this.type); }
@Test public void forMethodParameter() throws Exception { Method method = Methods.class.getDeclaredMethod("method", Class.class, Object.class); Type type = SerializableTypeWrapper.forMethodParameter(MethodParameter.forExecutable(method, 0)); assertThat(type.toString(), equalTo("java.lang.Class<T>")); assertSerializable(type); }
/** * Return a {@link ResolvableType} array representing the direct interfaces implemented by this * type. If this type does not implement any interfaces an empty array is returned. * * @see #getSuperType() */ public ResolvableType[] getInterfaces() { Class<?> resolved = resolve(); if (resolved == null || ObjectUtils.isEmpty(resolved.getGenericInterfaces())) { return EMPTY_TYPES_ARRAY; } ResolvableType[] interfaces = this.interfaces; if (interfaces == null) { interfaces = forTypes(SerializableTypeWrapper.forGenericInterfaces(resolved), asVariableResolver()); this.interfaces = interfaces; } return interfaces; }
/** * Return a {@link ResolvableType} representing the direct supertype of this type. If no supertype * is available this method returns {@link #NONE}. * * @see #getInterfaces() */ public ResolvableType getSuperType() { Class<?> resolved = resolve(); if (resolved == null || resolved.getGenericSuperclass() == null) { return NONE; } ResolvableType superType = this.superType; if (superType == null) { superType = forType(SerializableTypeWrapper.forGenericSuperclass(resolved), asVariableResolver()); this.superType = superType; } return superType; }
if (this.type instanceof Class) { Class<?> typeClass = (Class<?>) this.type; generics = forTypes(SerializableTypeWrapper.forTypeParameters(typeClass), this.variableResolver); } else if (this.type instanceof ParameterizedType) { Type[] actualTypeArguments = ((ParameterizedType) this.type).getActualTypeArguments();
@Override @Nullable public ResolvableType resolveVariable(TypeVariable<?> variable) { for (int i = 0; i < this.variables.length; i++) { TypeVariable<?> v1 = SerializableTypeWrapper.unwrap(this.variables[i]); TypeVariable<?> v2 = SerializableTypeWrapper.unwrap(variable); if (ObjectUtils.nullSafeEquals(v1, v2)) { return this.generics[i]; } } return null; }
@Test public void forConstructor() throws Exception { Constructor<?> constructor = Constructors.class.getDeclaredConstructor(List.class); Type type = SerializableTypeWrapper.forMethodParameter(MethodParameter.forExecutable(constructor, 0)); assertThat(type.toString(), equalTo("java.util.List<java.lang.String>")); assertSerializable(type); }
/** * Return a {@link Serializable} variant of * {@link MethodParameter#getGenericParameterType()}. */ @Nullable public static Type forMethodParameter(MethodParameter methodParameter) { return forTypeProvider(new MethodParameterTypeProvider(methodParameter)); }
other = unwrap((Type) other); return forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, -1)); result[i] = forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, i));
/** * Return the underling Java {@link Type} being managed. */ public Type getType() { return SerializableTypeWrapper.unwrap(this.type); }
@Test public void classType() throws Exception { Type type = SerializableTypeWrapper.forField(Fields.class.getField("classType")); assertThat(type.toString(), equalTo("class java.lang.String")); assertSerializable(type); }
/** * Return a {@link Serializable} variant of {@link Field#getGenericType()}. */ @Nullable public static Type forField(Field field) { return forTypeProvider(new FieldTypeProvider(field)); }
other = unwrap((Type) other); return forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, -1)); } else if (Type[].class == method.getReturnType() && args == null) { Type[] result = new Type[((Type[]) method.invoke(this.provider.getType())).length]; for (int i = 0; i < result.length; i++) { result[i] = forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, i));
@Override @Nullable public ResolvableType resolveVariable(TypeVariable<?> variable) { for (int i = 0; i < this.variables.length; i++) { TypeVariable<?> v1 = SerializableTypeWrapper.unwrap(this.variables[i]); TypeVariable<?> v2 = SerializableTypeWrapper.unwrap(variable); if (ObjectUtils.nullSafeEquals(v1, v2)) { return this.generics[i]; } } return null; }
@Test public void genericArrayType() throws Exception { GenericArrayType type = (GenericArrayType) SerializableTypeWrapper.forField(Fields.class.getField("genericArrayType")); assertThat(type.toString(), equalTo("java.util.List<java.lang.String>[]")); assertSerializable(type); assertSerializable(type.getGenericComponentType()); }
/** * Return a {@link Serializable} variant of * {@link MethodParameter#getGenericParameterType()}. */ @Nullable public static Type forMethodParameter(MethodParameter methodParameter) { return forTypeProvider(new MethodParameterTypeProvider(methodParameter)); }
other = unwrap((Type) other); return forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, -1)); result[i] = forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, i));