List of usage examples for java.lang Class getSuperclass
@HotSpotIntrinsicCandidate public native Class<? super T> getSuperclass();
From source file:com.fengduo.bee.commons.util.ObjectUtils.java
/** * @param obj/* w w w .j a v a 2s . c om*/ */ public static void trim(Object obj, Class<?> stopClass) { if (obj == null) { return; } if (stopClass == null) { stopClass = Object.class; } Class<?> objClass = obj.getClass(); boolean nextBreak = false; while (true) { try { trimStringField(obj, objClass); } catch (Exception e) { log.error(e.getMessage(), e); break; } if (nextBreak) { break; } objClass = objClass.getSuperclass(); if (objClass == null || objClass == Object.class) { break; } if (objClass == stopClass) { nextBreak = true; } } }
From source file:com.buaa.cfs.utils.ReflectionUtils.java
/** * Gets all the declared methods of a class including methods declared in superclasses. *///from w ww. j a v a 2s . com public static List<Method> getDeclaredMethodsIncludingInherited(Class<?> clazz) { List<Method> methods = new ArrayList<Method>(); while (clazz != null) { for (Method method : clazz.getDeclaredMethods()) { methods.add(method); } clazz = clazz.getSuperclass(); } return methods; }
From source file:it.sample.parser.util.CommonsUtil.java
/** * //from w w w . ja v a 2 s . c o m * @param propertyName * @param type * @return * @throws SecurityException * @throws NoSuchFieldException */ private static Field getDeclaredField(String propertyName, Class<?> type) throws SecurityException { Field declaredField = null; if (!propertyName.equals("class")) { try { declaredField = type.getDeclaredField(propertyName); } catch (NoSuchFieldException e) { if (type.getSuperclass() != null) { declaredField = getDeclaredField(propertyName, type.getSuperclass()); } } } return declaredField; }
From source file:com.braffdev.server.core.container.injection.DependencyInjector.java
/** * Determines the list of fields that need to be injected. * * @param target the object./* ww w.ja v a2s . c o m*/ * @return the list of fields. */ private static List<Field> getFields(Object target) { List<Field> fields = new ArrayList<Field>(); Class<?> clazz = target.getClass(); while (!Object.class.equals(clazz)) { Field[] declaredFields = clazz.getDeclaredFields(); for (Field field : declaredFields) { // is the Dependency annotation present? if (field.isAnnotationPresent(Dependency.class)) { fields.add(field); } } clazz = clazz.getSuperclass(); } return fields; }
From source file:com.github.gekoh.yagen.util.FieldInfo.java
public static List<FieldInfo> convertDeclaredAndInheritedFields(Class baseEntity) { List<FieldInfo> fields = new ArrayList<FieldInfo>(); Class clazz = baseEntity; while (clazz != null) { convertFields(fields, clazz);//from w ww. ja v a 2s .c om clazz = clazz.getSuperclass(); } return fields; }
From source file:ObjectInspector.java
/** * Recurses up the inheritance chain and collects all the fields * /*from w ww. j ava 2s . c om*/ * @param fields * The collection of fields found so far * @param c * The class to get fields from */ private static void getFields(Collection<Field> fields, Class c) { for (Field f : c.getDeclaredFields()) { fields.add(f); } if (c.getSuperclass() != null) { getFields(fields, c.getSuperclass()); } }
From source file:Main.java
/** * get all fields for a class//w w w. j a v a 2s .c o m * * @param type * @return all fields indexed by their names */ private static Map<String, Field> getAllFields(Class<?> type) { Map<String, Field> fields = new HashMap<String, Field>(); Class<?> currentType = type; while (!currentType.equals(Object.class)) { for (Field field : currentType.getDeclaredFields()) { int mod = field.getModifiers(); /* * by convention, our fields should not have any modifier */ if (mod == 0 || Modifier.isProtected(mod) && !Modifier.isStatic(mod)) { fields.put(field.getName(), field); } } currentType = currentType.getSuperclass(); } return fields; }
From source file:io.github.wysohn.triggerreactor.tools.ReflectionUtil.java
public static List<Field> getAllPublicFields(List<Field> fields, Class<?> c) { fields.addAll(Arrays.asList(c.getFields())); if (c.getSuperclass() != null) { fields = getAllPublicFields(fields, c.getSuperclass()); }// www.jav a2 s.co m return fields; }
From source file:com.cuubez.visualizer.resource.ResourceMetaDataScanner.java
public static boolean isResource(Class<?> clazz) { if (Modifier.isInterface(clazz.getModifiers()) || Modifier.isAbstract(clazz.getModifiers())) { return false; }/*from w w w . j a va 2 s . com*/ if (clazz.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) { return true; } Class<?> declaringClass = clazz; while (!declaringClass.equals(Object.class)) { // try a superclass Class<?> superclass = declaringClass.getSuperclass(); if (superclass.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) { return true; } // try interfaces Class<?>[] interfaces = declaringClass.getInterfaces(); for (Class<?> interfaceClass : interfaces) { if (interfaceClass.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) { return true; } } declaringClass = declaringClass.getSuperclass(); } return false; }
From source file:io.github.wysohn.triggerreactor.tools.ReflectionUtil.java
public static List<Method> getAllPublicMethods(List<Method> methods, Class<?> c) { methods.addAll(Arrays.asList(c.getMethods())); if (c.getSuperclass() != null) { methods = getAllPublicMethods(methods, c.getSuperclass()); }/* ww w. ja v a 2 s . co m*/ return methods; }