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.dcits.govsbu.southernbase.baseproject2.modules.utils.Reflections.java

/**
 * ?CGLib??./*from w  w  w  .  j  a va 2 s.  c  om*/
 */
public static Class<?> getUserClass(Object instance) {
    Validate.notNull(instance, "Instance must not be null");
    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;

}

From source file:MethodHashing.java

public static Method findMethodByHash(Class clazz, long hash) throws Exception {
    Method[] methods = clazz.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        if (methodHash(methods[i]) == hash)
            return methods[i];
    }//from  w ww.j av a  2  s .c  o m
    if (clazz.getSuperclass() != null) {
        return findMethodByHash(clazz.getSuperclass(), hash);
    }
    return null;
}

From source file:fit.Binding.java

private static Field getField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
    try {/* w w  w .  j a va 2s. c o  m*/
        return clazz.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
        Class<?> superClass = clazz.getSuperclass();
        if (superClass == null) {
            throw e;
        } else {
            return getField(superClass, fieldName);
        }
    }
}

From source file:com.manydesigns.portofino.utils.Reflections.java

public static Class<?> getUserClass(Object instance) {
    // Assert.notNull(instance, "Instance must not be null");
    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;
        }/*from  ww w.ja va  2  s .co m*/
    }
    return clazz;

}

From source file:com.topsem.common.utils.Reflections.java

/**
 * ?//from  w ww. j  av a  2 s  .  c  o m
 *
 * @param clazz
 * @param classes
 */
public static void getAllSuperclasses(Class<?> clazz, List<Class> classes) {
    Class superClass = clazz.getSuperclass();
    if (superClass != null) {
        getAllSuperclasses(superClass, classes);
        classes.add(superClass);
    }
}

From source file:Main.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Method getMethod(Class clazz, String methodName, final Class[] classes) throws Exception {
    Method method = null;//  w w  w  .  ja  v  a  2  s  .  c  om
    try {
        method = clazz.getDeclaredMethod(methodName, classes);
    } catch (NoSuchMethodException e) {
        try {
            method = clazz.getMethod(methodName, classes);
        } catch (NoSuchMethodException ex) {
            if (clazz.getSuperclass() == null) {
                return method;
            } else {
                method = getMethod(clazz.getSuperclass(), methodName, classes);
            }
        }
    }
    return method;
}

From source file:com.vmware.qe.framework.datadriven.impl.injector.DataInjectorUsingReflection.java

private static Field getField(Class<?> clazz, String fieldName) {
    Class<?> tmpClass = clazz;
    do {//from  w w w .j  av a  2s .co  m
        for (Field field : tmpClass.getDeclaredFields()) {
            String candidateName = field.getName();
            if (!candidateName.equals(fieldName)) {
                continue;
            }
            field.setAccessible(true);
            return field;
        }
        tmpClass = tmpClass.getSuperclass();
    } while (clazz != null);
    throw new RuntimeException("Field '" + fieldName + "' not found on class " + clazz);
}

From source file:MethodHashing.java

public static Constructor findConstructorByHash(Class clazz, long hash) throws Exception {
    Constructor[] cons = clazz.getDeclaredConstructors();
    for (int i = 0; i < cons.length; i++) {
        if (constructorHash(cons[i]) == hash)
            return cons[i];
    }// ww  w  . j  a  va2 s .  com
    if (clazz.getSuperclass() != null) {
        return findConstructorByHash(clazz.getSuperclass(), hash);
    }
    return null;
}

From source file:com.agileEAP.ireport.utils.Reflections.java

public static Class<?> getUserClass(Object instance) {
    Assert.notNull(instance, "Instance must not be null");
    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;
        }//from w  ww.  ja v  a2s  .co m
    }
    return clazz;

}

From source file:com.opensymphony.xwork2.util.AnnotationUtils.java

/**
 *
 * @param clazz The {@link Class} to inspect
 * @param allInterfaces list of all interfaces
 *///from   ww w  .jav  a  2 s . c  o m
public static void addAllInterfaces(Class clazz, List<Class> allInterfaces) {
    if (clazz == null) {
        return;
    }

    Class[] interfaces = clazz.getInterfaces();
    allInterfaces.addAll(Arrays.asList(interfaces));
    addAllInterfaces(clazz.getSuperclass(), allInterfaces);
}