List of usage examples for java.lang Class getSuperclass
@HotSpotIntrinsicCandidate public native Class<? super T> getSuperclass();
From source file:com.buaa.cfs.utils.ReflectionUtils.java
/** * Gets all the declared fields of a class including fields declared in superclasses. */// ww w. j av a2 s. c om public static List<Field> getDeclaredFieldsIncludingInherited(Class<?> clazz) { List<Field> fields = new ArrayList<Field>(); while (clazz != null) { for (Field field : clazz.getDeclaredFields()) { fields.add(field); } clazz = clazz.getSuperclass(); } return fields; }
From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java
/** * ?field,/*from w w w . j a v a 2 s.c o m*/ * * @param fields * @param type * @return */ public static Field[] getAllFields(Collection<Field> fields, Class<?> type) { if (Argument.isEmpty(fields)) { fields = new HashSet<Field>(); } for (Field field : type.getDeclaredFields()) { fields.add(field); } if (type.getSuperclass() != null) { fields.addAll(Arrays.asList(getAllFields(fields, type.getSuperclass()))); } return fields.toArray(new Field[fields.size()]); }
From source file:com.sunchenbin.store.feilong.core.lang.reflect.TypeUtil.java
/** * superclass parameterized type./*from w w w .j a va 2s .com*/ * * @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:jfix.util.Reflections.java
/** * Returns all interfaces and superclasses implemented by a given class. *///from www. ja v a2 s . c o m public static Set<Class<?>> getSuperClassesAndInterfaces(Class<?> clazz) { Set<Class<?>> result = new HashSet<>(); if (clazz != null) { result.add(clazz); for (Class<?> interfaceClass : clazz.getInterfaces()) { result.addAll(getSuperClassesAndInterfaces(interfaceClass)); } result.addAll(getSuperClassesAndInterfaces(clazz.getSuperclass())); } return result; }
From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java
public static LinkedList<Field> _getAllFields(LinkedList<Field> fields, Class<?> type) { if (Argument.isEmpty(fields)) { fields = new LinkedList<Field>(); }//w ww . j ava 2s . co m for (Field field : type.getDeclaredFields()) { fields.add(field); } if (type.getSuperclass() != null) { fields.addAll(_getAllFields(fields, type.getSuperclass())); } return fields; }
From source file:Main.java
private static void _addSuperTypes(Class<?> cls, Class<?> endBefore, Collection<Class<?>> result, boolean addClassItself) { if (cls != endBefore && cls != null && cls != Object.class) { if (addClassItself) { if (!result.contains(cls)) { result.add(cls);/*from w w w.j a v a2s . c o m*/ } else { return; } } for (Class<?> intCls : cls.getInterfaces()) { _addSuperTypes(intCls, endBefore, result, true); } _addSuperTypes(cls.getSuperclass(), endBefore, result, true); } }
From source file:activiti.common.persistence.util.ReflectHelper.java
public static Class<?> getUserClass(Object instance) { Validate.notNull(instance, "Instance must not be null"); Class clazz = instance.getClass(); if ((clazz != null) && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) { Class<?> superClass = clazz.getSuperclass(); if ((superClass != null) && !Object.class.equals(superClass)) { return superClass; }//w ww . j av a2 s . c o m } return clazz; }
From source file:Main.java
private static void _addSuperTypes(Class<?> cls, Class<?> endBefore, ArrayList<Class<?>> result, boolean addClassItself) { if (cls == endBefore || cls == null || cls == Object.class) { return;/*www. j a va2 s.c om*/ } if (addClassItself) { if (result.contains(cls)) { // already added, no need to check supers return; } result.add(cls); } for (Class<?> intCls : cls.getInterfaces()) { _addSuperTypes(intCls, endBefore, result, true); } _addSuperTypes(cls.getSuperclass(), endBefore, result, true); }
From source file:Main.java
private static void _addSuperTypes(Class<?> cls, Class<?> endBefore, Collection<Class<?>> result, boolean addClassItself) { if (cls == endBefore || cls == null || cls == Object.class) { return;// w ww. j ava 2 s .co m } if (addClassItself) { if (result.contains(cls)) { // already added, no need to check supers return; } result.add(cls); } for (Class<?> intCls : cls.getInterfaces()) { _addSuperTypes(intCls, endBefore, result, true); } _addSuperTypes(cls.getSuperclass(), endBefore, result, true); }
From source file:app.commons.ReflectionUtils.java
/** * We cannot use <code>clazz.getField(String fieldName)</code> because it only returns public fields. */// w w w.j a v a 2 s.co m public static Field getField(Class clazz, String fieldName) { Class currentClass = clazz; while (currentClass != null) { try { Field field = currentClass.getDeclaredField(fieldName); field.setAccessible(true); return field; } catch (NoSuchFieldException e) { currentClass = currentClass.getSuperclass(); } } throw new RuntimeException(new NoSuchFieldException(fieldName)); }