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:com.palantir.ptoss.util.Reflections.java

/**
 * Starting at the bottom of a class hierarchy, visit all classes (ancestors) in the hierarchy. Does
 * not visit interfaces./* ww  w . j  a v  a2  s .com*/
 * @param klass Class to use as the bottom of the class hierarchy
 * @param visitor Visitor object
 */
public static void visitClassHierarchy(Class<?> klass, Visitor<Class<?>> visitor) {
    while (klass != null) {
        visitor.visit(klass);
        klass = klass.getSuperclass();
    }
}

From source file:Main.java

/**
 * Get the interfaces for the specified class.
 *
 * @param cls  the class to look up, may be <code>null</code>
 * @param interfacesFound the <code>Set</code> of interfaces for the class
 */// w w w. ja  v  a  2 s .co m
private static void getAllInterfaces(Class cls, List interfacesFound) {
    while (cls != null) {
        Class[] interfaces = cls.getInterfaces();

        for (int i = 0; i < interfaces.length; i++) {
            if (!interfacesFound.contains(interfaces[i])) {
                interfacesFound.add(interfaces[i]);
                getAllInterfaces(interfaces[i], interfacesFound);
            }
        }

        cls = cls.getSuperclass();
    }
}

From source file:com.sun.socialsite.business.impl.JPAListenerManagerImpl.java

/**
 * Returns all listeners which have registered to receive lifecycle
 * events for a class to which the specified entity belongs.
 * @param entity the entity for which listeners are sought.
 *//*from   ww w  . j  av a 2 s  .  c  om*/
private static Collection<Object> getListeners(Object entity) {
    Collection<Object> results = new ArrayList<Object>();
    Set<Class> classes = new HashSet<Class>();
    for (Class clazz = entity.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
        classes.add(clazz);
        Class[] declaredClasses = entity.getClass().getDeclaredClasses();
        for (int i = 0; i < declaredClasses.length; i++) {
            classes.add(declaredClasses[i]);
        }
    }
    for (Class clazz : classes) {
        Collection<Object> listenersForClass = listenersMap.get(clazz);
        if (listenersForClass != null) {
            results.addAll(listenersForClass);
        }
    }
    //log.debug(String.format("getListeners(%s): entityClass=%s results.size=%d", entity, entity.getClass().getCanonicalName(), results.size()));
    return results;
}

From source file:com.searchbox.core.ref.ReflectionUtils.java

public static Field findUnderlying(Class<?> element, String fieldName) {
    if (element != null) {
        Field field = null;/*  ww  w . ja  v  a  2  s  .c  om*/
        try {
            field = element.getDeclaredField(fieldName);
        } catch (Exception e) {

        }
        if (field != null) {
            return field;
        } else {
            return findUnderlying(element.getSuperclass(), fieldName);
        }
    } else {
        return null;
    }
}

From source file:com.darkstar.beanCartography.utils.NameUtils.java

/**
 * Return all types of fields declared by the passed source object's class.
 * If getParentFields is false then only return those fields declared by
 * the object's class passed.  Otherwise, return all fields up the parent
 * hierarchy./*www  .jav  a2  s  .c om*/
 *
 * @param source object that is the source of the lookup.
 * @param includeSuperClasses if true follow the inheritance hierarchy.
 * @return A map containing a list of field objects for each class encountered.
 */
public static <T> Map<String, List<Field>> getFields(T source, boolean includeSuperClasses) {
    Preconditions.checkNotNull(source, "source cannot be null!");
    Map<String, List<Field>> resultMap = new HashMap<>();
    Class<?> clazz = source.getClass();
    List<Field> resultList;

    do {
        resultList = new ArrayList<>();
        getClassFields(clazz, resultList, false);
        resultMap.put(clazz.getCanonicalName(), resultList);
        clazz = clazz.getSuperclass();
    } while (clazz != null && includeSuperClasses);

    return resultMap;
}

From source file:com.netflix.hystrix.contrib.javanica.utils.AopUtils.java

public static <T extends Annotation> Optional<T> getAnnotation(Class<?> type, Class<T> annotation) {
    Validate.notNull(annotation, "annotation cannot be null");
    Validate.notNull(type, "type cannot be null");
    for (Annotation ann : type.getDeclaredAnnotations()) {
        if (ann.annotationType().equals(annotation))
            return Optional.of((T) ann);
    }/*from   w  w  w .  j av a2 s. c  o m*/

    Class<?> superType = type.getSuperclass();
    if (superType != null && !superType.equals(Object.class)) {
        return getAnnotation(superType, annotation);
    }

    return Optional.absent();
}

From source file:io.github.benas.randombeans.util.ReflectionUtils.java

/**
 * Get inherited fields of a given type.
 *
 * @param type the type to introspect//from  ww  w.  j a v a  2  s  . c  o  m
 * @return list of inherited fields
 */
public static List<Field> getInheritedFields(Class<?> type) {
    List<Field> inheritedFields = new ArrayList<>();
    while (type.getSuperclass() != null) {
        Class<?> superclass = type.getSuperclass();
        inheritedFields.addAll(asList(superclass.getDeclaredFields()));
        type = superclass;
    }
    return inheritedFields;
}

From source file:es.csic.iiia.planes.behaviors.AbstractBehaviorAgent.java

@SuppressWarnings("unchecked")
private static Method getMethod(Class<? extends Behavior> bClass, Class<? extends Message> mClass) {
    Method m = null;//  ww w. j a  v  a 2s.co  m
    try {
        m = bClass.getMethod("on", mClass);
    } catch (NoSuchMethodException ex) {
        Class c = mClass.getSuperclass();
        if (Message.class.isAssignableFrom(c)) {
            m = getMethod(bClass, (Class<? extends Message>) c);
        }
    } catch (SecurityException ex) {
        LOG.log(Level.SEVERE, null, ex);
    }
    return m;
}

From source file:edu.usu.sdl.openstorefront.doc.EntityProcessor.java

private static void addSuperClass(Class entity, EntityDocModel docModel) {
    if (entity != null) {
        if (Object.class.getName().equals(entity.getName()) == false) {
            docModel.getParentEntities().add(createEntityModel(entity));
            addSuperClass(entity.getSuperclass(), docModel);
        }/*w  ww.j av a  2s. c  o m*/
    }
}

From source file:com.rapid.develop.core.utils.ReflectionUtils.java

/**
 * ?.//from  w w  w  .  ja v  a  2  s.  c  o  m
 *
 * @param instance 
 * @return 
 */
public static Class<?> getSuperClass(Object instance) {
    Class clazz = instance.getClass();
    if ((clazz != null) && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
        Class<?> superClass = clazz.getSuperclass();
        if ((superClass != null) && !Object.class.equals(superClass)) {
            return superClass;
        }
    }
    return clazz;

}