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.yiji.openapi.sdk.util.Reflections.java

public static Set<String> getFieldNames(Class<?> pojoClass) {
    Set<String> propertyNames = new HashSet<String>();
    Class<?> clazz = pojoClass;
    do {/*from  www  . j av  a  2 s  . c o  m*/
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (!Modifier.isStatic(field.getModifiers())) {
                propertyNames.add(field.getName());

            }
        }
        clazz = clazz.getSuperclass();
    } while (clazz != null && !clazz.getSimpleName().equalsIgnoreCase("Object"));
    return propertyNames;
}

From source file:com.github.gekoh.yagen.ddl.comment.CommentsDDLGenerator.java

public static void setOnlyProcessEntityClasses(Set<Class> entityClasses) {
    ENTITY_CLASS_NAMES_ONLY = new HashSet<String>();
    for (Class entityClass : entityClasses) {
        ENTITY_CLASS_NAMES_ONLY.add(entityClass.getName());

        Class superClass = entityClass;
        while ((superClass = superClass.getSuperclass()) != null) {
            ENTITY_CLASS_NAMES_ONLY.add(superClass.getName());
        }//from  w  w w.ja  va2 s  .  c  o m
    }
}

From source file:com.opengamma.web.analytics.blotter.BlotterResource.java

static boolean isSecurity(Class<?> type) {
    if (type == null) {
        return false;
    } else if (ManageableSecurity.class.equals(type)) {
        return true;
    } else {/*www  .jav a 2 s .  co  m*/
        return isSecurity(type.getSuperclass());
    }
}

From source file:com.amalto.core.metadata.ClassRepository.java

private static Method[] getMethods(Class clazz) {
    // TMDM-5851: Work around several issues in introspection (getDeclaredMethods() and getMethods() may return
    // inherited methods if returned type is a sub class of super class method).
    Map<String, Class<?>> superClassMethods = new HashMap<String, Class<?>>();
    if (clazz.getSuperclass() != null) {
        for (Method method : clazz.getSuperclass().getMethods()) {
            superClassMethods.put(method.getName(), method.getReturnType());
        }/*  w  w w .j  av a  2  s  .  c  o  m*/
    }
    Map<String, Method> methods = new HashMap<String, Method>();
    for (Method method : clazz.getDeclaredMethods()) {
        if (!(superClassMethods.containsKey(method.getName())
                && superClassMethods.get(method.getName()).equals(method.getReturnType()))) {
            methods.put(method.getName(), method);
        }
    }
    Method[] allMethods = clazz.getMethods();
    for (Method method : allMethods) {
        if (!methods.containsKey(method.getName())) {
            methods.put(method.getName(), method);
        }
    }
    Method[] classMethods = methods.values().toArray(new Method[methods.size()]);
    // TMDM-5483: getMethods() does not always return methods in same order: sort them to ensure fixed order.
    Arrays.sort(classMethods, new Comparator<Method>() {
        @Override
        public int compare(Method method1, Method method2) {
            return method1.getName().compareTo(method2.getName());
        }
    });
    return classMethods;
}

From source file:ml.shifu.shifu.util.ClassUtils.java

@SuppressWarnings("unchecked")
public static List<Method> getAllMethods(Class<?> clazz) {
    if (clazz == null) {
        return Collections.EMPTY_LIST;
    }//from w ww. j  ava2s.co  m

    if (clazz.equals(Object.class)) {
        return Collections.EMPTY_LIST;
    }

    List<Method> result = new ArrayList<Method>();
    for (Method method : clazz.getDeclaredMethods()) {
        result.add(method);
    }
    Class<?> tmpClazz = clazz.getSuperclass();
    while (!Object.class.equals(tmpClazz)) {
        result.addAll(getAllMethods(tmpClazz));
        tmpClazz = tmpClazz.getSuperclass();
    }

    return result;
}

From source file:com.expressui.core.util.ReflectionUtil.java

/**
 * Finds field on a given type.// w  w  w. j a  v a  2 s  .  co m
 *
 * @param type      class containing the field
 * @param fieldName name of field to search for
 * @return found field
 */
public static Field getField(Class type, String fieldName) {
    Field field = null;
    Class currentType = type;
    while (field == null && !currentType.equals(Object.class)) {
        try {
            field = currentType.getDeclaredField(fieldName);
        } catch (SecurityException e) {
            throw new RuntimeException(e);
        } catch (NoSuchFieldException e) {
            currentType = currentType.getSuperclass();
        }
    }

    return field;
}

From source file:com.feilong.commons.core.lang.reflect.TypeUtil.java

/**
 *  superclass parameterized type.//from   w w w .j av  a  2 s . c  om
 *
 * @param klass
 *            the klass
 * @return the superclass parameterized type
 * @throws NullPointerException
 *             the null pointer exception
 * @see java.lang.Class#getGenericSuperclass()
 */
private static ParameterizedType getGenericSuperclassParameterizedType(Class<?> klass)
        throws NullPointerException {

    if (Validator.isNullOrEmpty(klass)) {
        throw new NullPointerException("klass can't be null/empty!");
    }

    Type type = klass.getGenericSuperclass(); //com.feilong.commons.core.lang.reflect.res.BaseSolrRepositoryImpl<com.feilong.commons.core.lang.reflect.res.SkuItem, java.lang.Long>

    while (!(type instanceof ParameterizedType) && Object.class != klass) {
        klass = klass.getSuperclass();
        type = klass.getGenericSuperclass();
    }

    return (ParameterizedType) type;
}

From source file:com.autobizlogic.abl.util.BeanUtil.java

private static Field getFieldFromClassWithInheritance(Class<?> cls, String fieldName, Class<?> argClass) {
    Field field = getFieldFromClass(cls, fieldName, argClass, false);
    while (field == null && (!cls.getName().equals("java.lang.Object"))) {
        cls = cls.getSuperclass();
        field = getFieldFromClass(cls, fieldName, argClass, true);
    }//from   w w  w.j a  va 2s  .c  o m
    return field;
}

From source file:com.datumbox.common.persistentstorage.factories.MongoDBStructureFactory.java

public static List<Field> getAllFields(List<Field> fields, Class<?> type) {
    fields.addAll(Arrays.asList(type.getDeclaredFields()));

    if (type.getSuperclass() != null) {
        fields = getAllFields(fields, type.getSuperclass());
    }//from  ww  w  .  j  a va 2 s.  c  om

    return fields;
}

From source file:com.medsphere.fileman.FMRecord.java

static private void accumulateJavaDomainFields(Map<String, AnnotatedElement> domainFields,
        Class<? extends FMRecord> domainClass) {
    if (domainClass != null && domainClass.getSuperclass() != null) {
        Class<? extends FMRecord> superClass = (Class<? extends FMRecord>) domainClass.getSuperclass();
        accumulateJavaDomainFields(domainFields, superClass);
    }/*from w w  w .j  a  v a  2s  .c o  m*/
    for (AnnotatedElement e : domainClass.getDeclaredFields()) {
        FMAnnotateFieldInfo annote = e.getAnnotation(FMAnnotateFieldInfo.class);
        if (annote != null) {
            domainFields.put(annote.number(), e);
        }
    }
    for (AnnotatedElement e : domainClass.getDeclaredMethods()) {
        FMAnnotateFieldInfo annote = e.getAnnotation(FMAnnotateFieldInfo.class);
        if (annote != null) {
            domainFields.put(annote.number(), e);
        }
    }

}