Package nl.pim16aap2.util.reflection
Class FieldFinder.NamedFieldFinder<T>
java.lang.Object
nl.pim16aap2.util.reflection.ReflectionFinder<Field,FieldFinder.NamedFieldFinder<T>>
nl.pim16aap2.util.reflection.FieldFinder.NamedFieldFinder<T>
- All Implemented Interfaces:
IAccessibleSetter<FieldFinder.NamedFieldFinder<T>>,IAnnotationFinder<FieldFinder.NamedFieldFinder<T>>
- Enclosing class:
FieldFinder
public static final class FieldFinder.NamedFieldFinder<T>
extends ReflectionFinder<Field,FieldFinder.NamedFieldFinder<T>>
Represents an implementation of
ReflectionFinder to retrieve a field by its name.-
Nested Class Summary
Nested classes/interfaces inherited from class nl.pim16aap2.util.reflection.ReflectionFinder
ReflectionFinder.ReflectionFinderWithParameters<T,U extends ReflectionFinder.ReflectionFinderWithParameters<T, U>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Class<? extends Annotation>[]protected booleanprotected booleanFields inherited from class nl.pim16aap2.util.reflection.ReflectionFinder
modifiers -
Method Summary
Modifier and TypeMethodDescriptionUsed to configure the field finder to include the source class's superclasses when searching for the target field.get()Retrieves the target reflection object(s) using the current configuration.Retrieves the object of the field from the given instance.protected TRetrieves the object of the field from the given instance.@Nullable FieldRetrieves the target reflection object(s) using the current configuration.getNullable(@Nullable Object instance) Retrieves the object of the field from the given instance.Gets the configured type of the target field.<U> FieldFinder.NamedFieldFinder<U> Specifies the type the field should have.voidSets the value of the field in the given instance.Sets the returned reflection object(s) as accessible.final FieldFinder.NamedFieldFinder<T> withAnnotations(Class<? extends Annotation>... annotations) Adds a requirement that the target constructor should contain at least a set of given annotations.Methods inherited from class nl.pim16aap2.util.reflection.ReflectionFinder
addModifiers, withModifiers
-
Field Details
-
setAccessible
protected boolean setAccessible -
checkSuperClasses
protected boolean checkSuperClasses -
annotations
-
-
Method Details
-
get
Description copied from class:ReflectionFinderRetrieves the target reflection object(s) using the current configuration.This may throw an exception if the lookup hasn't been configured yet.
- Specified by:
getin classReflectionFinder<Field,FieldFinder.NamedFieldFinder<T>> - Returns:
- The target reflection object(s) being searched for.
-
getNullable
Description copied from class:ReflectionFinderRetrieves the target reflection object(s) using the current configuration.This may throw an exception if the lookup hasn't been configured yet.
- Specified by:
getNullablein classReflectionFinder<Field,FieldFinder.NamedFieldFinder<T>> - Returns:
- The target reflection object(s) being searched for or null if no object(s) could be found.
-
ofType
@CheckReturnValue @Contract(pure=true) public <U> FieldFinder.NamedFieldFinder<U> ofType(Class<U> fieldType) Specifies the type the field should have.If this is set to null (default), the type of the field will be ignored.
- Parameters:
fieldType- The type the field should have.- Returns:
- The new instance of the current finder.
-
getTargetFieldType
Gets the configured type of the target field.This is used to cast the field to the correct type when retrieving it.
- Returns:
- The type of the target field.
-
get
Retrieves the object of the field from the given instance.- Parameters:
field- The field to retrieve the object from.instance- The instance to retrieve the field from.This can be null if the field is static.
- Returns:
- The object of the field from the given instance.
-
get
Retrieves the object of the field from the given instance.The field will be retrieved using
ReflectionFinder.get()first.- Parameters:
instance- The instance to retrieve the field from.This can be null if the field is static.
- Returns:
- The object of the field from the given instance.
- Throws:
NullPointerException- If the field could not be found, if the instance was null and the field was not static, or if the object of the field was null.ClassCastException- If the field could be found, but could not be cast to the correct type.IllegalArgumentException- If the field could be found, but could not be accessed or
-
getNullable
Retrieves the object of the field from the given instance.The field will be retrieved using
getNullable(Object)first. If the field could not be found, this method will return null.- Parameters:
instance- The instance to retrieve the field from.This can be null if the field is static.
- Returns:
- The object of the field from the given instance.
- Throws:
NullPointerException- If the field could not be found or if the instance was null and the field was not static.ClassCastException- If the field could be found, but could not be cast to the correct type.IllegalArgumentException- If the field could be found, but could not be accessed or
-
set
Sets the value of the field in the given instance.The field will be retrieved using
ReflectionFinder.get()first.- Parameters:
instance- The instance to set the field in.value- The value to set the field to.- Throws:
NullPointerException- If the field could not be found or if the instance was null and the field was not static.IllegalArgumentException- If the field could not be accessed, or if the field could not be set to the given value.
-
setAccessible
Description copied from interface:IAccessibleSetterSets the returned reflection object(s) as accessible.- Specified by:
setAccessiblein interfaceIAccessibleSetter<T>- Returns:
- The current object.
-
withAnnotations
@SafeVarargs public final FieldFinder.NamedFieldFinder<T> withAnnotations(Class<? extends Annotation>... annotations) Description copied from interface:IAnnotationFinderAdds a requirement that the target constructor should contain at least a set of given annotations.- Specified by:
withAnnotationsin interfaceIAnnotationFinder<T>- Parameters:
annotations- The annotations the constructor should have.- Returns:
- The current object.
-
checkSuperClasses
Used to configure the field finder to include the source class's superclasses when searching for the target field.- Returns:
- The current field finder instance.
-