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.cassius.spring.assembly.test.common.toolbox.ContextUtil.java

/**
 * Get spring context locations./*from  w w  w  .  j  a va 2 s. co  m*/
 *
 * @param testClass the test class
 * @return the string [ ]
 */
public static Set<String> getSpringContextLocations(Class<?> testClass) {
    Set<String> files = new HashSet<String>();
    while (testClass != null) {
        SpringContextConfigure configure = testClass.getAnnotation(SpringContextConfigure.class);
        if (configure != null) {
            files.addAll(Arrays.asList(configure.value()));
        }
        testClass = testClass.getSuperclass();
    }
    return files;
}

From source file:app.commons.ReflectionUtils.java

public static Field[] getAllDeclaredFields(Class clazz) {
    Class currentClass = clazz;
    List<Field> fields = new ArrayList<Field>();
    while (currentClass != null) {
        fields.addAll(Arrays.asList(currentClass.getDeclaredFields()));
        currentClass = currentClass.getSuperclass();
    }/*  w  w  w  .  j  av a2 s .co m*/
    return fields.toArray(new Field[fields.size()]);
}

From source file:com.tridion.storage.si4t.JPASearchDAOFactory.java

private static Field getPrivateFieldRec(final Class<?> clazz, final String fieldName, Logger log) {
    for (Field field : clazz.getDeclaredFields()) {
        if (fieldName.equals(field.getName())) {
            return field;
        }// ww  w  . ja v a 2  s .  c  o  m
    }
    final Class<?> superClazz = clazz.getSuperclass();

    if (superClazz != null) {
        return getPrivateFieldRec(superClazz, fieldName, log);
    }

    return null;
}

From source file:com.cassius.spring.assembly.test.common.reflect.FieldWriter.java

/**
 * New instance.//from  w  w  w .  jav a 2s  .  c o m
 *
 * @param object the object
 * @param fieldName the field name
 * @param value the value
 * @return the field writer
 * @throws NoSuchFieldException the no such field exception
 */
public static FieldWriter newInstance(Object object, String fieldName, Object value)
        throws NoSuchFieldException {
    Class<?> clazz = object.getClass();
    while (clazz != Object.class) {
        try {
            Field field = clazz.getDeclaredField(fieldName);
            if (field != null) {
                return new FieldWriter(object, field, value);
            }
        } catch (NoSuchFieldException ignore) {
        }
        clazz = clazz.getSuperclass();
    }
    throw new NoSuchFieldException(fieldName + "not exist");
}

From source file:com.qrmedia.commons.persistence.hibernate.clone.HibernateEntityBeanCloner.java

private static Class<?> getEntityClass(Object entity) {
    Class<?> entityClass = entity.getClass();

    // walk up the superclass try until a non-CGLIB class is found (will stop at Object!)
    while (entityClass.getName().contains(CGLIB_CLASS_NAME_IDENTIFIER)) {
        entityClass = entityClass.getSuperclass();
    }/*  w w w.j av a  2  s  .co m*/

    return entityClass;
}

From source file:com.aw.support.reflection.MethodInvoker.java

public static List getAllAttributes(Object target) {
    logger.info("searching attributes " + target.getClass().getName());
    List attributes = new ArrayList();
    Class cls = target.getClass();
    Field[] fields = cls.getDeclaredFields();
    Field[] superFields = cls.getSuperclass().getDeclaredFields();
    attributes.addAll(procesarFields("", fields));
    attributes.addAll(procesarFields("", superFields));

    // analizamos si tiene domain..
    BeanWrapper beanWrapper = new BeanWrapperImpl(target);
    try {//from   w w w  .j  a va  2 s  .  c  o  m
        Class claz = beanWrapper.getPropertyType("domain");
        if (claz != null) {
            Field[] fieldsDomain = claz.getDeclaredFields();
            Field[] superFieldsDomain = claz.getSuperclass().getDeclaredFields();
            attributes.addAll(procesarFields("domain.", fieldsDomain));
            attributes.addAll(procesarFields("domain.", superFieldsDomain));
        }
    } catch (Exception e) {
        logger.error("No tiene attributo domain");
    }
    return attributes;
}

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

public static Iterable<Field> getFieldsUpTo(Class<?> type, Class<?> exclusiveParent) {
    List<Field> currentClassFields = new ArrayList<>();
    currentClassFields.addAll(Arrays.asList(type.getDeclaredFields()));

    Class<?> parentClass = type.getSuperclass();
    if (parentClass != null && (exclusiveParent == null || !parentClass.equals(exclusiveParent))) {
        List<Field> parentClassFields = (List<Field>) getFieldsUpTo(parentClass, exclusiveParent);
        currentClassFields.addAll(parentClassFields);
    }//from  ww w . j  a  v a 2s. c om

    return currentClassFields;
}

From source file:com.manydesigns.portofino.pageactions.PageActionLogic.java

public static Class<?> getConfigurationClass(Class<?> actionClass) {
    if (!PageAction.class.isAssignableFrom(actionClass)) {
        return null;
    }/*from  www.j a  v a  2 s.co  m*/
    ConfigurationClass configurationClass = actionClass.getAnnotation(ConfigurationClass.class);
    if (configurationClass != null) {
        return configurationClass.value();
    } else {
        return getConfigurationClass(actionClass.getSuperclass());
    }
}

From source file:com.infinira.aerospike.dataaccess.util.Utils.java

@SuppressWarnings("unchecked")
public static <V> V get(Object object, String fieldName) {
    Assert.notNull(object, "Object cannot be null.");
    Assert.notNull(fieldName, "Fieldname cannot be null.");
    Class<?> clazz = object.getClass();
    while (clazz != null) {
        try {//from   ww  w. ja v  a 2 s. c om
            Field field = clazz.getDeclaredField(fieldName);
            field.setAccessible(true);
            return (V) field.get(object);
        } catch (NoSuchFieldException e) {
            clazz = clazz.getSuperclass();
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    return null;
}

From source file:au.com.dw.testdatacapturej.reflection.util.ReflectionUtil.java

/**
 * Check if a class has a setter method with parameter signature for the superclass for a field.
 *
 * @param clazz/*from   w w  w  . j a v  a  2s .  co m*/
 * @param methodName
 * @param subclass
 * @return
 */
private static boolean hasSetterMethodForSuperClass(Class<?> clazz, String methodName, Class<?> subclass) {
    boolean hasSetterMethodForSuperClass = false;

    Class<?> superclass = subclass.getSuperclass();
    while (superclass != null) {
        hasSetterMethodForSuperClass = hasSetterMethodForParameterClass(clazz, methodName, superclass);
        if (hasSetterMethodForSuperClass)
            break;

        // handle next superclass in chain or super interfaces
        if (superclass.isInterface()) {
            hasSetterMethodForSuperClass = hasSetterMethodForInterfaces(clazz, methodName, superclass);

            // need to break out of the loop
            superclass = null;
        } else {
            // handle interfaces for superclass
            hasSetterMethodForSuperClass = hasSetterMethodForInterfaces(clazz, methodName, superclass);
            if (!hasSetterMethodForSuperClass) {
                subclass = superclass;
                superclass = subclass.getSuperclass();
            } else {
                superclass = null;
            }
        }
    }
    return hasSetterMethodForSuperClass;
}