List of usage examples for java.lang Class getSuperclass
@HotSpotIntrinsicCandidate public native Class<? super T> getSuperclass();
From source file:Main.java
@SuppressWarnings("rawtypes") private static List<Method> getParentClassMothds(List<Method> list, Class clazz) { Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { list.add(method);//from w w w. ja v a 2 s . c o m } if (clazz.getSuperclass() == Object.class) { return list; } getParentClassMothds(list, clazz.getSuperclass()); return list; }
From source file:Main.java
/** * <p>Gets a {@code List} of superclasses for the given class.</p> * * @param cls the class to look up, may be {@code null} * @return the {@code List} of superclasses in order going up from this one * {@code null} if null input//from ww w. ja va 2 s.c o m */ public static List<Class<?>> getAllSuperclasses(Class<?> cls) { if (cls == null) { return null; } List<Class<?>> classes = new ArrayList<Class<?>>(); Class<?> superclass = cls.getSuperclass(); while (superclass != null) { classes.add(superclass); superclass = superclass.getSuperclass(); } return classes; }
From source file:com.bstek.dorado.common.event.ClientEventRegistry.java
private static void collectClientEventRegisterInfos(Map<String, ClientEventRegisterInfo> eventMap, Class<?> type) { Class<?> superType = type.getSuperclass(); if (superType != null) { collectClientEventRegisterInfos(eventMap, superType); }//from w w w .ja va2 s. c om Class<?>[] interfaces = type.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { Class<?> interfaceType = interfaces[i]; collectClientEventRegisterInfos(eventMap, interfaceType); } collectClientEventRegisterInfosFromSingleType(type); Map<String, ClientEventRegisterInfo> selfEventMap = typeMap.get(type); if (selfEventMap != null) { eventMap.putAll(selfEventMap); } }
From source file:Main.java
/** * Copy fields from parent object to child object. * * @param parent parent object//from ww w. j a va 2 s . co m * @param child child object * @param <T> child class * @return filled child object */ public static <T> T shallowCopy(Object parent, T child) { try { List<Field> fields = new ArrayList<>(); Class clazz = parent.getClass(); do { fields.addAll(Arrays.asList(clazz.getDeclaredFields())); } while (!(clazz = clazz.getSuperclass()).equals(Object.class)); for (Field field : fields) { field.setAccessible(true); field.set(child, field.get(parent)); } return child; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:io.gumga.application.GumgaUntypedRepository.java
/** * Pegar todos os atributos de uma classe * @param classe objeto que voce deseja pegar os atributos * @return dados da pesquisa/*from w w w.j a v a2 s. com*/ * @throws SecurityException */ public static List<Field> getTodosAtributos(Class classe) throws SecurityException { List<Field> aRetornar = new ArrayList<>(); if (!classe.getSuperclass().equals(Object.class)) { aRetornar.addAll(getTodosAtributos(classe.getSuperclass())); } aRetornar.addAll(Arrays.asList(classe.getDeclaredFields())); return aRetornar; }
From source file:ClassUtil.java
/** * Builds an <b>unordered</b> set of all interface and object classes that * are generalizations of the provided class. * @param classObject the class to find generalization of. * @return a Set of class objects.//www .j a va 2 s.c o m */ public static Set getGeneralizations(Class classObject) { Set generalizations = new HashSet(); generalizations.add(classObject); Class superClass = classObject.getSuperclass(); if (superClass != null) { generalizations.addAll(getGeneralizations(superClass)); } Class[] superInterfaces = classObject.getInterfaces(); for (int i = 0; i < superInterfaces.length; i++) { Class superInterface = superInterfaces[i]; generalizations.addAll(getGeneralizations(superInterface)); } return generalizations; }
From source file:Main.java
/** * <p>Gets a {@code List} of superclasses for the given class.</p> * * @param cls the class to look up, may be {@code null} * @return the {@code List} of superclasses in order going up from this one * {@code null} if null input//from ww w. j ava 2s. c o m */ public static List<Class<?>> getAllSuperclasses(final Class<?> cls) { if (cls == null) { return null; } final List<Class<?>> classes = new ArrayList<Class<?>>(); Class<?> superclass = cls.getSuperclass(); while (superclass != null) { classes.add(superclass); superclass = superclass.getSuperclass(); } return classes; }
From source file:Main.java
private static Field getFieldByNameFromAnywhere(Class<?> aClass, String fieldName) { Field result = null;/*from w w w.j a v a 2s. c o m*/ try { result = aClass.getDeclaredField(fieldName); } catch (Exception e) { result = getFieldByNameFromAnywhere(aClass.getSuperclass(), fieldName); } return result; }
From source file:Main.java
public static void print_class(Class c) { if (c.isInterface()) { System.out.print(Modifier.toString(c.getModifiers()) + " " + typename(c)); } else if (c.getSuperclass() != null) { System.out.print(Modifier.toString(c.getModifiers()) + " class " + typename(c) + " extends " + typename(c.getSuperclass())); } else {/*from www . j av a2 s. c o m*/ System.out.print(Modifier.toString(c.getModifiers()) + " class " + typename(c)); } Class[] interfaces = c.getInterfaces(); if ((interfaces != null) && (interfaces.length > 0)) { if (c.isInterface()) System.out.print(" extends "); else System.out.print(" implements "); for (int i = 0; i < interfaces.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(interfaces[i])); } } System.out.println(" {"); Constructor[] constructors = c.getDeclaredConstructors(); for (int i = 0; i < constructors.length; i++) print_method_or_constructor(constructors[i]); Field[] fields = c.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { print_field(fields[i]); } Method[] methods = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) print_method_or_constructor(methods[i]); System.out.println("}"); }
From source file:Main.java
public static void checkRecyclerView(ViewGroup recyclerView) { checkRecyclerViewOnClassPath();/* w ww. jav a 2 s.c om*/ Class clazz = recyclerView.getClass(); while (clazz != null) { if (clazz.getName().equals(RECYCLERVIEW_CLASS_NAME)) { return; } clazz = clazz.getSuperclass(); } throw new IllegalArgumentException("ViewGroup " + recyclerView.getClass().getName() + " not supported"); }