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

/**
 * Set the value of the given field in the given object.
 *///from   w ww . j  a v a2s  .com
public static void set(Object target, Field field, int value) {
    if (target == null || field == null)
        return;
    makeAccessible(field, field.getModifiers());
    try {
        field.setInt(target, value);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

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

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

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

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

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

/**
 * Set the value of the given field in the given object.
 */// w  w w  .  ja  va 2s . c o m
public static void set(Object target, Field field, long value) {
    if (target == null || field == null)
        return;
    makeAccessible(field, field.getModifiers());
    try {
        field.setLong(target, value);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

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

/**
 * Set the value of the given field in the given object.
 *///w w w  . ja v  a2  s  .  c  o  m
public static void set(Object target, Field field, float value) {
    if (target == null || field == null)
        return;
    makeAccessible(field, field.getModifiers());
    try {
        field.setFloat(target, value);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

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

/**
 * Set the value of the given field in the given object.
 *//*from w w w. j  ava 2  s .  c o m*/
public static void set(Object target, Field field, short value) {
    if (target == null || field == null)
        return;
    makeAccessible(field, field.getModifiers());
    try {
        field.setShort(target, value);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

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

/**
 * Set the value of the given field in the given object.
 *///from w w  w. jav a2  s  .c  om
public static void set(Object target, Field field, Object value) {
    if (target == null || field == null)
        return;
    makeAccessible(field, field.getModifiers());
    try {
        field.set(target, value);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

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

/**
 * Set the value of the given field in the given object.
 *//* w w  w.j a va 2  s  .co m*/
public static void set(Object target, Field field, double value) {
    if (target == null || field == null)
        return;
    makeAccessible(field, field.getModifiers());
    try {
        field.setDouble(target, value);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}

From source file:adalid.core.XS1.java

static boolean checkFieldAnnotation(boolean log, Field field, Class<? extends Annotation> annotation,
        Class<?>[] validTypes) {
    String name = field.getName();
    Class<?> type = field.getDeclaringClass();
    String string;/*ww  w  .ja va 2  s .  c o  m*/
    int modifiers = field.getModifiers();
    if (Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers)) {
        string = "field " + name + " has static and/or final modifier";
        if (log) {
            logFieldAnnotationErrorMessage(name, type, annotation, string);
        }
        return false;
    }
    int length = validTypes == null ? 0 : validTypes.length;
    if (length < 1) {
        return true;
    }
    Class<?> ft = getTrueType(field.getType());
    String[] strings = new String[length];
    int i = 0;
    for (Class<?> vt : validTypes) {
        if (vt.isAssignableFrom(ft)) {
            return true;
        }
        strings[i++] = vt.getSimpleName();
    }
    string = "type of " + name + " is not " + StringUtils.join(strings, " or ");
    if (log) {
        logFieldAnnotationErrorMessage(name, type, annotation, string);
    }
    return false;
}

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

/**
 * Set the value of the given field in the given object.
 *///from w  w  w.j  a  v a2  s .co m
public static void set(Object target, Field field, boolean value) {
    if (target == null || field == null)
        return;
    makeAccessible(field, field.getModifiers());
    try {
        field.setBoolean(target, value);
    } catch (Throwable t) {
        throw wrapReflectionException(t);
    }
}