List of usage examples for java.lang Class getSuperclass
@HotSpotIntrinsicCandidate public native Class<? super T> getSuperclass();
From source file:com.springframework.beans.BeanUtils.java
/** * Find a method with the given method name and minimal parameters (best case: none), * declared on the given class or one of its superclasses. Will return a public, * protected, package access, or private method. * <p>Checks {@code Class.getDeclaredMethods}, cascading upwards to all superclasses. * @param clazz the class to check/* w ww. jav a2 s . c o m*/ * @param methodName the name of the method to find * @return the Method object, or {@code null} if not found * @throws IllegalArgumentException if methods of the given name were found but * could not be resolved to a unique method with minimal parameters * @see Class#getDeclaredMethods */ public static Method findDeclaredMethodWithMinimalParameters(Class<?> clazz, String methodName) throws IllegalArgumentException { Method targetMethod = findMethodWithMinimalParameters(clazz.getDeclaredMethods(), methodName); if (targetMethod == null && clazz.getSuperclass() != null) { targetMethod = findDeclaredMethodWithMinimalParameters(clazz.getSuperclass(), methodName); } return targetMethod; }
From source file:br.gov.frameworkdemoiselle.ldap.internal.ClazzUtils.java
/** * Build a super classes List(Class(? extends Object)) * /* w ww.j a va 2 s.com*/ * @return List of Super Classes */ public static List<Class<? extends Object>> getSuperClasses(Class<?> entryClass) { List<Class<? extends Object>> list = new ArrayList<Class<? extends Object>>(); Class<? extends Object> superClazz = entryClass.getSuperclass(); while (superClazz != null) { list.add(superClazz); superClazz = superClazz.getSuperclass(); } return list; }
From source file:com.smart.utils.ReflectionUtils.java
/** * ?classString,list,listString/*from w w w .ja v a 2s. com*/ * * @param clz * @return */ public static List<String> getAllFieldNames(Class clz) { List result = new ArrayList(); Map allFields = new HashMap(); // ??? List classFamilyTree = new LinkedList(); classFamilyTree.add(clz); Class tempSuperClass = clz; while ((tempSuperClass = tempSuperClass.getSuperclass()) != null) { classFamilyTree.add(tempSuperClass); } // Map???field?????? for (int i = classFamilyTree.size() - 1; i >= 0; i--) { Class tempClass = (Class) classFamilyTree.get(i); Field[] fieldsOfTempClass = tempClass.getDeclaredFields(); for (int j = 0; j < fieldsOfTempClass.length; j++) { Field field = fieldsOfTempClass[j]; allFields.put(field.getName(), field.getName()); } } // map?list for (Iterator iter = allFields.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); result.add(entry.getValue()); } return result; }
From source file:com.ms.commons.test.common.ReflectUtil.java
protected static void getDeclaredFields(Class<?> clazz, List<Field> fieldList) { if (clazz == Object.class) { return;//from w w w . j a va 2 s . co m } Field[] fields = clazz.getDeclaredFields(); if (fields != null) { for (Field field : fields) { fieldList.add(field); } } getDeclaredFields(clazz.getSuperclass()); }
From source file:com.smart.utils.ReflectionUtils.java
/** * ?classFieldlistlistField/*from w w w. j av a 2 s . co m*/ * * @param clz * @return */ public static List<Field> getAllFields(Class clz) { List result = new ArrayList(); Map allFields = new HashMap(); // ??? List classFamilyTree = new LinkedList(); classFamilyTree.add(clz); Class tempSuperClass = clz; while ((tempSuperClass = tempSuperClass.getSuperclass()) != null) { classFamilyTree.add(tempSuperClass); } // Map???field?????? for (int i = classFamilyTree.size() - 1; i >= 0; i--) { Class tempClass = (Class) classFamilyTree.get(i); Field[] fieldsOfTempClass = tempClass.getDeclaredFields(); for (int j = 0; j < fieldsOfTempClass.length; j++) { Field field = fieldsOfTempClass[j]; allFields.put(field.getName(), field); } } // map?list for (Iterator iter = allFields.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); result.add(entry.getValue()); } return result; }
From source file:me.totalfreedom.totalfreedommod.util.FUtil.java
@SuppressWarnings("unchecked") public static <T> T getField(Object from, String name) { Class<?> checkClass = from.getClass(); do {/*from w w w . j a v a 2 s . c o m*/ try { Field field = checkClass.getDeclaredField(name); field.setAccessible(true); return (T) field.get(from); } catch (NoSuchFieldException | IllegalAccessException ex) { } } while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null)); return null; }
From source file:com.mine.core.util.ReflectUtils.java
/** * ?CGLib??.//from ww w . ja v a2 s . co m */ public static Class<?> getProxyBeanOrgClass(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; } } return clazz; }
From source file:com.rockagen.commons.util.ClassUtil.java
/** * obtain method list of specified class If recursively is true, obtain * method from all class hierarchy//from w w w . j a v a 2 s . c om * * @param clazz class * @param recursively recursively * @param methodName method name * @param parameterTypes parameter types * @return method */ public static Method getDeclaredMethod(Class<?> clazz, boolean recursively, String methodName, Class<?>... parameterTypes) { try { return clazz.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { Class<?> superClass = clazz.getSuperclass(); if (superClass != null && recursively) { return getDeclaredMethod(superClass, true, methodName, parameterTypes); } } catch (SecurityException e) { log.error("{}", e.getMessage(), e); } return null; }
From source file:de.micromata.genome.util.runtime.ClassUtils.java
/** * Find first method with given name./*w ww. j a va 2s . c o m*/ * * @param clazz the clazz * @param method the method * @return null if not found */ public static Method findFirstMethod(Class<?> clazz, String method) { for (Method m : clazz.getDeclaredMethods()) { if (m.getName().equals(method) == true) { return m; } } if (clazz.getSuperclass() != null) { return findFirstMethod(clazz.getSuperclass(), method); } return null; }
From source file:Main.java
public static boolean hasCustomHashCode(Class<?> c) { Class<?> origClass = c; if (_customHash.containsKey(c)) { return _customHash.get(c); }/*from w w w . j ava 2 s. c o m*/ while (!Object.class.equals(c)) { try { c.getDeclaredMethod("hashCode"); _customHash.put(origClass, true); return true; } catch (Exception ignored) { } c = c.getSuperclass(); } _customHash.put(origClass, false); return false; }