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

@SuppressWarnings("rawtypes")
private static Map<String, Class> getClassFields(Class clazz, boolean includeParentClass) {

    Map<String, Class> map = new HashMap<String, Class>();

    Field[] fields = clazz.getDeclaredFields();

    for (Field field : fields) {

        map.put(clazz.getName() + "." + field.getName(), field.getType());// field.getType()

    }/*from w  ww .  j a  va 2 s  .co m*/

    if (includeParentClass)

        getParentClassFields(map, clazz.getSuperclass());

    return map;

}

From source file:Main.java

/**
 * Returns all fields declared in the class passed as argument or in its super classes annotated with
 * the supplied annotation.//from  w w  w  .j a v  a2 s.  c  o  m
 */
public static List<Field> getAllDeclaredField(Class<?> clazz, Class<? extends Annotation> annotationClass) {
    final List<Field> result = new LinkedList<Field>();
    for (final Field field : clazz.getDeclaredFields()) {
        final Object jakeOption = field.getAnnotation(annotationClass);
        if (jakeOption != null) {
            result.add(field);
        }
    }
    final Class<?> superClass = clazz.getSuperclass();
    if (superClass != null) {
        result.addAll(getAllDeclaredField(superClass, annotationClass));
    }
    return result;
}

From source file:Main.java

@Nullable
public static Class<?> getInterfaceOfClassExtendingGivenInterface(final Class<?> possibleExtendingClass,
        final Class<?> givenInterface) {
    if (!givenInterface.isAssignableFrom(possibleExtendingClass)) {
        // not possible
        return null;
    }/*from ww w.  ja  v  a  2s . c o  m*/

    // assignable, find the interface
    Class<?> viewClass = possibleExtendingClass;
    while (viewClass != null) {
        final Class<?>[] interfaces = viewClass.getInterfaces();
        for (final Class<?> clazz : interfaces) {
            if (givenInterface.isAssignableFrom(clazz)) {
                return clazz;
            }
        }

        // check super
        viewClass = viewClass.getSuperclass();
    }

    // should never happen
    return null;
}

From source file:com.yc.modules.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;
        }//  w  ww  .j  a  va  2  s.  com
    }
    return clazz;

}

From source file:Main.java

public static boolean hasCustomEquals(Class c) {
    Class origClass = c;/*w w  w  .  jav  a2s .  c o m*/
    if (_customEquals.containsKey(c)) {
        return _customEquals.get(c);
    }

    while (!Object.class.equals(c)) {
        try {
            c.getDeclaredMethod("equals", Object.class);
            _customEquals.put(origClass, true);
            return true;
        } catch (Exception ignored) {
        }
        c = c.getSuperclass();
    }
    _customEquals.put(origClass, false);
    return false;
}

From source file:com.jlfex.hermes.common.utils.Reflections.java

@SuppressWarnings("rawtypes")
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;
        }//from  www  .ja  v a 2  s  .c o  m
    }
    return clazz;

}

From source file:cn.com.qiqi.order.utils.Reflections.java

@SuppressWarnings("rawtypes")
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.j  a va2s . co m*/
    }
    return clazz;

}

From source file:net.cpollet.jixture.hibernate3.helper.Hibernate3MappingDefinitionHolder.java

private static Iterable<Field> getFieldsUpToObject(Class<?> startClass) {
    List<Field> currentClassFields = new ArrayList<Field>();
    currentClassFields.addAll(Arrays.asList(startClass.getDeclaredFields()));
    Class<?> parentClass = startClass.getSuperclass();

    if (null != parentClass) {
        List<Field> parentClassFields = (List<Field>) getFieldsUpToObject(parentClass);
        currentClassFields.addAll(parentClassFields);
    }//from   ww w  .  jav  a  2s .  c  o m

    return currentClassFields;
}

From source file:springobjectmapper.ReflectionHelper.java

public static List<Field> getFields(Class<?> c) {
    List<Field> results = new ArrayList<Field>();
    do {//from   w w w.j  ava 2s  . c om
        Field[] fields = c.getDeclaredFields();
        for (Field field : fields) {
            if (isEntityField(field)) {
                results.add(field);
            }
            field.setAccessible(true);
        }
        c = c.getSuperclass();
    } while (c != null);
    return results;
}

From source file:com.nabla.wapp.server.general.Util.java

public static Class getGenericDeclaration(Class clazz, int position) {
    Assert.argumentNotNull(clazz);/*from   w w w . ja  v  a  2s. c o  m*/
    Assert.state(position >= 0);

    Type classGenType = clazz.getGenericSuperclass();

    // special CGLIB workaround -- get generic superclass of superclass
    if (clazz.getName().contains("$$EnhancerByCGLIB$$")) {
        classGenType = clazz.getSuperclass().getGenericSuperclass();
    }

    if (classGenType instanceof ParameterizedType) {
        Type[] params = ((ParameterizedType) classGenType).getActualTypeArguments();

        if ((params != null) && (params.length > position)) {
            return (Class) params[position];
        }
    }

    for (Type ifGenType : clazz.getGenericInterfaces()) {
        if (ifGenType instanceof ParameterizedType) {
            Type[] params = ((ParameterizedType) ifGenType).getActualTypeArguments();

            if ((params != null) && (params.length > position)) {
                return (Class) params[position];
            }
        }
    }

    if (log.isErrorEnabled())
        log.error("fail to find class of generic parameter " + position + " of class '" + clazz.getSimpleName()
                + "'");

    return null;
}