O
- the owner type which the field belongs toT
- the type of the fieldpublic class FieldToken<O,T> extends java.lang.Object implements MemberToken<O,FieldToken<O,T>>
Modifier | Constructor and Description |
---|---|
protected |
FieldToken(java.lang.Class<?> instance,
java.lang.reflect.Field field) |
Modifier and Type | Method and Description |
---|---|
static FieldToken<java.lang.Void,?> |
forField(java.lang.reflect.Field field)
Create a new
FieldToken instance from a reference to a Field
of an outer or static class. |
static FieldToken<java.lang.Void,?> |
forStaticField(java.lang.reflect.Field field)
Create a new
FieldToken instance from a reference to a Field . |
T |
get(O target) |
BoundSet |
getBounds() |
TypeToken<T> |
getFieldType() |
java.lang.reflect.Field |
getMember() |
java.lang.String |
getName() |
java.util.Optional<? extends DeclarationToken<?>> |
getOwningDeclaration() |
TypeToken<? super O> |
getReceiverType()
This is the exact receiver type which this member should be accessed from or
invoked upon.
|
java.util.stream.Stream<TypeArgument<?>> |
getTypeArguments() |
int |
getTypeParameterCount() |
java.util.stream.Stream<TypeParameter<?>> |
getTypeParameters() |
boolean |
isGeneric() |
boolean |
isTransient() |
boolean |
isVolatile() |
FieldToken<? extends O,? extends T> |
parameterize()
If the declaration is raw, parameterize it with its own type parameters,
otherwise return the declaration itself.
|
FieldToken<O,T> |
resolve()
Derived a new
MemberToken instance with all associated generic
parameters inferred. |
void |
set(O target,
T value) |
static java.util.stream.Stream<FieldToken<java.lang.Void,?>> |
staticFields(java.lang.Class<?> declaringClass)
Find which fields are declared on this type.
|
FieldToken<O,T> |
withAllTypeArguments(java.util.List<java.lang.reflect.Type> typeArguments)
Derive a new
DeclarationToken instance with the given type argument
parameterization. |
FieldToken<O,T> |
withAllTypeArguments(java.lang.reflect.Type... typeArguments) |
<S> FieldToken<O,? super S> |
withAssignmentFrom(java.lang.Class<S> target)
As @see
withAssignmentFrom(TypeToken) . |
FieldToken<O,?> |
withAssignmentFrom(java.lang.reflect.Type target)
As @see
withAssignmentFrom(TypeToken) . |
<S> FieldToken<O,? super S> |
withAssignmentFrom(TypeToken<S> target)
Derive a new instance of
FieldToken which is assignment compatible
from the given type. |
<S> FieldToken<O,? extends S> |
withAssignmentTo(java.lang.Class<S> target)
As @see
withAssignmentTo(TypeToken) . |
FieldToken<O,?> |
withAssignmentTo(java.lang.reflect.Type target)
As @see
withAssignmentTo(TypeToken) . |
<S> FieldToken<O,? extends S> |
withAssignmentTo(TypeToken<S> target)
Derive a new instance of
FieldToken with the given assignment target
type. |
FieldToken<O,T> |
withBounds(BoundSet bounds)
Derive a new
FieldToken instance, with the given bounds incorporated
into the bounds of the underlying resolver. |
FieldToken<?,? extends T> |
withReceiverType(java.lang.reflect.Type type)
|
<U> FieldToken<U,? extends T> |
withReceiverType(TypeToken<U> type)
Derive a new instance of
MemberToken with the given owner type. |
<S> FieldToken<O,S> |
withType(java.lang.Class<S> target)
As @see
withType(TypeToken) . |
FieldToken<O,?> |
withType(java.lang.reflect.Type target)
As @see
withType(TypeToken) . |
<S> FieldToken<O,S> |
withType(TypeToken<S> target)
Derive a new instance of
FieldToken with the exact given type. |
FieldToken<O,T> |
withTypeArguments(java.util.Collection<? extends TypeArgument<?>> arguments)
Derive a new
ExecutableToken instance from this, with types
substituted according to the given arguments. |
FieldToken<O,T> |
withTypeArguments(java.util.List<java.lang.reflect.Type> typeArguments)
As @see
DeclarationToken.withAllTypeArguments(List) , but only providing arguments for
the parameters occurring directly on the declaration. |
FieldToken<O,T> |
withTypeArguments(java.lang.reflect.Type... typeArguments) |
protected FieldToken<O,T> |
withTypeSubstitution(BoundSet bounds,
TypeSubstitution typeSubstitution) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDeclaringClass, getVisibility, isFinal, isRaw, isStatic
getAllTypeArguments, getAllTypeParameterCount, getAllTypeParameters, resolveTypeArgument, resolveTypeArgument, withTypeArguments
protected FieldToken(java.lang.Class<?> instance, java.lang.reflect.Field field)
public static FieldToken<java.lang.Void,?> forField(java.lang.reflect.Field field)
FieldToken
instance from a reference to a Field
of an outer or static class.
If the method is generic it will be parameterized with its own type variables.
field
- the field to wrappublic static FieldToken<java.lang.Void,?> forStaticField(java.lang.reflect.Field field)
FieldToken
instance from a reference to a Field
.field
- the field to wrappublic java.lang.String getName()
getName
in interface MemberToken<O,FieldToken<O,T>>
public java.lang.reflect.Field getMember()
getMember
in interface MemberToken<O,FieldToken<O,T>>
Member
object backing the MemberToken
.public BoundSet getBounds()
getBounds
in interface MemberToken<O,FieldToken<O,T>>
MemberToken
public boolean isVolatile()
public boolean isTransient()
public TypeToken<? super O> getReceiverType()
MemberToken
For non-static members, this type will be identical to the
owning type
.
For constructors and static members, if they are declared on a non-static inner class then the receiver type should be a subtype of the enclosing class, otherwise the receiver type should be void.
getReceiverType
in interface MemberToken<O,FieldToken<O,T>>
void.class
if the member has no receiver typepublic TypeToken<T> getFieldType()
public FieldToken<? extends O,? extends T> parameterize()
public FieldToken<O,T> withBounds(BoundSet bounds)
FieldToken
instance, with the given bounds incorporated
into the bounds of the underlying resolver. The original FieldToken
will remain unmodified.withBounds
in interface MemberToken<O,FieldToken<O,T>>
bounds
- The new bounds to incorporate.ExecutableToken
.protected FieldToken<O,T> withTypeSubstitution(BoundSet bounds, TypeSubstitution typeSubstitution)
public FieldToken<?,? extends T> withReceiverType(java.lang.reflect.Type type)
MemberToken
withReceiverType
in interface MemberToken<O,FieldToken<O,T>>
public <U> FieldToken<U,? extends T> withReceiverType(TypeToken<U> type)
MemberToken
MemberToken
with the given owner type.
The new MemberToken
will always have a owner type which is as or more
specific than both the current receiver type and the given type.
This means that the new owner will be assignment compatible with the given
type, but if the given type contains wildcards or inference variables which
are less specific that those implied by the current receiver type,
new type arguments will be inferred in their place, or further bounds may be
added to them.
If the receiver type is not generic, the method will always return the same token, or will throw an exception if the given type is not a subtype of the receiver.
This may result in unsafe transformations when we convert from a raw receiver to a parameterized receiver, but declarations of those types should give a raw type warning from the Java compiler and this is considered sufficient.
withReceiverType
in interface MemberToken<O,FieldToken<O,T>>
type
- The new owner type. The raw type of this type must be a subtype of
the raw type of the current receiver type.MemberToken
compatible with the given owner type.
The new owner type will not be effectively more specific than the intersection type of the current owner type and the given type. That is, any type which can be assigned to both the given type and the current owner type, will also be assignable to the new type.
public <S> FieldToken<O,S> withType(java.lang.Class<S> target)
withType(TypeToken)
.public FieldToken<O,?> withType(java.lang.reflect.Type target)
withType(TypeToken)
.public <S> FieldToken<O,S> withType(TypeToken<S> target)
FieldToken
with the exact given type.
TODO documentpublic <S> FieldToken<O,? extends S> withAssignmentTo(java.lang.Class<S> target)
withAssignmentTo(TypeToken)
.public FieldToken<O,?> withAssignmentTo(java.lang.reflect.Type target)
withAssignmentTo(TypeToken)
.public <S> FieldToken<O,? extends S> withAssignmentTo(TypeToken<S> target)
FieldToken
with the given assignment target
type.
TODO documentpublic <S> FieldToken<O,? super S> withAssignmentFrom(java.lang.Class<S> target)
withAssignmentFrom(TypeToken)
.public FieldToken<O,?> withAssignmentFrom(java.lang.reflect.Type target)
withAssignmentFrom(TypeToken)
.public <S> FieldToken<O,? super S> withAssignmentFrom(TypeToken<S> target)
FieldToken
which is assignment compatible
from the given type.
TODO documentpublic FieldToken<O,T> resolve()
MemberToken
MemberToken
instance with all associated generic
parameters inferred.resolve
in interface MemberToken<O,FieldToken<O,T>>
MemberToken
with inferred typespublic T get(O target)
target
- the instance to access the field ofpublic void set(O target, T value)
target
- the instance to assign to the field ofvalue
- the value to assignpublic java.util.Optional<? extends DeclarationToken<?>> getOwningDeclaration()
getOwningDeclaration
in interface DeclarationToken<FieldToken<O,T>>
public int getTypeParameterCount()
getTypeParameterCount
in interface DeclarationToken<FieldToken<O,T>>
public java.util.stream.Stream<TypeParameter<?>> getTypeParameters()
getTypeParameters
in interface DeclarationToken<FieldToken<O,T>>
Executable
, or their inference variables if not yet
instantiated.public java.util.stream.Stream<TypeArgument<?>> getTypeArguments()
getTypeArguments
in interface DeclarationToken<FieldToken<O,T>>
Executable
, or their inference variables if not yet
instantiated.public FieldToken<O,T> withTypeArguments(java.util.Collection<? extends TypeArgument<?>> arguments)
DeclarationToken
ExecutableToken
instance from this, with types
substituted according to the given arguments.
More specifically, each of the given arguments represents a type variable and an instantiation for that type variable. Occurrences of those type variables in the declaration will be substituted for their instantiations in the derived declaration.
The substitution will only succeed if it results in a valid parameterization of the declaration.
For example, the following method could be used to derive instances of
TypeToken over different parameterizations of List<?>
at runtime.
public TypeToken<List<T>> getListType(TypeToken<T> elementType)} {
return new TypeToken<T>()} {}.withTypeArguments(new TypeParameter<T>() {}.as(elementType));
}
withTypeArguments
in interface DeclarationToken<FieldToken<O,T>>
arguments
- the type variable instantiationsExecutableToken
instance with the given
instantiation substituted for the given type variablepublic boolean isGeneric()
isGeneric
in interface DeclarationToken<FieldToken<O,T>>
public FieldToken<O,T> withAllTypeArguments(java.util.List<java.lang.reflect.Type> typeArguments)
DeclarationToken
DeclarationToken
instance with the given type argument
parameterization.
The types in the given list correspond, in order, to the
type parameters
of this declaration. The current
parameterization of the declaration is substituted for that given.
Each substitution will only succeed if it is compatible with the bounds on
that type variable, and if it is more specific than the current argument,
whether it is an InferenceVariable
, a TypeVariableCapture
, or
another kind of Type
.
This behavior is different from DeclarationToken.withTypeArguments(Collection)
, which
performs a substitution for arbitrary type variables rather than
re-instantiating every parameter on the declaration.
withAllTypeArguments
in interface DeclarationToken<FieldToken<O,T>>
typeArguments
- a list of arguments for each generic type parameter of the
underlying declarationDeclarationToken
instance with the given
instantiations substituted for each generic type parameter, in orderpublic FieldToken<O,T> withTypeArguments(java.util.List<java.lang.reflect.Type> typeArguments)
DeclarationToken
DeclarationToken.withAllTypeArguments(List)
, but only providing arguments for
the parameters occurring directly on the declaration.withTypeArguments
in interface DeclarationToken<FieldToken<O,T>>
public FieldToken<O,T> withAllTypeArguments(java.lang.reflect.Type... typeArguments)
withAllTypeArguments
in interface DeclarationToken<FieldToken<O,T>>
DeclarationToken.withTypeArguments(List)
public FieldToken<O,T> withTypeArguments(java.lang.reflect.Type... typeArguments)
withTypeArguments
in interface DeclarationToken<FieldToken<O,T>>
DeclarationToken.withTypeArguments(List)
public static java.util.stream.Stream<FieldToken<java.lang.Void,?>> staticFields(java.lang.Class<?> declaringClass)
declaringClass
- the declaring class for which to retrieve the fieldsField
objects applicable to this type, wrapped in
FieldToken
instances