Example usage for java.lang Class getSuperclass

List of usage examples for java.lang Class getSuperclass

Introduction

In this page you can find the example usage for java.lang Class getSuperclass.

Prototype

@HotSpotIntrinsicCandidate
public native Class<? super T> getSuperclass();

Source Link

Document

Returns the Class representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class .

Usage

From source file:Main.java

private static void collectAssignables(Class c1, Class c2, Set s) {
    if (c1.isAssignableFrom(c2)) {
        s.add(c1);//from  w  w  w  .j  a  va  2 s . com
    }
    Class sc = c1.getSuperclass();
    if (sc != null) {
        collectAssignables(sc, c2, s);
    }
    Class[] itf = c1.getInterfaces();
    for (int i = 0; i < itf.length; ++i) {
        collectAssignables(itf[i], c2, s);
    }
}

From source file:Main.java

static void findAllInterfaces(Class c, Set<Class> interfaces) {
    if (c.isInterface()) {
        interfaces.add(c);//  www.  ja  v  a  2 s  .  c  om
    }
    Class s = c.getSuperclass();
    if (s != null) {
        findAllInterfaces(s, interfaces);
    }
    Class[] is = c.getInterfaces();
    for (int i = 0; i < is.length; i++) {
        findAllInterfaces(is[i], interfaces);
    }
}

From source file:Main.java

/**
 * Convenience method to obtain the Swing class from which this
 * component was directly or indirectly derived.
 * //from   w  w w  .  j av  a2s.c o m
 * @param <T>
 * @param component The component whose Swing superclass is to be
 * determined
 * @return The nearest Swing class in the inheritance tree
 */
public static <T extends JComponent> Class<?> getJClass(T component) {
    Class<?> clazz = component.getClass();
    while (!clazz.getName().matches("javax.swing.J[^.]*$")) {
        clazz = clazz.getSuperclass();
    }
    return clazz;
}

From source file:Main.java

private static void addFields(Class<?> clazz, List<Field> list) {
    for (Field f : clazz.getFields()) {
        list.add(f);// w  w  w.  ja v a 2  s.  co  m
    }
    Class<?> superClass = clazz.getSuperclass();
    if (superClass != null) {
        addFields(superClass, list);
    }
}

From source file:Main.java

public static boolean isSubclassOf(Class clazz, Class what) {
    while (clazz != null) {
        if (clazz == what)
            return true;

        clazz = clazz.getSuperclass();
    }//w  w  w  .  java  2s  .c o  m

    return false;
}

From source file:testReflection.java

public static Field[] getAllFields(Class klass) {
    List<Field> fields = new ArrayList<Field>();
    fields.addAll(Arrays.asList(klass.getDeclaredFields()));
    if (klass.getSuperclass() != null) {
        fields.addAll(Arrays.asList(getAllFields(klass.getSuperclass())));
    }/*from  ww w.jav  a 2s .  c om*/
    return fields.toArray(new Field[] {});
}

From source file:com.ht.halo.dorado.util.proxy.ProxyBeanUtils.java

public static Class<?> getProxyTargetType(Class<?> cl) {
    while (ProxyBeanUtils.isProxy(cl)) {
        cl = cl.getSuperclass();
    }/*from  ww w.j  a  v a2  s  . c o  m*/
    return cl;
}

From source file:Main.java

/**
 * Return a List of super-classes for the given class.
 *
 * @param clazz the class to look up//from   ww  w  .  j  av  a  2s .c  o  m
 * @return the List of super-classes in order going up from this one
 */
public static List<Class<?>> getAllSuperclasses(Class<?> clazz) {
    List<Class<?>> classes = new ArrayList<Class<?>>();

    Class<?> superclass = clazz.getSuperclass();
    while (superclass != null) {
        classes.add(superclass);
        superclass = superclass.getSuperclass();
    }

    return classes;
}

From source file:Main.java

public static Field findField(Class src, String fieldName) throws Exception {
    try {/*from ww w  .  ja  va2 s  . c  o  m*/
        return src.getDeclaredField(fieldName);
    } catch (Exception e) {
        if (src.getSuperclass() != null) {
            return findField(src.getSuperclass(), fieldName);
        } else {
            throw e;
        }
    }
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.acl.ProxyUtils.java

/**
 * Finds the unproxied superclass if proxied.
 * @param clazz  the potentially proxied class
 * @return  the unproxied class//from w w w  . j  a  va  2 s. c om
 */
public static Class<?> unproxy(final Class<?> clazz) {
    Class<?> current = clazz;
    while (AopUtils.isCglibProxyClass(current)) {
        current = current.getSuperclass();
    }
    return current;
}