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

/**
 * <p>Gets a <code>List</code> of superclasses for the given class.</p>
 *
 * @param cls  the class to look up, may be <code>null</code>
 * @return the <code>List</code> of superclasses in order going up from this one
 *  <code>null</code> if null input
 *//*  www .ja  v  a2s  .  co m*/
public static List getAllSuperclasses(Class cls) {
    if (cls == null) {
        return null;
    }
    List classes = new ArrayList();
    Class superclass = cls.getSuperclass();
    while (superclass != null) {
        classes.add(superclass);
        superclass = superclass.getSuperclass();
    }
    return classes;
}

From source file:Main.java

public static <A extends Annotation> A getAnnotationFromHierarchy(final Class<?> clazz,
        final Class<A> annotation) {
    Class<?> currentClass = clazz;
    A annotationInstance;//www  .  jav  a2 s.  c om
    do {
        annotationInstance = currentClass.getAnnotation(annotation);
        currentClass = currentClass.getSuperclass();
    } while (annotationInstance == null && currentClass != Object.class);
    return annotationInstance;
}

From source file:grails.plugin.springsecurity.acl.util.ProxyUtils.java

/**
 * Finds the unproxied superclass if proxied.
 * @param clazz  the potentially proxied class
 * @return  the unproxied class/*from   ww  w  .jav  a  2s .  c o m*/
 */
public static Class<?> unproxy(final Class<?> clazz) {
    Class<?> current = clazz;
    while (isProxy(current)) {
        current = current.getSuperclass();
    }
    return current;
}

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

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

From source file:fr.exanpe.tapestry.tldgen.utils.JavadocBeanMerger.java

/**
 * Recursively search the Javadoc into parent classes
 * Only manage the classes which the source files are in the project.
 * Stops when {@link Object} class is found
 * /*from  ww w .j  a va  2 s  .  co m*/
 * @param comp the "Javadoc" object
 * @param a the Attribute searched
 * @param infos the main Javadoc structure
 * @return a String corresponding to the Javadoc documentation, or null is not found
 */
private static String getParentAttributeDescription(ComponentBean comp, Attribute a, ComponentsInfoBean infos) {
    try {
        Class<?> c = Class.forName(comp.getClassName());

        if (c.getSuperclass() == null) {
            return null;
        }

        comp = infos.getComponentByClassName(c.getSuperclass().getName());

        if (comp != null) {
            ParameterBean superParam = comp.getParameterByName(a.getName());

            if (superParam != null) {
                return superParam.getDescription();
            } else {
                return getParentAttributeDescription(comp, a, infos);
            }
        }

        // else pas enregistr donc pas dans les sources donc on quitte

    } catch (ClassNotFoundException e) {
        // should not happen
        // just return null is ok
    }

    return null;
}

From source file:Main.java

public static Set<Class<?>> findSuperTypes(Class<?> targetClass) {
    Set<Class<?>> classes = new HashSet<Class<?>>();
    Class<?> clazz = targetClass;
    while (clazz != null) {
        classes.add(clazz);//from  ww  w . ja  va 2s .co  m
        addInterfaces(classes, clazz.getInterfaces());
        clazz = clazz.getSuperclass();
    }
    return classes;
}

From source file:Main.java

public static String[][] returnTable(Collection E) {
    if ((E == null) || E.isEmpty()) {
        System.out.println("The collection is empty!");
    }/*from   ww w  .  j  av a  2 s.c om*/

    Set<Field> collectionFields = new TreeSet<>(new Comparator<Field>() {
        @Override
        public int compare(Field o1, Field o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    for (Object o : E) {
        Class c = o.getClass();
        createSetOfFields(collectionFields, c);
        while (c.getSuperclass() != null) {
            c = c.getSuperclass();
            createSetOfFields(collectionFields, c);
        }
    }
    String[][] exitText = new String[E.size() + 1][collectionFields.size() + 1];
    exitText[0][0] = String.format("%20s", "Class");
    int indexOfColumn = 0;
    for (Field f : collectionFields) {
        exitText[0][indexOfColumn + 1] = String.format("%20s", f.getName());
        indexOfColumn++;

    }
    int indexOfRow = 0;
    for (Object o : E) {
        indexOfColumn = 0;
        exitText[indexOfRow + 1][0] = String.format("%20s", o.getClass().getSimpleName());
        for (Field field : collectionFields) {
            try {
                field.setAccessible(true);
                if (field.get(o) instanceof Date) {
                    exitText[indexOfRow + 1][indexOfColumn + 1] = String.format("%20tD", field.get(o));
                } else {
                    String temp = String.valueOf(field.get(o));
                    exitText[indexOfRow + 1][indexOfColumn + 1] = String.format("%20s", temp);
                }
            } catch (Exception e) {
                exitText[indexOfRow + 1][indexOfColumn + 1] = String.format("%20s", "-");
            }
            indexOfColumn++;
        }
        indexOfRow++;
    }
    return exitText;
}

From source file:gumga.framework.application.GumgaUntypedRepository.java

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()));
    }//w  ww. jav a 2 s .  co m
    aRetornar.addAll(Arrays.asList(classe.getDeclaredFields()));
    return aRetornar;
}

From source file:Main.java

public static Field getField(Class<?> klass, String member) throws NoSuchFieldException {
    try {/*from   w w w . ja  v  a  2 s . c om*/
        return klass.getDeclaredField(member);
    } catch (NoSuchFieldException e) {
        if (klass.getSuperclass() != null)
            return getField(klass.getSuperclass(), member);
        else
            throw new NoSuchFieldException(String.format("Class does not contain member %s!", member));
    }
}

From source file:Main.java

private static List<Field> getAllFieads(Object o) {
    ArrayList<Field> fields = new ArrayList<Field>();
    if (o != null) {
        Class<?> type = o.getClass();
        do {/* w  w  w. ja  va2  s.co  m*/
            for (Field f : type.getDeclaredFields()) {
                fields.add(f);
            }
            type = type.getSuperclass();
        } while (type != null);
    }
    return fields;
}