protected static class BeanPathAdapter.FieldHandle<T,F>
extends java.lang.Object
Field handle to getAccessor()
and
getSetter()
for a given
getTarget()
.
Modifier | Constructor and Description |
---|---|
protected |
FieldHandle(T target,
java.lang.String fieldName,
java.lang.Class<F> declaredFieldType)
Constructor
|
Modifier and Type | Method and Description |
---|---|
protected static java.lang.invoke.MethodHandle |
buildAccessor(java.lang.Object target,
java.lang.String fieldName,
java.lang.String... fieldNamePrefix)
Attempts to build a
MethodHandle accessor for the field name
using common prefixes used for methods to access a field |
protected static java.lang.invoke.MethodHandle |
buildAccessorWithLikelyPrefixes(java.lang.Object target,
java.lang.String fieldName)
Attempts to build a
MethodHandle accessor for the field name
using common prefixes used for methods to access a field |
protected static java.lang.String |
buildMethodName(java.lang.String prefix,
java.lang.String fieldName)
Builds a method name using a prefix and a field name
|
protected static java.lang.invoke.MethodHandle |
buildSetter(java.lang.invoke.MethodHandle accessor,
java.lang.Object target,
java.lang.String fieldName)
Builds a setter
MethodHandle |
F |
defaultValue()
Gets a default value for the
getDeclaredFieldType() |
static <VT> VT |
defaultValue(java.lang.Class<VT> clazz)
Gets a default value for the specified class
|
protected F |
deriveValueFromAccessor(boolean isNullable)
Gets an accessor’s return target value obtained by calling the
accessor’s
MethodHandle#invoke(Object…) method. |
protected java.lang.invoke.MethodHandle |
getAccessor() |
static java.lang.Class<?> |
getAccessorType(java.lang.Object target,
java.lang.String fieldName)
Gets the
buildAccessorWithLikelyPrefixes(Object, String)
MethodHandle.type() |
java.lang.Class<F> |
getDeclaredFieldType() |
java.lang.String |
getFieldName() |
java.lang.Class<?> |
getFieldType() |
protected java.lang.invoke.MethodHandle |
getSetter() |
T |
getTarget() |
static boolean |
hasDefault(java.lang.Class<?> clazz)
Determines if a
Class has a default value designated |
boolean |
hasDefaultDerived() |
F |
setDerivedValueFromAccessor()
Sets the derived value from
#deriveValueFromAccessor() using
getSetter() |
void |
setTarget(T target)
Binds a new target to the
BeanPathAdapter.FieldHandle |
protected void |
updateMethodHandles()
|
static <VT> VT |
valueOf(java.lang.Class<VT> valueOfClass,
java.lang.Object value)
Attempts to invoke a <code>valueOf</code> using the specified class
|
F |
valueOf(java.lang.String value)
Attempts to invoke a <code>valueOf</code> using the
getDeclaredFieldType() class |
protected FieldHandle(T target, java.lang.String fieldName, java.lang.Class<F> declaredFieldType)
Constructor
target
- the getTarget()
for the MethodHandle
sfieldName
- the field name defined in the getTarget()
declaredFieldType
- the declared field type for the getFieldName()
protected void updateMethodHandles()
Updates the getAccessor()
and getSetter()
using the
current getTarget()
and getFieldName()
.
MethodHandle
s are immutable so new ones are created.
public static java.lang.Class<?> getAccessorType(java.lang.Object target, java.lang.String fieldName)
Gets the buildAccessorWithLikelyPrefixes(Object, String)
MethodHandle.type()
target
- the accessor targetfieldName
- the field name of the targetprotected static java.lang.invoke.MethodHandle buildAccessorWithLikelyPrefixes(java.lang.Object target, java.lang.String fieldName)
Attempts to build a MethodHandle
accessor for the field name
using common prefixes used for methods to access a field
target
- the target object that the accessor is forfieldName
- the field name that the accessor is forMethodHandle
protected static java.lang.invoke.MethodHandle buildAccessor(java.lang.Object target, java.lang.String fieldName, java.lang.String... fieldNamePrefix)
Attempts to build a MethodHandle
accessor for the field name
using common prefixes used for methods to access a field
target
- the target object that the accessor is forfieldName
- the field name that the accessor is forfieldNamePrefix
- the prefix of the method for the field nameMethodHandle
protected static java.lang.invoke.MethodHandle buildSetter(java.lang.invoke.MethodHandle accessor, java.lang.Object target, java.lang.String fieldName)
Builds a setter MethodHandle
accessor
- the field’s accesssor that will be used as the parameter
type for the settertarget
- the target object that the setter is forfieldName
- the field name that the setter is forMethodHandle
public F valueOf(java.lang.String value)
Attempts to invoke a <code>valueOf</code> using the
getDeclaredFieldType()
class
value
- the value to invoke the <code>valueOf</code> method onpublic static <VT> VT valueOf(java.lang.Class<VT> valueOfClass, java.lang.Object value)
Attempts to invoke a <code>valueOf</code> using the specified class
valueOfClass
- the class to attempt to invoke a <code>valueOf</code>
method onvalue
- the value to invoke the <code>valueOf</code> method onpublic static boolean hasDefault(java.lang.Class<?> clazz)
Determines if a Class
has a default value designated
clazz
- the Class
to checkClass
has a default value designated for
itpublic F defaultValue()
Gets a default value for the getDeclaredFieldType()
public static <VT> VT defaultValue(java.lang.Class<VT> clazz)
Gets a default value for the specified class
clazz
- the classprotected static java.lang.String buildMethodName(java.lang.String prefix, java.lang.String fieldName)
Builds a method name using a prefix and a field name
prefix
- the method’s prefixfieldName
- the method’s field namepublic F setDerivedValueFromAccessor()
Sets the derived value from #deriveValueFromAccessor()
using
getSetter()
#deriveValueFromAccessor()
protected F deriveValueFromAccessor(boolean isNullable)
Gets an accessor’s return target value obtained by calling the
accessor’s MethodHandle#invoke(Object…)
method. When the
value returned is <code>null</code> an attempt will be made to
instantiate it using either by using a default value from
DFLTS
(for primatives) or Class.newInstance()
on the
accessor’s MethodType.returnType()
method.
public void setTarget(T target)
Binds a new target to the BeanPathAdapter.FieldHandle
target
- the target to bind topublic T getTarget()
public java.lang.String getFieldName()
protected java.lang.invoke.MethodHandle getAccessor()
protected java.lang.invoke.MethodHandle getSetter()
public java.lang.Class<F> getDeclaredFieldType()
public java.lang.Class<?> getFieldType()
getAccessor()
of the property
valuepublic boolean hasDefaultDerived()