List of usage examples for java.lang Class getGenericSuperclass
public Type getGenericSuperclass()
From source file:org.tinygroup.tinyioc.impl.BeanContainerImpl.java
public static boolean isSubClass(Class a, Class b) { Type genericSuperclass = a.getGenericSuperclass(); for (Type type : a.getGenericInterfaces()) { if (type.equals(b)) { return true; }//www . j a v a 2s. co m boolean is = isSubClass((Class) type, b); if (is) { return true; } } if (genericSuperclass != null) { if (genericSuperclass.equals(b)) { return true; } else { boolean is = isSubClass((Class) genericSuperclass, b); if (is) { return true; } } } return false; }
From source file:com.topsem.common.utils.Reflections.java
/** * ??, Class?./*w w w . j av a2 s. c o m*/ * , Object.class. * <p/> * 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 getClassGenericType(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:info.donsun.core.utils.Reflections.java
/** * ??, Class?. , Object.class.//from w ww .ja v a2 s . c om * * 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 <T> Class<T> getClassGenricType(final Class clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return null; } 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 null; } if (!(params[index] instanceof Class)) { logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return null; } return (Class) params[index]; }
From source file:com.austin.base.commons.util.ReflectUtil.java
/** * ??,Class?. public BookManager extends GenricManager<Book> * * @param clazz clazz The class to introspect * @param index the Index of the generic ddeclaration,start from 0. * @return the index generic declaration, or <code>Object.class</code> if cannot be determined *///w w w . j a va2s . com public static Class getSuperClassGenricType(Class clazz, int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { log.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { log.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { log.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return Object.class; } return (Class) params[index]; }
From source file:activiti.common.persistence.util.ReflectHelper.java
/** * ??, Class?. , Object.class./*ww w . j av a2 s . c o 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 getClassGenricType(final Class clazz, final int index) { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if ((index >= params.length) || (index < 0)) { return Object.class; } if (!(params[index] instanceof Class)) { return Object.class; } return (Class) params[index]; }
From source file:de.micromata.genome.util.runtime.ClassUtils.java
/** * Reads the generic type of the given class at the given index. * /*from w ww . ja v a 2 s.c o m*/ * Note: this doesn't work, if class MyClass implements Super MyConcreteType * * @param clazz the class with generic types * @param index the index of the generic type * @return the generic type or null */ public static Class<?> getGenericTypeArgument(Class<?> clazz, int index) { Type genericSuperclass = clazz.getGenericSuperclass(); return findGenericTypeArgument(genericSuperclass, index); }
From source file:org.lightadmin.core.util.DomainConfigurationUtils.java
public static Class<?> configurationDomainType(Class clazz) { if (isAnnotationBasedConfigurationCandidate(clazz)) { final Administration annotation = findAnnotation(clazz, Administration.class); return annotation == null ? null : annotation.value(); }//from w ww. j a v a2 s. c o m if (isSuperClassBasedConfigurationCandidate(clazz)) { final ParameterizedType genericSuperclass = (ParameterizedType) clazz.getGenericSuperclass(); return (Class<?>) genericSuperclass.getActualTypeArguments()[0]; } throw new RuntimeException("Unknown configuration candidate"); }
From source file:com.hihframework.core.utils.ReflectUtil.java
/** * ??,Class?.//from w ww . j a v 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]; }
From source file:com.mine.core.util.ReflectUtils.java
/** * ??, Class?. , Object.class.//w w w . ja v a 2s . co m * <p> * 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 getClassGenricType(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: {}, Size of {}'s Parameterized Type: {}", index, clazz.getSimpleName(), 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.mine.core.util.ReflectUtils.java
/** * ??, Class?. , Object.class.//from w w w.j ava2 s.c om * <p> * 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("rawtypes") 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: {}, Size of {}'s Parameterized Type: {}", index, clazz.getSimpleName(), 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]; }