Class FieldAccessor
- java.lang.Object
-
- nl.jqno.equalsverifier.internal.reflection.FieldAccessor
-
public class FieldAccessor extends java.lang.Object
Provides reflective access to one field of an object.
-
-
Constructor Summary
Constructors Constructor Description FieldAccessor(java.lang.Object object, java.lang.reflect.Field field)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canBeModifiedReflectively()
Determines whether the field can be modified using reflection.void
changeField(PrefabValues prefabValues, TypeTag enclosingType)
Changes the field's value to something else.void
copyTo(java.lang.Object to)
Copies field's value to the corresponding field in the specified object.void
defaultField()
Tries to make the field null.void
defaultStaticField()
Tries to make the field null.boolean
fieldIsEmptyOrSingleValueEnum()
boolean
fieldIsFinal()
boolean
fieldIsPrimitive()
boolean
fieldIsStatic()
boolean
fieldIsTransient()
java.lang.Object
get()
Tries to get the field's value.java.lang.reflect.Field
getField()
java.lang.String
getFieldName()
java.lang.Class<?>
getFieldType()
java.lang.Object
getObject()
void
set(java.lang.Object value)
Tries to set the field to the specified value.
-
-
-
Method Detail
-
getObject
public java.lang.Object getObject()
- Returns:
- The object that contains the field.
-
getField
public java.lang.reflect.Field getField()
- Returns:
- The field itself.
-
getFieldType
public java.lang.Class<?> getFieldType()
- Returns:
- The field's type.
-
getFieldName
public java.lang.String getFieldName()
- Returns:
- The field's name.
-
fieldIsPrimitive
public boolean fieldIsPrimitive()
- Returns:
- Whether the field is of a primitive type.
-
fieldIsFinal
public boolean fieldIsFinal()
- Returns:
- Whether the field is marked with the final modifier.
-
fieldIsStatic
public boolean fieldIsStatic()
- Returns:
- Whether the field is marked with the static modifier.
-
fieldIsTransient
public boolean fieldIsTransient()
- Returns:
- Whether the field is marked with the transient modifier.
-
fieldIsEmptyOrSingleValueEnum
public boolean fieldIsEmptyOrSingleValueEnum()
- Returns:
- Whether the field is an enum with a single value.
-
get
public java.lang.Object get()
Tries to get the field's value.- Returns:
- The field's value.
- Throws:
ReflectionException
- If the operation fails.
-
set
public void set(java.lang.Object value)
Tries to set the field to the specified value. Includes static fields but ignores fields that can't be modified reflectively.- Parameters:
value
- The value that the field should get.- Throws:
ReflectionException
- If the operation fails.
-
defaultField
public void defaultField()
Tries to make the field null. Ignores static fields and fields that can't be modified reflectively.- Throws:
ReflectionException
- If the operation fails.
-
defaultStaticField
public void defaultStaticField()
Tries to make the field null. Includes static fields but ignores fields that can't be modified reflectively.- Throws:
ReflectionException
- If the operation fails.
-
copyTo
public void copyTo(java.lang.Object to)
Copies field's value to the corresponding field in the specified object. Ignores static fields and fields that can't be modified reflectively.- Parameters:
to
- The object into which to copy the field.- Throws:
ReflectionException
- If the operation fails.
-
changeField
public void changeField(PrefabValues prefabValues, TypeTag enclosingType)
Changes the field's value to something else. The new value will never be null. Other than that, the precise value is undefined. Ignores static fields and fields that can't be modified reflectively.- Parameters:
prefabValues
- If the field is of a type contained within prefabValues, the new value will be taken from it.enclosingType
- A tag for the type that contains the field. Needed to determine a generic type, if it has one..- Throws:
ReflectionException
- If the operation fails.
-
canBeModifiedReflectively
public boolean canBeModifiedReflectively()
Determines whether the field can be modified using reflection.- Returns:
- Whether or not the field can be modified reflectively.
-
-