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:gemlite.core.util.Util.java

public final static boolean isInterface(Class<?> c, String szInterface) {
    Class<?>[] face = c.getInterfaces();
    for (int i = 0, j = face.length; i < j; i++) {
        if (face[i].getName().equals(szInterface)) {
            return true;
        } else {//  ww w .j av a 2s .  com
            Class<?>[] face1 = face[i].getInterfaces();
            for (int x = 0; x < face1.length; x++) {
                if (face1[x].getName().equals(szInterface)) {
                    return true;
                } else if (isInterface(face1[x], szInterface)) {
                    return true;
                }
            }
        }
    }
    if (null != c.getSuperclass()) {
        return isInterface(c.getSuperclass(), szInterface);
    }
    return false;
}

From source file:Mopex.java

/**
 * Returns a Method that has the signature specified by the calling
 * parameters.// www  .  j a  v a  2  s  .  c o  m
 * 
 * @return Method
 * @param cls
 *            java.lang.Class
 * @param name
 *            String
 * @param paramTypes
 *            java.lang.Class[]
 */
//start extract getSupportedMethod
public static Method getSupportedMethod(Class cls, String name, Class[] paramTypes)
        throws NoSuchMethodException {
    if (cls == null) {
        throw new NoSuchMethodException();
    }
    try {
        return cls.getDeclaredMethod(name, paramTypes);
    } catch (NoSuchMethodException ex) {
        return getSupportedMethod(cls.getSuperclass(), name, paramTypes);
    }
}

From source file:com.github.dactiv.common.utils.ReflectionUtils.java

/**
 * ?Classcglib AOPCGLIBClass?Class// w w w .  j av  a 2  s  .  c o m
 * 
 * @param targetClass  class
 * 
 * @return Class
 */
public static Class<?> getTargetClass(Class<?> targetClass) {

    Assert.notNull(targetClass, "targetClass?");

    Class clazz = targetClass;
    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:org.opentides.util.CrudUtil.java

/**
 * Helper method to retrieve all methods of a class including
 * methods declared in its superclass.//from   w w w  .j a  v a  2s .com
 * @param clazz
 * @param includeParent
 * @return
 */
@SuppressWarnings({ "rawtypes" })
public static List<Method> getAllMethods(Class clazz, boolean includeParent) {
    List<Method> methods = new ArrayList<Method>();
    if (BaseEntity.class.isAssignableFrom(clazz) && includeParent)
        methods.addAll(getAllMethods(clazz.getSuperclass(), includeParent));
    for (Method method : clazz.getDeclaredMethods())
        methods.add(method);
    return methods;
}

From source file:adalid.core.XS1.java

static Class<?> getNamedClass(Class<?> clazz) {
    assert clazz != null;
    return clazz.isAnonymousClass() ? clazz.getSuperclass() : clazz;
}

From source file:IntrospectionUtil.java

public static Field findField(Class clazz, String targetName, Class targetType, boolean checkInheritance,
        boolean strictType) throws NoSuchFieldException {
    if (clazz == null)
        throw new NoSuchFieldException("No class");
    if (targetName == null)
        throw new NoSuchFieldException("No field name");

    try {/* www .j  av a 2s . co  m*/
        Field field = clazz.getDeclaredField(targetName);
        if (strictType) {
            if (field.getType().equals(targetType))
                return field;
        } else {
            if (field.getType().isAssignableFrom(targetType))
                return field;
        }
        if (checkInheritance) {
            return findInheritedField(clazz.getPackage(), clazz.getSuperclass(), targetName, targetType,
                    strictType);
        } else
            throw new NoSuchFieldException("No field with name " + targetName + " in class " + clazz.getName()
                    + " of type " + targetType);
    } catch (NoSuchFieldException e) {
        return findInheritedField(clazz.getPackage(), clazz.getSuperclass(), targetName, targetType,
                strictType);
    }
}

From source file:org.LexGrid.LexBIG.caCore.dao.orm.LexEVSDAOImpl.java

protected static void initializeAll(List<Object> list) {
    for (Object obj : list) {
        Class resultClass = obj.getClass();
        while (resultClass != null) {
            Field[] fields = resultClass.getDeclaredFields();
            for (int f = 0; f < fields.length; f++) {
                fields[f].setAccessible(true);
                try {
                    if (!Hibernate.isInitialized(fields[f].get(obj))) {
                        Hibernate.initialize(fields[f].get(obj));
                    }//  w w w.j a v a 2  s. co m
                } catch (Exception e) {
                    throw new HibernateException("Error fully initializing.", e);
                }
            }
            resultClass = resultClass.getSuperclass();
        }
    }
}

From source file:com.mawujun.utils.AnnotationUtils.java

/**
 * Find the first {@link Class} in the inheritance hierarchy of the specified
 * {@code clazz} (including the specified {@code clazz} itself) which declares
 * at least one of the specified {@code annotationTypes}, or {@code null} if
 * none of the specified annotation types could be found.
 * <p>If the supplied {@code clazz} is {@code null}, {@code null} will be
 * returned.//  w w w.  j a  v a2  s . c o m
 * <p>If the supplied {@code clazz} is an interface, only the interface itself
 * will be checked; the inheritance hierarchy for interfaces will not be traversed.
 * <p>The standard {@link Class} API does not provide a mechanism for determining
 * which class in an inheritance hierarchy actually declares one of several
 * candidate {@linkplain Annotation annotations}, so we need to handle this
 * explicitly.
 * @param annotationTypes the list of Class objects corresponding to the
 * annotation types
 * @param clazz the Class object corresponding to the class on which to check
 * for the annotations, or {@code null}
 * @return the first {@link Class} in the inheritance hierarchy of the specified
 * {@code clazz} which declares an annotation of at least one of the specified
 * {@code annotationTypes}, or {@code null} if not found
 * @see Class#isAnnotationPresent(Class)
 * @see Class#getDeclaredAnnotations()
 * @see #findAnnotationDeclaringClass(Class, Class)
 * @see #isAnnotationDeclaredLocally(Class, Class)
 * @since 3.2.2
 */
public static Class<?> findAnnotationDeclaringClassForTypes(List<Class<? extends Annotation>> annotationTypes,
        Class<?> clazz) {
    Assert.notEmpty(annotationTypes, "The list of annotation types must not be empty");
    if (clazz == null || clazz.equals(Object.class)) {
        return null;
    }

    for (Class<? extends Annotation> annotationType : annotationTypes) {
        if (isAnnotationDeclaredLocally(annotationType, clazz)) {
            return clazz;
        }
    }

    return findAnnotationDeclaringClassForTypes(annotationTypes, clazz.getSuperclass());
}

From source file:IntrospectionUtil.java

protected static Method findInheritedMethod(Package pack, Class clazz, String methodName, Class[] args,
        boolean strictArgs) throws NoSuchMethodException {
    if (clazz == null)
        throw new NoSuchMethodException("No class");
    if (methodName == null)
        throw new NoSuchMethodException("No method name");

    Method method = null;/*from  w w  w .jav  a  2 s . co m*/
    Method[] methods = clazz.getDeclaredMethods();
    for (int i = 0; i < methods.length && method == null; i++) {
        if (methods[i].getName().equals(methodName) && isInheritable(pack, methods[i])
                && checkParams(methods[i].getParameterTypes(), args, strictArgs))
            method = methods[i];
    }
    if (method != null) {
        return method;
    } else
        return findInheritedMethod(clazz.getPackage(), clazz.getSuperclass(), methodName, args, strictArgs);
}

From source file:adalid.core.XS1.java

static Class<?> getConcreteSuperclass(Class<?> c) {
    if (c == null) {
        return null;
    }/* w ww . j  av a 2  s  . c  om*/
    Class<?> s = c.getSuperclass();
    if (s == null) {
        return null;
    }
    if (c.isAnonymousClass()) {
        return getConcreteSuperclass(s);
    }
    int modifiers = s.getModifiers();
    if (Modifier.isAbstract(modifiers)) {
        return null;
    }
    if (s.getSimpleName().equals(c.getSimpleName())) {
        return getConcreteSuperclass(s);
    }
    return s;
}