List of usage examples for java.lang Class getSuperclass
@HotSpotIntrinsicCandidate public native Class<? super T> getSuperclass();
From source file:kina.utils.Utils.java
private static Field[] getAllFieldsRec(Class clazz, List<Field> fields) { Class superClazz = clazz.getSuperclass(); if (superClazz != null) { getAllFieldsRec(superClazz, fields); }/*from w ww . jav a 2 s. c o m*/ fields.addAll(Arrays.asList(clazz.getDeclaredFields())); return fields.toArray(new Field[fields.size()]); }
From source file:com.fjn.helper.common.util.StreamUtil.java
public static void close(Object closeable) { if (closeable != null) { try {/*from www . j a v a 2 s .co m*/ if (closeable instanceof Closeable) { ((Closeable) closeable).close(); return; } } catch (Exception ex) { // ignore it; } // close(); Method closeMethod = null; Class<?> targetClass = closeable.getClass(); while (closeMethod == null && targetClass != null) { try { closeMethod = targetClass.getDeclaredMethod("close", new Class[0]); } catch (Exception ex) { targetClass = targetClass.getSuperclass(); } } if (closeMethod != null) { try { closeMethod.invoke(closeable, new Object[0]); } catch (Exception e) { // ignore it } } } }
From source file:de.xwic.appkit.core.model.EntityModelFactory.java
/** * Creates a new entity model based upon the specified entity. * @param entity//from ww w . j a va 2s . co m * @return * @throws EntityModelException */ @SuppressWarnings("unchecked") public static IEntityModel createModel(IEntity entity) { // create model and InvocationHandler Set<Class<?>> interfacesSet = new HashSet<Class<?>>(); Class<? extends IEntity> clazz = entity.getClass(); interfacesSet.add(IEntityModel.class); // recursivly add all interfaces Class<?> c = clazz; while (c != null) { Class<?>[] orgInterfaces = c.getInterfaces(); for (int i = 0; i < orgInterfaces.length; i++) { interfacesSet.add(orgInterfaces[i]); } c = c.getSuperclass(); } Class[] interfaces = new Class[interfacesSet.size()]; int idx = 0; for (Iterator<Class<?>> it = interfacesSet.iterator(); it.hasNext();) { interfaces[idx++] = it.next(); } EntityModelInvocationHandler ih = new EntityModelInvocationHandler(entity); return (IEntityModel) Proxy.newProxyInstance(classLoader, interfaces, ih); }
From source file:Main.java
/** * Attempts to find a method with the given name and argument types on the specified class. Other than Class's * getMethod(String, Class...) method, this method will also return protected and private methods. * * @param clazz Class supposed to offer the method being searched. * @param methodName Name of the method. * @param argumentTypes The arguments found in the method signature, if any. * @return a method with the given name and argument types on the specified class, if any. *//*from w ww .j ava 2 s.c o m*/ public static synchronized Method getMethod(final Class clazz, final String methodName, final Class... argumentTypes) { try { return clazz.getMethod(methodName, argumentTypes); } catch (NoSuchMethodException e) { /* Ok, so there's no public method... */ } Class runner = clazz; while (runner != null) { try { return runner.getDeclaredMethod(methodName, argumentTypes); } catch (NoSuchMethodException e) { /* No luck here either */ } runner = runner.getSuperclass(); } /* Still no luck, means there is no suitable method */ return null; }
From source file:gumga.framework.presentation.api.CSVGeneratorAPI.java
public static List<Field> getAllAtributes(Class clazz) { List<Field> fields = new ArrayList<>(); Class superClass = clazz.getSuperclass(); if (superClass != null && !superClass.equals(Object.class)) { fields.addAll(getAllAtributes(clazz.getSuperclass())); }/*from w w w . j a v a2 s .c o m*/ for (Field f : clazz.getDeclaredFields()) { if (!Modifier.isStatic(f.getModifiers())) { fields.add(f); } } return fields; }
From source file:com.github.juanmf.java2plant.Parser.java
private static void addSuperClass(Class<?> c, Set<Class<?>> newClasses) { Class<?> superclass = c.getSuperclass(); if (null == superclass || Object.class.equals(superclass)) { return;// w ww . j a va2 s.c o m } newClasses.add(superclass); addSuperClass(superclass, newClasses); addInterfaces(superclass, newClasses); }
From source file:com.nabla.wapp.server.database.SqlInsert.java
@SuppressWarnings("unchecked") protected static IRecordTable getTable(final Class clazz) { Assert.notNull(clazz, "have you forgotten to set @IRecordTable for record " + clazz.getSimpleName()); final IRecordTable t = (IRecordTable) clazz.getAnnotation(IRecordTable.class); return (t != null) ? t : getTable(clazz.getSuperclass()); }
From source file:com.aw.support.reflection.AttributeAccessor.java
public static Field getField(Class cls, String attrName) throws Throwable { Field field = null;//ww w. ja v a 2 s . c om try { field = cls.getDeclaredField(attrName); } catch (NoSuchFieldException e) { try { // Se va a buscar en la superclase field = cls.getSuperclass().getDeclaredField(attrName); } catch (NoSuchFieldException e2) { try { // Se va a buscar en la superclase 2 field = cls.getSuperclass().getSuperclass().getDeclaredField(attrName); } catch (NoSuchFieldException e3) { field = cls.getSuperclass().getSuperclass().getSuperclass().getDeclaredField(attrName); } } } catch (SecurityException e) { throw e; } return field; }
From source file:com.searchbox.core.ref.ReflectionUtils.java
public static List<Field> findAllFields(Class<?> element) { ArrayList<Field> fields = new ArrayList<Field>(); if (element != null) { for (Field field : element.getDeclaredFields()) { fields.add(field);/*from w w w. ja va 2s. com*/ } fields.addAll(findAllFields(element.getSuperclass())); return fields; } else { return Collections.emptyList(); } }
From source file:Main.java
public static Set<Class<?>> getAllImplementedInterfaceNames(Class<?> klass) { Set<Class<?>> interfaces = new HashSet<Class<?>>(); while (klass != null) { Class<?>[] localInterfaces = klass.getInterfaces(); for (Class<?> intf : localInterfaces) { interfaces.add(intf);/* ww w . j a v a 2 s. c o m*/ exploreSuperInterfaces(intf, interfaces); } klass = klass.getSuperclass(); } return interfaces; }