Example usage for java.lang.reflect Field getModifiers

List of usage examples for java.lang.reflect Field getModifiers

Introduction

In this page you can find the example usage for java.lang.reflect Field getModifiers.

Prototype

public int getModifiers() 

Source Link

Document

Returns the Java language modifiers for the field represented by this Field object, as an integer.

Usage

From source file:org.acoveo.tools.Reflection.java

/**
 * Return the value of the given field in the given object.
 *///from   ww  w .  j  a va2  s  .c o  m
public static float getFloat(Object target, Field field) {
    if (target == null || field == null)
        return 0F;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getFloat(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

From source file:org.acoveo.tools.Reflection.java

/**
 * Return the value of the given field in the given object.
 *//*from  w w w .  j a v  a  2s .  co  m*/
public static long getLong(Object target, Field field) {
    if (target == null || field == null)
        return 0L;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getLong(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

From source file:org.acoveo.tools.Reflection.java

/**
 * Return the value of the given field in the given object.
 *//*from  ww  w . j  a v a2 s.c  o  m*/
public static Object get(Object target, Field field) {
    if (target == null || field == null)
        return null;
    makeAccessible(field, field.getModifiers());
    try {
        return field.get(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

From source file:org.acoveo.tools.Reflection.java

/**
 * Return the value of the given field in the given object.
 *///from  w  w w  . j a va 2s. c  o m
public static boolean getBoolean(Object target, Field field) {
    if (target == null || field == null)
        return false;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getBoolean(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

From source file:org.acoveo.tools.Reflection.java

/**
 * Return the value of the given field in the given object.
 *///from  w ww  .  j a  v a 2s . com
public static byte getByte(Object target, Field field) {
    if (target == null || field == null)
        return (byte) 0;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getByte(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

From source file:org.acoveo.tools.Reflection.java

/**
 * Return the value of the given field in the given object.
 *///  w ww .j a va  2s.  com
public static char getChar(Object target, Field field) {
    if (target == null || field == null)
        return (char) 0;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getChar(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

From source file:org.acoveo.tools.Reflection.java

/**
 * Return the value of the given field in the given object.
 *///  w  w  w. j  av a 2 s.  c o  m
public static short getShort(Object target, Field field) {
    if (target == null || field == null)
        return (short) 0;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getShort(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

From source file:com.hc.wx.server.common.bytecode.ReflectUtils.java

public static Map<String, Field> getBeanPropertyFields(Class cl) {
    Map<String, Field> properties = new HashMap<String, Field>();
    for (; cl != null; cl = cl.getSuperclass()) {
        Field[] fields = cl.getDeclaredFields();
        for (Field field : fields) {
            if (Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
                continue;
            }//from   w ww. j a  v  a2 s. c om

            field.setAccessible(true);

            properties.put(field.getName(), field);
        }
    }

    return properties;
}

From source file:com.link_intersystems.lang.reflect.SerializableField.java

int getModifier(Field field) {
    int currentModifiers = field.getModifiers();
    return currentModifiers;
}

From source file:me.prokopyl.storagemonitor.beans.JavaBean.java

@Override
public String toJSONString() {
    JSONObject obj = new JSONObject();
    obj.put("BeanType", this.getBeanName());
    Field[] fields = this.getClass().getDeclaredFields();

    for (Field field : fields) {
        if (Modifier.isTransient(field.getModifiers()))
            continue;
        field.setAccessible(true);/*from   w w w.  ja v  a 2  s  .  c o  m*/
        try {
            obj.put(field.getName(), field.get(this));
        } catch (IllegalAccessException ex) {
        }
    }

    return obj.toJSONString();
}