Example usage for java.lang.reflect Member getClass

List of usage examples for java.lang.reflect Member getClass

Introduction

In this page you can find the example usage for java.lang.reflect Member getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.eclecticlogic.pedal.dm.internal.MetamodelUtil.java

/**
 * @param attribute JPA metamodel attribute.
 * @param entity Entity to set the value on.
 * @param value Value to set./*  w  ww  . j  ava2  s.c om*/
 */
public static <E extends Serializable, T extends Serializable> void set(Attribute<? super E, T> attribute,
        E entity, T value) {
    Member member = attribute.getJavaMember();
    if (member instanceof Field) {
        Field field = (Field) member;
        field.setAccessible(true);
        try {
            field.set(entity, value);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (member instanceof Method) {
        PropertyDescriptor pd = BeanUtils.findPropertyForMethod((Method) member);
        if (pd.getWriteMethod() != null) {
            pd.getWriteMethod().setAccessible(true);
            try {
                pd.getWriteMethod().invoke(entity, value);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            throw new RuntimeException(
                    "No setter for " + attribute.getName() + " in " + entity.getClass().getName());
        }
    } else {
        throw new RuntimeException("Failed to set " + attribute.getName() + " of type "
                + member.getClass().getName() + " in entity " + entity.getClass().getName());
    }
}

From source file:com.github.juanmf.java2plant.render.PlantRenderer.java

private void addMembers(Member[] declaredMembers, List<String> plantMembers) {
    for (Member m : declaredMembers) {
        memberPrinters.get(m.getClass()).addMember(m, plantMembers);
    }/* w  w  w . java  2  s  . c  o m*/
}

From source file:nu.staldal.lsp.wrapper.ReadonlyBeanMap.java

public Object get(Object key) {
    Member member = getMember((String) key);
    if (member == null) {
        return null;
    }/* ww  w  . j  a  va2s  .  c  o  m*/

    try {
        if (member instanceof Method) {
            return ((Method) member).invoke(bean);
        } else if (member instanceof Field) {
            return ((Field) member).get(bean);
        } else {
            throw new Error("Unknown Member: " + member.getClass().getName());
        }
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        Throwable ee = e.getCause();
        if (ee instanceof RuntimeException) {
            throw (RuntimeException) ee;
        } else {
            throw new RuntimeException(ee);
        }
    }
}

From source file:org.assertj.assertions.generator.description.converter.ClassToClassDescriptionConverter.java

private static Class<?> getTypeOf(Member member) {
    if (member instanceof Method)
        return ((Method) member).getReturnType();
    if (member instanceof Field)
        return ((Field) member).getType();
    throw new IllegalArgumentException("argument should be a Method or Field but was " + member.getClass());
}

From source file:org.assertj.assertions.generator.description.converter.ClassToClassDescriptionConverter.java

private static ParameterizedType getParameterizedTypeOf(Member member) {
    if (member instanceof Method)
        return (ParameterizedType) ((Method) member).getGenericReturnType();
    if (member instanceof Field)
        return (ParameterizedType) ((Field) member).getGenericType();
    throw new IllegalArgumentException("argument should be a Method or Field but was " + member.getClass());
}