List of usage examples for java.lang.reflect ParameterizedType getActualTypeArguments
Type[] getActualTypeArguments();
From source file:org.raml.emitter.RamlEmitter.java
private void dumpMappingField(StringBuilder dump, int depth, Field field, boolean implicit, Object pojo) { if (!Map.class.isAssignableFrom(field.getType())) { throw new RuntimeException("invalid type"); }//from w w w. j a va 2s.c om Map value = (Map) getFieldValue(field, pojo); if (value == null || value.isEmpty()) { return; } if (!implicit) { dump.append(indent(depth)).append(alias(field)).append(YAML_MAP_SEP).append("\n"); depth++; } ParameterizedType pType = (ParameterizedType) field.getGenericType(); Type valueType = pType.getActualTypeArguments()[1]; dumpMap(dump, depth, valueType, value); }
From source file:info.archinnov.achilles.entity.parsing.PropertyParser.java
private <K, V> Pair<Class<K>, Class<V>> determineMapGenericTypes(Field field) { log.trace("Determine generic types for field Map<K,V> {} of entity class {}", field.getName(), field.getDeclaringClass().getCanonicalName()); Type genericType = field.getGenericType(); ParameterizedType pt = (ParameterizedType) genericType; Type[] actualTypeArguments = pt.getActualTypeArguments(); Class<K> keyClass = propertyHelper.getClassFromType(actualTypeArguments[0]); Class<V> valueClass = propertyHelper.getClassFromType(actualTypeArguments[1]); return Pair.create(keyClass, valueClass); }
From source file:dstrelec.nats.listener.adapter.MessagingMessageListenerAdapter.java
private boolean eligibleParameter(MethodParameter methodParameter) { Type parameterType = methodParameter.getGenericParameterType(); if (parameterType.equals(io.nats.client.Message.class)) { return false; }/*from w ww . ja v a 2 s . c o m*/ if (parameterType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) parameterType; if (parameterizedType.getRawType().equals(Message.class)) { return !(parameterizedType.getActualTypeArguments()[0] instanceof WildcardType); } } return !parameterType.equals(Message.class); // could be Message without a generic type }
From source file:io.mandrel.OtherTest.java
public void inspect(int level, Type clazz, String name) { if (level > 6) return;//from w w w. j a v a 2s . c o m if (clazz instanceof Class && !((Class<?>) clazz).isEnum() && ((Class<?>) clazz).getPackage() != null && ((Class<?>) clazz).getPackage().getName().startsWith("io.mandrel")) { int newLevel = level + 1; Field[] fields = ((Class<?>) clazz).getDeclaredFields(); for (Field field : fields) { Class<?> fieldType = field.getType(); String text; if (!field.isAnnotationPresent(JsonIgnore.class) && !Modifier.isStatic(field.getModifiers())) { if (List.class.equals(fieldType) || Map.class.equals(fieldType)) { Type type = field.getGenericType(); if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; Type paramType = pType.getActualTypeArguments()[pType.getActualTypeArguments().length - 1]; text = field.getName() + "(container of " + paramType + ")"; System.err.println(StringUtils.leftPad(text, text.length() + newLevel * 5, "\t- ")); inspect(newLevel, paramType, ""); } } else { text = field.getName() + (field.getType().isPrimitive() || field.getType().equals(String.class) || field.getType().equals(LocalDateTime.class) ? " (" + field.getType().getName() + ")" : ""); System.err.println(StringUtils.leftPad(text, text.length() + newLevel * 5, "\t- ")); inspect(newLevel, fieldType, field.getName()); } // JsonSubTypes subtype = // fieldType.getAnnotation(JsonSubTypes.class); // if (subtype != null) { // int subLevel = level + 2; // text = "subtypes:"; // System.err.println(StringUtils.leftPad(text, // text.length() + subLevel * 5, "\t- ")); // for (JsonSubTypes.Type type : subtype.value()) { // text = "subtype:" + type.name(); // System.err.println(StringUtils.leftPad(text, // text.length() + (subLevel + 1) * 5, "\t- ")); // inspect((subLevel + 1), type.value(), type.name()); // } // } } } JsonSubTypes subtype = ((Class<?>) clazz).getAnnotation(JsonSubTypes.class); if (subtype != null) { int subLevel = level + 1; String text = "subtypes:"; System.err.println(StringUtils.leftPad(text, text.length() + subLevel * 5, "\t- ")); for (JsonSubTypes.Type type : subtype.value()) { text = "subtype:" + type.name(); System.err.println(StringUtils.leftPad(text, text.length() + (subLevel + 1) * 5, "\t- ")); inspect((subLevel + 1), type.value(), type.name()); } } } }
From source file:GenericClass.java
private void recurse(Class<?> clazz, Class<?> simplesup, ParameterizedType partype) { Type[] typeArguments = partype.getActualTypeArguments(); TypeVariable<?>[] parameters = simplesup.getTypeParameters(); for (int i = 0; i < typeArguments.length; i++) { if (typeArguments[i] instanceof Class) { genericMap.put(simplesup.getName() + "--" + parameters[i].getName(), (Class) typeArguments[i]); } else if (typeArguments[i] instanceof TypeVariable) { reverseIntermediate.put(clazz.getName() + "--" + ((TypeVariable<?>) typeArguments[i]).getName(), simplesup.getName() + "--" + parameters[i].getName()); }//from w w w. j a v a 2 s. c o m } recurse(simplesup); }
From source file:com.qihang.winter.poi.excel.imports.base.ImportBaseService.java
/** * ??/*from ww w . j av a 2s. c o m*/ * * * @param exclusions * @param targetId * ID * @param fields * @param excelCollection * @throws Exception */ public void getAllExcelField(String targetId, Field[] fields, Map<String, ExcelImportEntity> excelParams, List<com.qihang.winter.poi.excel.entity.params.ExcelCollectionParams> excelCollection, Class<?> pojoClass, List<Method> getMethods) throws Exception { ExcelImportEntity excelEntity = null; for (int i = 0; i < fields.length; i++) { Field field = fields[i]; if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) { continue; } if (PoiPublicUtil.isCollection(field.getType())) { // ? com.qihang.winter.poi.excel.entity.params.ExcelCollectionParams collection = new com.qihang.winter.poi.excel.entity.params.ExcelCollectionParams(); collection.setName(field.getName()); Map<String, ExcelImportEntity> temp = new HashMap<String, ExcelImportEntity>(); ParameterizedType pt = (ParameterizedType) field.getGenericType(); Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0]; collection.setType(clz); getExcelFieldList(targetId, PoiPublicUtil.getClassFields(clz), clz, temp, null); collection.setExcelParams(temp); collection.setExcelName(field.getAnnotation(ExcelCollection.class).name()); additionalCollectionName(collection); excelCollection.add(collection); } else if (PoiPublicUtil.isJavaClass(field)) { addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams); } else { List<Method> newMethods = new ArrayList<Method>(); if (getMethods != null) { newMethods.addAll(getMethods); } newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass)); getAllExcelField(targetId, PoiPublicUtil.getClassFields(field.getType()), excelParams, excelCollection, field.getType(), newMethods); } } }
From source file:com.impetus.kundera.persistence.AssociationBuilder.java
/** * Returns associated bi-directional field. * /*from w w w. ja v a 2 s. c om*/ * @param originalClazz * Original class * @param referencedClass * Referenced class. */ public Field getBiDirectionalField(Class originalClazz, Class referencedClass) { Field[] fields = referencedClass.getDeclaredFields(); Class<?> clazzz = null; Field biDirectionalField = null; for (Field field : fields) { clazzz = field.getType(); if (PropertyAccessorHelper.isCollection(clazzz)) { ParameterizedType type = (ParameterizedType) field.getGenericType(); Type[] types = type.getActualTypeArguments(); clazzz = (Class<?>) types[0]; } if (clazzz.equals(originalClazz)) { biDirectionalField = field; break; } } return biDirectionalField; }
From source file:com.opensymphony.able.action.EmbeddedCollectionActionBean.java
public EmbeddedCollectionActionBean(String propertyName) { this.propertyName = propertyName; ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass(); Type[] typeArguments = genericSuperclass.getActualTypeArguments(); this.ownerClass = (Class<O>) typeArguments[0]; this.entityClass = (Class<E>) typeArguments[1]; init();//from w w w .j a va 2 s .com }
From source file:com.heisenberg.impl.plugin.Descriptors.java
protected Descriptor getDataTypeDescriptor(Type type, Field field /* passed for error message only */) { Descriptor descriptor = dataTypeDescriptorsByValueType.get(type); if (descriptor != null) { return descriptor; }/*from w w w. j av a 2 s. c o m*/ if (String.class.equals(type)) { return getDataTypeDescriptor(TextType.class, null); } else if (type instanceof ParameterizedType) { ParameterizedType parametrizedType = (ParameterizedType) type; Type rawType = parametrizedType.getRawType(); Type[] typeArgs = parametrizedType.getActualTypeArguments(); descriptor = createDataTypeDescriptor(rawType, typeArgs, field); dataTypeDescriptorsByValueType.put(type, descriptor); return descriptor; } throw new RuntimeException( "Don't know how to handle " + type + "'s. It's used in configuration field: " + field); }
From source file:org.netxilia.spi.impl.formula.function.MethodWrapper.java
public MethodWrapper(Object instance, Method method) { this.instance = instance; this.method = method; Class<?>[] paramTypes = method.getParameterTypes(); paramConverters = new IParamConverter[paramTypes.length]; Type[] genericParameterTypes = method.getGenericParameterTypes(); for (int i = 0; i < genericParameterTypes.length; ++i) { Type genericParameterType = genericParameterTypes[i]; if (genericParameterType instanceof ParameterizedType) { ParameterizedType aType = (ParameterizedType) genericParameterType; if (Iterator.class.isAssignableFrom((Class<?>) aType.getRawType())) { Class<?> componentType = (Class<?>) aType.getActualTypeArguments()[0]; paramConverters[i] = new IteratorConverter(componentType); }/*from w w w . j av a2s. c o m*/ } else { Class<?> paramType = (Class<?>) genericParameterType; if (IGenericValue.class == paramType) { paramConverters[i] = new LazyParamConverter(); } else if (RichValue.class == paramType) { paramConverters[i] = new RichValueParamConverter(); } else { paramConverters[i] = new BasicTypeConverter(paramType); } } } Function annotation = this.method.getAnnotation(Function.class); cacheable = annotation == null || annotation.cacheable(); }