List of usage examples for java.lang Class getGenericSuperclass
public Type getGenericSuperclass()
From source file:ClassUtils.java
static public Type[] getGenericType(Class<?> target) { if (target == null) return new Type[0]; Type[] types = target.getGenericInterfaces(); if (types.length > 0) { return types; }/*w w w . jav a 2 s . c o m*/ Type type = target.getGenericSuperclass(); if (type != null) { if (type instanceof ParameterizedType) { return new Type[] { type }; } } return new Type[0]; }
From source file:com.feilong.core.lang.reflect.TypeUtil.java
/** * superclass parameterized type./*from w w w.j a v a2 s .c o m*/ * * @param klass * the klass * @return the superclass parameterized type * @see java.lang.Class#getGenericSuperclass() */ private static ParameterizedType getGenericSuperclassParameterizedType(Class<?> klass) { Validate.notNull(klass, "klass can't be null/empty!"); Class<?> useClass = klass; Type type = useClass.getGenericSuperclass(); //com.feilong.core.lang.reflect.res.BaseSolrRepositoryImpl<com.feilong.core.lang.reflect.res.SkuItem, java.lang.Long> while (!(type instanceof ParameterizedType) && Object.class != useClass) { useClass = useClass.getSuperclass(); type = useClass.getGenericSuperclass(); } return (ParameterizedType) type; }
From source file:com.google.code.guice.repository.spi.TypeUtil.java
public static void getGenericSuperclassActualTypes(Collection<Type> types, Class aClass) { if (aClass != null && types != null) { Type superclass = aClass.getGenericSuperclass(); if (superclass instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) superclass; Type[] interfaces = parameterizedType.getActualTypeArguments(); types.addAll(Arrays.asList(interfaces)); } else if (superclass instanceof Class) { Class sClass = (Class) superclass; getGenericInterfacesActualTypes(types, sClass); getGenericSuperclassActualTypes(types, aClass.getSuperclass()); }//from ww w .j a v a 2s . c o m } }
From source file:com.iflytek.edu.cloud.frame.utils.ReflectionUtils.java
/** * ??,Class?. public UserDao extends// w ww. j av a 2 s .com * HibernateDao<User,Long> * * @param clazz clazz The class to introspect * @param index the Index of the generic ddeclaration,start from 0. * @return the index generic declaration, or Object.class if cannot be * determined */ public static Class getSuperClassGenricType(final Class clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return Object.class; } return (Class) params[index]; }
From source file:com.sunchenbin.store.feilong.core.lang.reflect.TypeUtil.java
/** * superclass parameterized type./*from www . j ava2 s .c o m*/ * * @param klass * the klass * @return the superclass parameterized type * @see java.lang.Class#getGenericSuperclass() */ private static ParameterizedType getGenericSuperclassParameterizedType(Class<?> klass) { if (Validator.isNullOrEmpty(klass)) { throw new NullPointerException("klass can't be null/empty!"); } Class<?> useClass = klass; Type type = useClass.getGenericSuperclass(); //com.sunchenbin.store.feilong.core.lang.reflect.res.BaseSolrRepositoryImpl<com.sunchenbin.store.feilong.core.lang.reflect.res.SkuItem, java.lang.Long> while (!(type instanceof ParameterizedType) && Object.class != useClass) { useClass = useClass.getSuperclass(); type = useClass.getGenericSuperclass(); } return (ParameterizedType) type; }
From source file:GenericsUtil.java
/** * Returns all of the {@link ParameterizedType}s implemented * by the given class. If none are implemented then an array * of zero length is returned.//w w w . ja va 2s . com * @param clazz the class * @return an array of ParameterizedType */ public static ParameterizedType[] getGenericTypes(Class<?> clazz) { List<ParameterizedType> types = new ArrayList<ParameterizedType>(); // add superclass if (clazz.getGenericSuperclass() instanceof ParameterizedType) { types.add((ParameterizedType) clazz.getGenericSuperclass()); } // add interfaces for (Type type : clazz.getGenericInterfaces()) { if (type instanceof ParameterizedType) { types.add((ParameterizedType) type); } } // return list return types.toArray(new ParameterizedType[0]); }
From source file:cn.geobeans.web.common.utils.ReflectionUtils.java
/** * ??, Class?.//from w ww . java 2 s.c om * , Object.class. * * public UserDao extends HibernateDao<User,Long> * * @param clazz clazz The class to introspect * @param index the Index of the generic ddeclaration,start from 0. * @return the index generic declaration, or Object.class if cannot be determined */ @SuppressWarnings("unchecked") public static Class getSuperClassGenricType(final Class clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return Object.class; } return (Class) params[index]; }
From source file:cn.taqu.core.modules.utils.ReflectionUtils.java
/** * ??, Class?.//from w w w. j av a 2s . c om * , Object.class. * * public UserDao extends HibernateDao<User,Long> * * @param clazz clazz The class to introspect * @param index the Index of the generic ddeclaration,start from 0. * @return the index generic declaration, or Object.class if cannot be determined */ public static Class<?> getSuperClassGenricType(final Class<?> clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if ((index >= params.length) || (index < 0)) { logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return Object.class; } return (Class<?>) params[index]; }
From source file:com.yize.broadcast.core.util.ReflectionUtils.java
/** * ??, Class?. , Object.class./*from w ww. j a v a2 s .co m*/ * * public UserDao extends HibernateDao<User,Long> * * @param clazz * clazz The class to introspect * @param index * the Index of the generic ddeclaration,start from 0. * @return the index generic declaration, or Object.class if cannot be * determined */ public static Class<?> getSuperClassGenricType(final Class<?> clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { LOGGER.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { LOGGER.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { LOGGER.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return Object.class; } return (Class<?>) params[index]; }
From source file:com.lily.dap.util.ReflectionUtils.java
/** * , Class.//from w ww . j av a 2 s . c o m * , Object.class. * * public UserDao extends HibernateDao<User,Long> * * @param clazz clazz The class to introspect * @param index the Index of the generic ddeclaration,start from 0. * @return the index generic declaration, or Object.class if cannot be determined */ public static Class getSuperClassGenricType(final Class clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return Object.class; } return (Class) params[index]; }