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

/**
 * @param type/* w  w  w . jav  a2 s .co  m*/
 * @param fieldName
 * @return
 */
private static Field getField(Class<?> type, String fieldName) {
    Class<?> currentType = type;
    while (!currentType.equals(Object.class)) {
        for (Field field : currentType.getDeclaredFields()) {
            if (field.getName().equals(fieldName)) {
                return field;
            }
        }
        currentType = currentType.getSuperclass();
    }
    return null;
}

From source file:com.mewmew.fairy.v1.cli.AnnotatedCLI.java

public static <T> AnnotatedCLI getMagicCLI(Class<T> c) {
    Stack<Class> stack = new Stack<Class>();
    Class p = c;
    while (p != Object.class) {
        stack.push(p);/*from   ww w.  j a  va2  s.  com*/
        p = p.getSuperclass();
    }
    return new AnnotatedCLI(stack.toArray(new Class[stack.size()]));
}

From source file:Main.java

private static void processAttachAllProperties(Class<? extends Object> clazz, List<Field> fields) {
    if (!isEffectiveClass(clazz)) {
        return;//from  ww w  .j  av  a 2s  .  com
    }

    Field[] declaredFields = clazz.getDeclaredFields();
    for (Field field : declaredFields) {
        fields.add(field);
    }

    processAttachAllProperties(clazz.getSuperclass(), fields);
}

From source file:Main.java

public static Field findFieldByClassAndTypeAndName(Class<?> targetObject, Class<?> fieldType,
        String fieldName) {//from w ww  . j  av  a  2s . c  om
    Class clazz = targetObject;
    do {
        for (Field field : clazz.getDeclaredFields()) {
            if (field.getType() == fieldType && field.getName().equals(fieldName)) {
                field.setAccessible(true);
                return field;
            }
        }
        clazz = clazz.getSuperclass();
    } while (clazz != null);
    throw new NoSuchFieldError("Field of type " + fieldType.getName() + " in class " + targetObject.getName());
}

From source file:com.evolveum.midpoint.prism.xml.XsdTypeMapper.java

/**
 * Returns the class in the type mapping.
 * The class supplied by the caller may be a subclass of what we have in the map.
 * This returns the class that in the mapping.
 *//*from   ww  w.  j  ava2  s  .  c o  m*/
public static Class<?> getTypeFromClass(Class<?> clazz) {
    if (javaToXsdTypeMap.containsKey(clazz)) {
        return clazz;
    }
    Class<?> superClazz = clazz.getSuperclass();
    if (superClazz != null) {
        return getTypeFromClass(superClazz);
    }
    return null;
}

From source file:com.sunway.cbm.util.web.ReflectionUtils.java

public static List<Field> getDeclaredFields(Class<?> clazz) {
    List<Field> fieldRes = new ArrayList<Field>();
    Class<?> superclass = clazz.getSuperclass();
    if (superclass != null) {
        fieldRes.addAll(getDeclaredFields(superclass));
    }/* w w  w  . j  av a 2 s.com*/
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        fieldRes.add(field);
    }
    return fieldRes;
}

From source file:GenericsUtil.java

private static void gatherTypeVariables(final Class<?> clazz, final Type type,
        final Map<TypeVariable<?>, Type> map) {
    if (clazz == null) {
        return;/* w ww .  ja va 2s.co  m*/
    }
    gatherTypeVariables(type, map);

    final Class<?> superClass = clazz.getSuperclass();
    final Type superClassType = clazz.getGenericSuperclass();
    if (superClass != null) {
        gatherTypeVariables(superClass, superClassType, map);
    }
    final Class<?>[] interfaces = clazz.getInterfaces();
    final Type[] interfaceTypes = clazz.getGenericInterfaces();
    for (int i = 0; i < interfaces.length; ++i) {
        gatherTypeVariables(interfaces[i], interfaceTypes[i], map);
    }
}

From source file:GenericsUtil.java

private static Map<TypeVariable<?>, Type> getTypeVariableMap(final Class<?> clazz) {
    if (clazz == null) {
        return Collections.emptyMap();
    }//w  w  w . j  a  v a 2s.co m
    final Map<TypeVariable<?>, Type> map = new LinkedHashMap<TypeVariable<?>, Type>();
    final Class<?> superClass = clazz.getSuperclass();
    final Type superClassType = clazz.getGenericSuperclass();
    if (superClass != null) {
        gatherTypeVariables(superClass, superClassType, map);
    }
    final Class<?>[] interfaces = clazz.getInterfaces();
    final Type[] interfaceTypes = clazz.getGenericInterfaces();
    for (int i = 0; i < interfaces.length; ++i) {
        gatherTypeVariables(interfaces[i], interfaceTypes[i], map);
    }
    return map;
}

From source file:com.sugaronrest.restapicalls.ModuleInfo.java

/**
 *  Checks if field is numeric or not.// w  w w . j  a  va  2 s. c  o  m
 *
 * @param type Field type.
 * @return True or false.
 */
public static boolean isTypeNumeric(Class type) {
    if (type == null) {
        return false;
    }

    if (type.getSuperclass() == null) {
        return false;
    }

    return type.getSuperclass().equals(Number.class);
}

From source file:com.dapeng.dao.orm.GenericsUtils.java

/**
 * cglib AOP, ?Class./*from   w  w w  .  j a va  2s.c  o m*/
 */
public static Class<?> getUserClass(Class<?> clazz) {
    if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
        Class<?> superClass = clazz.getSuperclass();
        if (superClass != null && !Object.class.equals(superClass)) {
            return superClass;
        }
    }
    return clazz;
}