public static TypeInfo getTypeInfo(Class<?> type) { return getTypeInfo(type, null); }
public ReflectParameter(int index, String name, Parameter p, Type genericType) { this.index = index; this.name = name; this.p = p; this.genericType = genericType; this.typeInfo = Types.getTypeInfo(p.getType(), genericType); }
public static OpenType of(Class<?> type, Type genericType) { if(type == Void.class || type == Void.TYPE) { return SimpleType.VOID; } TypeInfo ti = Types.getTypeInfo(type, genericType); return of(ti); }
public SimpleProperty(Class<T> type, T value) { Args.notNull(type); this.type = type; this.complex = Types.getTypeInfo(type, null).isComplexType();; this.value = value; }
protected boolean validateMap(String name, Map map, Validation validation, int maxErrors) { TypeInfo typeInfo = null; for(Object item : map.entrySet()) { Map.Entry entry = (Map.Entry)item; Object value = entry.getValue(); if(null == value) { continue; } if(null == typeInfo) { typeInfo = Types.getTypeInfo(value.getClass()); } if(typeInfo.isComplexType() || typeInfo.isCollectionType()) { String fullName = Strings.nullToEmpty(name) + "['" + entry.getKey().toString() + "']"; if(!validate(fullName, value, validation, maxErrors) ){ return false; } } else { return true; } } return true; }
protected boolean validateCollection(String name, Iterable iterable, Validation validation, int maxErrors) { int i=0; TypeInfo typeInfo = null; for(Object value : iterable) { if(value == null) { continue; } if(typeInfo == null) { typeInfo = Types.getTypeInfo(value.getClass()); } if(typeInfo.isComplexType() || typeInfo.isCollectionType()) { String fullName = Strings.nullToEmpty(name) + "[" + String.valueOf(i) + "]"; if(!validate(fullName, value, validation, maxErrors) ){ return false; } } else { return true; } i++; } return true; }
protected boolean validateArray(String name, Object[] array, Validation validation, int maxErrors) { TypeInfo typeInfo = null; for(int i=0;i<array.length;i++) { Object value = array[i]; if(value == null) { continue; } if(typeInfo == null) { typeInfo = Types.getTypeInfo(value.getClass()); } if(typeInfo.isComplexType() || typeInfo.isCollectionType()) { String fullName = Strings.nullToEmpty(name) + "[" + String.valueOf(i) + "]"; if(!validate(fullName, value, validation, maxErrors) ){ return false; } } else { return true; } } return true; }
public static TypeInfo getTypeInfo(Class<?> type,Type genericType) { MTypeKind kind = null; Class<?> elementType = null; TypeInfo elementTypeInfo = null; if(isSimpleType(type, genericType)){ kind = MTypeKind.SIMPLE; }else if(isCollectionType(type, genericType)){ kind = MTypeKind.COLLECTION; elementType = getElementType(type, genericType); elementTypeInfo = getTypeInfo(elementType, null); }else{ kind = MTypeKind.COMPLEX; } return new TypeInfo(type, genericType, kind,elementType,elementTypeInfo); }
@Override public <T> Property<T> getDynaProperty(String name, Class<T> type) { if(null != propertyProvider) { try { Property<T> p = propertyProvider.getDynaProperty(name, type); return p; } catch (UnsupportedDynaPropertyException e) { log.info("property {0} unsupported by {1}, use local config",name,propertyProvider.getClass()); } } String v = properties.get(name); if(null == v || v.isEmpty()) { return new NullProperty<>(); } TypeInfo ti = Types.getTypeInfo(type,null); if(ti.isComplexType()) { return new SimpleProperty<>(type, JSON.decode(v, type)); }else{ return new SimpleProperty<>(type, Converts.convert(v, type)); } }
prop.setTypeInfo(Types.getTypeInfo(field.getType(), field.getGenericType())); prop.setDeclaringClass(field.getDeclaringClass()); if(null == prop.getGenericType()){ prop.setGenericType(m.getGenericParameterTypes()[0]); prop.setTypeInfo(Types.getTypeInfo(prop.getType(), prop.getGenericType())); if(null == prop.getGenericType()){ prop.setGenericType(m.getGenericReturnType()); prop.setTypeInfo(Types.getTypeInfo(prop.getType(), prop.getGenericType())); prop.setAnnotations(Arrays2.concat(prop.getAnnotations(), m.getAnnotations())); if(null == prop.getGenericType()){ prop.setGenericType(m.getGenericReturnType()); prop.setTypeInfo(Types.getTypeInfo(prop.getType(), prop.getGenericType())); prop.setAnnotations(Arrays2.concat(prop.getAnnotations(), m.getAnnotations()));