List of usage examples for java.lang.reflect ParameterizedType getActualTypeArguments
Type[] getActualTypeArguments();
From source file:net.easysmarthouse.service.scripting.ScriptDecoratorPointcut.java
@Override public boolean matches(Method method, Class<?> type) { Class<?> returnType = method.getReturnType(); if (returnType == Device.class) { return true; }/*ww w . j ava 2 s . com*/ if (Collection.class.isAssignableFrom(returnType)) { Type genericReturnType = method.getGenericReturnType(); if (genericReturnType instanceof ParameterizedType) { ParameterizedType listType = (ParameterizedType) genericReturnType; Type[] actualTypeArgs = listType.getActualTypeArguments(); if (actualTypeArgs != null && actualTypeArgs.length != 0) { Class<?> listClass = (Class<?>) actualTypeArgs[0]; if (listClass == Device.class) { return true; } } } } return false; }
From source file:com.ngdata.hbaseindexer.rest.IndexerDefinitionsMessageBodyWriter.java
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (Collection.class.isAssignableFrom(type) && mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)) { if (genericType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) genericType; if (Arrays.asList(parameterizedType.getActualTypeArguments()).contains(IndexerDefinition.class)) { return true; }// w w w. ja v a2 s .c o m } } return false; }
From source file:com.hc.wx.server.common.bytecode.ReflectUtils.java
public static Class<?> getGenericClass(Class<?> cls, int i) { try {//from w w w .j a v a2 s. c o m ParameterizedType parameterizedType = ((ParameterizedType) cls.getGenericInterfaces()[0]); Object genericClass = parameterizedType.getActualTypeArguments()[i]; if (genericClass instanceof ParameterizedType) { // ? return (Class<?>) ((ParameterizedType) genericClass).getRawType(); } else if (genericClass instanceof GenericArrayType) { // ? return (Class<?>) ((GenericArrayType) genericClass).getGenericComponentType(); } else if (((Class) genericClass).isArray()) { // JDK 7 , Foo<int[]> ?? GenericArrayType return ((Class) genericClass).getComponentType(); } else { return (Class<?>) genericClass; } } catch (Throwable e) { throw new IllegalArgumentException(cls.getName() + " generic type undefined!", e); } }
From source file:org.lilyproject.rest.providers.json.EntityListMessageBodyWriter.java
public boolean isTypeParamSupported(Type genericType) { if (genericType instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) genericType; Type[] types = pt.getActualTypeArguments(); if (types.length == 1 && EntityRegistry.SUPPORTED_TYPES.containsKey(types[0])) { return true; }/*w ww .ja va2 s . com*/ } return false; }
From source file:org.chtijbug.drools.platform.entity.coder.JSONCoder.java
@Override public void init(EndpointConfig endpointConfig) { ParameterizedType $thisClass = (ParameterizedType) this.getClass().getGenericSuperclass(); Type $T = $thisClass.getActualTypeArguments()[0]; if ($T instanceof Class) { _type = (Class<T>) $T; } else if ($T instanceof ParameterizedType) { _type = (Class<T>) ((ParameterizedType) $T).getRawType(); }/*from w w w. j a va 2 s. c o m*/ }
From source file:com.senfino.yodo.dao.AbstracAcountDao.java
@SuppressWarnings("unchacked") private Class<T> getDomainClass() { if (domainClass == null) { ParameterizedType thisType = (ParameterizedType) getClass().getGenericSuperclass(); this.domainClass = (Class<T>) thisType.getActualTypeArguments()[0]; }/*ww w . j a v a2 s . c o m*/ return domainClass; }
From source file:org.lilyproject.rest.providers.json.RepositoryTablesBodyWriter.java
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (Collection.class.isAssignableFrom(type) && mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)) { if (genericType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) genericType; if (Arrays.asList(parameterizedType.getActualTypeArguments()).contains(RepositoryTable.class)) { return true; }/*from w w w. j a va 2 s . c o m*/ } } return false; }
From source file:org.everrest.core.impl.provider.MultipartFormDataEntityProvider.java
@Override public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (type == Iterator.class) { try {//from w w w .j av a 2 s . c o m ParameterizedType t = (ParameterizedType) genericType; Type[] ta = t.getActualTypeArguments(); return ta.length == 1 && ta[0] == FileItem.class; } catch (ClassCastException e) { return false; } } return false; }
From source file:org.openmrs.module.openhmis.cashier.web.propertyeditor.EntityPropertyEditor.java
@SuppressWarnings("unchecked") protected Class<E> getEntityClass() { ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass(); return (Class) parameterizedType.getActualTypeArguments()[0]; }
From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.provider.AbstractFieldPersistenceProvider.java
protected Class<?> getListFieldType(Serializable instance, FieldManager fieldManager, Property property, PersistenceManager persistenceManager) { Class<?> returnType = null; Field field = fieldManager.getField(instance.getClass(), property.getName()); java.lang.reflect.Type type = field.getGenericType(); if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; Class<?> clazz = (Class<?>) pType.getActualTypeArguments()[0]; Class<?>[] entities = persistenceManager.getDynamicEntityDao() .getAllPolymorphicEntitiesFromCeiling(clazz); if (!ArrayUtils.isEmpty(entities)) { returnType = entities[entities.length - 1]; }/* ww w . ja v a2s . co m*/ } return returnType; }