use of java.lang.reflect.ParameterizedType in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method processPropertyTypeForQNames.
private void processPropertyTypeForQNames(PropertyDescriptor pType, Map<QualifiedName, QNameInfo> qNameInfos, Set<QualifiedName> newQNames, List<CompositeDescriptorInfo> vDescriptors, Set<String> enumValues, Boolean setQNameTableNameToNull) {
QualifiedName qName = pType.qualifiedName();
if (!newQNames.contains(qName) && !qName.name().equals(Identity.class.getName())) {
newQNames.add(qName);
// System.out.println("QName: " + qName + ", hc: " + qName.hashCode());
QNameInfo info = qNameInfos.get(qName);
if (info == null) {
info = QNameInfo.fromProperty(//
qName, setQNameTableNameToNull ? null : (QNAME_TABLE_NAME_PREFIX + qNameInfos.size()), //
pType);
qNameInfos.put(qName, info);
}
Type vType = info.getFinalType();
while (vType instanceof ParameterizedType) {
vType = ((ParameterizedType) vType).getRawType();
}
if (//
vType instanceof Class<?>) {
final Class<?> vTypeClass = (Class<?>) vType;
if (((Class<?>) vType).isInterface()) {
for (CompositeDescriptorInfo descInfo : vDescriptors) {
CompositeDescriptor desc = descInfo.composite;
if (desc instanceof ValueDescriptor) {
ValueDescriptor vDesc = (ValueDescriptor) desc;
// other Serializable
if (Iterables.matchesAny(new Specification<Class<?>>() {
@Override
public boolean satisfiedBy(Class<?> item) {
return vTypeClass.isAssignableFrom(item);
}
}, vDesc.types())) {
for (PropertyDescriptor subPDesc : vDesc.state().properties()) {
//
this.processPropertyTypeForQNames(//
subPDesc, //
qNameInfos, //
newQNames, //
vDescriptors, //
enumValues, //
setQNameTableNameToNull);
}
}
}
}
} else if (Enum.class.isAssignableFrom((Class<?>) vType)) {
for (Object value : ((Class<?>) vType).getEnumConstants()) {
enumValues.add(QualifiedName.fromClass((Class<?>) vType, value.toString()).toString());
}
}
}
}
}
use of java.lang.reflect.ParameterizedType in project qi4j-sdk by Qi4j.
the class ValueCompositeCxfType method isMap.
private boolean isMap(Type type) {
if (isMapClass(type)) {
return true;
}
if (type instanceof ParameterizedType) {
ParameterizedType param = (ParameterizedType) type;
Type rawType = param.getRawType();
if (isCollectionClass(rawType)) {
return true;
}
}
return false;
}
use of java.lang.reflect.ParameterizedType in project qi4j-sdk by Qi4j.
the class ValueCompositeCxfType method isCollection.
private boolean isCollection(Type type) {
if (isCollectionClass(type)) {
return true;
}
if (type instanceof ParameterizedType) {
ParameterizedType param = (ParameterizedType) type;
Type rawType = param.getRawType();
if (isCollectionClass(rawType)) {
return true;
}
}
return false;
}
use of java.lang.reflect.ParameterizedType in project MVCHelper by LuckyJayce.
the class JsonParser method getSuperclassTypeParameter.
private static Type getSuperclassTypeParameter(Class<?> subclass) {
Type superclass = subclass.getGenericSuperclass();
if (superclass instanceof Class) {
throw new RuntimeException("Missing type parameter.");
}
ParameterizedType parameterized = (ParameterizedType) superclass;
return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
}
use of java.lang.reflect.ParameterizedType in project MinecraftForge by MinecraftForge.
the class ConfigManager method createConfig.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void createConfig(String modid, String category, Configuration cfg, Class<?> ftype, Field f, Object instance) {
Property prop = null;
String comment = null;
Comment ca = f.getAnnotation(Comment.class);
if (ca != null)
comment = NEW_LINE.join(ca.value());
String langKey = modid + "." + category + "." + f.getName().toLowerCase(Locale.ENGLISH);
LangKey la = f.getAnnotation(LangKey.class);
if (la != null)
langKey = la.value();
ITypeAdapter adapter = ADAPTERS.get(ftype);
if (adapter != null) {
if (category.isEmpty())
throw new RuntimeException("Can not specify a primitive field when the category is empty: " + f.getDeclaringClass() + "/" + f.getName());
prop = adapter.getProp(cfg, category, f, instance, comment);
set(instance, f, adapter.getValue(prop));
} else if (ftype.getSuperclass() == Enum.class) {
if (category.isEmpty())
throw new RuntimeException("Can not specify a primitive field when the category is empty: " + f.getDeclaringClass() + "/" + f.getName());
Enum enu = (Enum) get(instance, f);
prop = cfg.get(category, getName(f), enu.name(), comment);
prop.setValidationPattern(makePattern((Class<? extends Enum>) ftype));
set(instance, f, Enum.valueOf((Class<? extends Enum>) ftype, prop.getString()));
} else if (ftype == Map.class) {
if (category.isEmpty())
throw new RuntimeException("Can not specify a primitive field when the category is empty: " + f.getDeclaringClass() + "/" + f.getName());
String sub = category + "." + getName(f).toLowerCase(Locale.ENGLISH);
Map<String, Object> m = (Map<String, Object>) get(instance, f);
ParameterizedType type = (ParameterizedType) f.getGenericType();
Type mtype = type.getActualTypeArguments()[1];
cfg.getCategory(sub).setComment(comment);
for (Entry<String, Object> e : m.entrySet()) {
ITypeAdapter.Map adpt = MAP_ADAPTERS.get(mtype);
if (adpt != null) {
prop = adpt.getProp(cfg, sub, e.getKey(), e.getValue());
} else if (mtype instanceof Class && ((Class<?>) mtype).getSuperclass() == Enum.class) {
prop = TypeAdapters.Str.getProp(cfg, sub, e.getKey(), ((Enum) e.getValue()).name());
prop.setValidationPattern(makePattern((Class<? extends Enum>) mtype));
} else
throw new RuntimeException("Unknown type in map! " + f.getDeclaringClass() + "/" + f.getName() + " " + mtype);
prop.setLanguageKey(langKey + "." + e.getKey().toLowerCase(Locale.ENGLISH));
}
prop = null;
} else if (//Only support classes that are one level below Object.
ftype.getSuperclass() == Object.class) {
String sub = (category.isEmpty() ? "" : category + ".") + getName(f).toLowerCase(Locale.ENGLISH);
cfg.getCategory(sub).setComment(comment);
Object sinst = get(instance, f);
for (Field sf : ftype.getDeclaredFields()) {
if (!Modifier.isPublic(sf.getModifiers()))
continue;
createConfig(modid, sub, cfg, sf.getType(), sf, sinst);
}
} else
throw new RuntimeException("Unknown type in config! " + f.getDeclaringClass() + "/" + f.getName() + " " + ftype);
if (prop != null) {
prop.setLanguageKey(langKey);
RangeInt ia = f.getAnnotation(RangeInt.class);
if (ia != null) {
prop.setMinValue(ia.min());
prop.setMaxValue(ia.max());
if (comment != null)
prop.setComment(NEW_LINE.join(new String[] { comment, "Min: " + ia.min(), "Max: " + ia.max() }));
else
prop.setComment(NEW_LINE.join(new String[] { "Min: " + ia.min(), "Max: " + ia.max() }));
}
RangeDouble da = f.getAnnotation(RangeDouble.class);
if (da != null) {
prop.setMinValue(da.min());
prop.setMaxValue(da.max());
if (comment != null)
prop.setComment(NEW_LINE.join(new String[] { comment, "Min: " + da.min(), "Max: " + da.max() }));
else
prop.setComment(NEW_LINE.join(new String[] { "Min: " + da.min(), "Max: " + da.max() }));
}
//TODO List length values
}
}
Aggregations