Package com.google.api.client.util
Class FieldInfo
- java.lang.Object
-
- com.google.api.client.util.FieldInfo
-
public class FieldInfo extends java.lang.Object
Parses field information to determine data key name/value pair associated with the field.Implementation is thread-safe.
- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.reflect.Field,FieldInfo>
CACHE
Cached field information.private java.lang.reflect.Field
field
Field.private boolean
isPrimitive
Whether the field class is "primitive" as defined byData.isPrimitive(Type)
.private java.lang.String
name
private java.lang.reflect.Method[]
setters
-
Constructor Summary
Constructors Constructor Description FieldInfo(java.lang.reflect.Field field, java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends java.lang.Enum<T>>
TenumValue()
ClassInfo
getClassInfo()
Returns the class information of the field's declaring class.java.lang.reflect.Field
getField()
Returns the field.static java.lang.Object
getFieldValue(java.lang.reflect.Field field, java.lang.Object obj)
Returns the value of the given field in the given object using reflection.java.lang.reflect.Type
getGenericType()
Returns the field's generic type, which is a class, parameterized type, generic array type, or type variable, but not a wildcard type.java.lang.String
getName()
java.lang.Class<?>
getType()
Returns the field's type.java.lang.Object
getValue(java.lang.Object obj)
Returns the value of the field in the given object instance using reflection.boolean
isFinal()
Returns whether the field is final.boolean
isPrimitive()
Returns whether the field is primitive as defined byData.isPrimitive(Type)
.static FieldInfo
of(java.lang.Enum<?> enumValue)
Returns the field information for the given enum value.static FieldInfo
of(java.lang.reflect.Field field)
Returns the field information for the given field.static void
setFieldValue(java.lang.reflect.Field field, java.lang.Object obj, java.lang.Object value)
Sets the given field in the given object to the given value using reflection.private java.lang.reflect.Method[]
settersMethodForField(java.lang.reflect.Field field)
Creates list of setter methods for a field only in declaring class.void
setValue(java.lang.Object obj, java.lang.Object value)
Sets this field in the given object to the given value using reflection.
-
-
-
Field Detail
-
CACHE
private static final java.util.Map<java.lang.reflect.Field,FieldInfo> CACHE
Cached field information.
-
isPrimitive
private final boolean isPrimitive
Whether the field class is "primitive" as defined byData.isPrimitive(Type)
.
-
field
private final java.lang.reflect.Field field
Field.
-
setters
private final java.lang.reflect.Method[] setters
-
name
private final java.lang.String name
-
-
Method Detail
-
of
public static FieldInfo of(java.lang.Enum<?> enumValue)
Returns the field information for the given enum value.- Parameters:
enumValue
- enum value- Returns:
- field information
- Throws:
java.lang.IllegalArgumentException
- if the enum value has no value annotation- Since:
- 1.4
-
of
public static FieldInfo of(java.lang.reflect.Field field)
Returns the field information for the given field.- Parameters:
field
- field ornull
fornull
result- Returns:
- field information or
null
if the field has noname
or fornull
input
-
settersMethodForField
private java.lang.reflect.Method[] settersMethodForField(java.lang.reflect.Field field)
Creates list of setter methods for a field only in declaring class.
-
getField
public java.lang.reflect.Field getField()
Returns the field.- Since:
- 1.4
-
getName
public java.lang.String getName()
Returns the data key name associated with the field for a non-enum-constant with aKey
annotation, or data key value associated with the enum constant with aValue
annotation ornull
for an enum constant with aNullValue
annotation.This string is interned.
- Since:
- 1.4
-
getType
public java.lang.Class<?> getType()
Returns the field's type.- Since:
- 1.4
-
getGenericType
public java.lang.reflect.Type getGenericType()
Returns the field's generic type, which is a class, parameterized type, generic array type, or type variable, but not a wildcard type.- Since:
- 1.4
-
isFinal
public boolean isFinal()
Returns whether the field is final.- Since:
- 1.4
-
isPrimitive
public boolean isPrimitive()
Returns whether the field is primitive as defined byData.isPrimitive(Type)
.- Since:
- 1.4
-
getValue
public java.lang.Object getValue(java.lang.Object obj)
Returns the value of the field in the given object instance using reflection.
-
setValue
public void setValue(java.lang.Object obj, java.lang.Object value)
Sets this field in the given object to the given value using reflection.If the field is final, it checks that the value being set is identical to the existing value.
-
getClassInfo
public ClassInfo getClassInfo()
Returns the class information of the field's declaring class.
-
enumValue
public <T extends java.lang.Enum<T>> T enumValue()
-
getFieldValue
public static java.lang.Object getFieldValue(java.lang.reflect.Field field, java.lang.Object obj)
Returns the value of the given field in the given object using reflection.
-
setFieldValue
public static void setFieldValue(java.lang.reflect.Field field, java.lang.Object obj, java.lang.Object value)
Sets the given field in the given object to the given value using reflection.If the field is final, it checks that the value being set is identical to the existing value.
-
-