public class UnboundTypeReference extends LightweightTypeReference
UnboundTypeReference
should be created with a concrete ITypeExpectation
via the factory method ITypeExpectation.createUnboundTypeReference(XExpression, JvmTypeParameter)
or create(ITypeExpectation, XExpression, JvmTypeParameter)
respectively.
Such type references may be produced in cases like
val x = newArrayList
where x
has the inferred type ArrayList<Unbound[E]>
.
Unbound types may be enhanced with hints
to
allow the type inferrer to find the most suitable type.LightweightTypeReference.IdentifierFunction, LightweightTypeReference.JavaIdentifierFunction, LightweightTypeReference.SimpleNameFunction, LightweightTypeReference.UniqueIdentifierFunction
KIND_ANY_TYPE_REFERENCE, KIND_ARRAY_TYPE_REFERENCE, KIND_COMPOUND_TYPE_REFERENCE, KIND_FUNCTION_TYPE_REFERENCE, KIND_INNER_FUNCTION_TYPE_REFERENCE, KIND_INNER_TYPE_REFERENCE, KIND_LIGHTWEIGHT_TYPE_REFERENCE, KIND_PARAMETERIZED_TYPE_REFERENCE, KIND_UNBOUND_TYPE_REFERENCE, KIND_UNKNOWN_TYPE_REFERENCE, KIND_WILDCARD_TYPE_REFERENCE
Modifier | Constructor and Description |
---|---|
protected |
UnboundTypeReference(ITypeReferenceOwner owner,
XExpression expression,
JvmTypeParameter typeParameter) |
protected |
UnboundTypeReference(ITypeReferenceOwner owner,
XExpression expression,
JvmTypeParameter typeParameter,
java.lang.Object handle) |
Modifier and Type | Method and Description |
---|---|
void |
accept(TypeReferenceVisitor visitor) |
<Param> void |
accept(TypeReferenceVisitorWithParameter<Param> visitor,
Param param) |
<Param,Result> |
accept(TypeReferenceVisitorWithParameterAndResult<Param,Result> visitor,
Param param) |
<Result> Result |
accept(TypeReferenceVisitorWithResult<Result> visitor) |
void |
acceptHint(LightweightBoundTypeArgument hint) |
void |
acceptHint(LightweightTypeReference hint,
BoundTypeArgumentSource source,
java.lang.Object origin,
VarianceInfo expectedVariance,
VarianceInfo actualVariance)
Attach a resolution hint to this unbound type reference.
|
void |
acceptHint(VarianceInfo variance) |
boolean |
canResolveTo(LightweightTypeReference reference)
Returns true if the existing hints would allow to resolve to the given reference.
|
protected boolean |
canResolveTo(LightweightTypeReference reference,
java.util.List<LightweightBoundTypeArgument> allHints) |
LightweightTypeReference |
copyInto(ITypeReferenceOwner owner)
Always copies the reference since we want to reduce the nesting level
of references if this one was resolved but points to something unresolved.
|
static UnboundTypeReference |
create(ITypeExpectation expectation,
XExpression expression,
JvmTypeParameter typeParameter)
Create a new, managed unbound type reference for the given type parameter which was
first encountered for the given expression.
|
protected UnboundTypeReference |
createCopy(ITypeReferenceOwner owner) |
protected LightweightTypeReference |
doCopyInto(ITypeReferenceOwner owner) |
boolean |
equalHandles(UnboundTypeReference reference) |
java.util.List<LightweightBoundTypeArgument> |
getAllHints() |
LightweightTypeReference |
getComponentType()
Returns the component type of the current array type.
|
XExpression |
getExpression() |
FunctionTypeKind |
getFunctionTypeKind() |
java.lang.Object |
getHandle()
Returns the identifying handle for this reference.
|
java.lang.String |
getIdentifier()
Returns the identifier of this type reference.
|
LightweightTypeReference |
getInvariantBoundSubstitute() |
java.lang.String |
getJavaIdentifier() |
int |
getKind()
Subclasses must override this method.
|
LightweightTypeReference |
getLowerBoundSubstitute() |
java.util.List<LightweightTypeReference> |
getMultiTypeComponents() |
LightweightTypeReference |
getPrimitiveIfWrapperType() |
Primitives.Primitive |
getPrimitiveKind() |
Primitives.Primitive |
getPrimitiveKindIfWrapperType() |
LightweightTypeReference |
getResolvedTo()
Returns the resolved reference for this unbound reference.
|
java.lang.String |
getSimpleName()
Prints the simple name of this type reference.
|
LightweightTypeReference |
getSuperType(java.lang.Class<?> rawType)
Returns the resolved super type for the given raw type or
null if the raw type
is not a valid super type of this type. |
LightweightTypeReference |
getSuperType(JvmType rawType)
Returns the resolved super type for the given raw type or null if the raw type
is not a valid super type of this type.
|
protected java.util.List<LightweightTypeReference> |
getSuperTypes(TypeParameterSubstitutor<?> substitutor) |
JvmType |
getType() |
java.util.List<LightweightTypeReference> |
getTypeArguments()
Returns the type arguments of this reference if it has any.
|
JvmTypeParameter |
getTypeParameter() |
java.lang.String |
getUniqueIdentifier()
Returns an identifier that allows to disambiguate type parameter names that have
different origins.
|
LightweightTypeReference |
getUpperBoundSubstitute() |
LightweightTypeReference |
getWrapperTypeIfPrimitive() |
boolean |
hasSignificantHints() |
boolean |
hasSignificantHints(java.util.List<LightweightBoundTypeArgument> hints) |
protected boolean |
hasSignificantHints(java.util.List<LightweightBoundTypeArgument> hints,
boolean constraintsAreSignificant) |
boolean |
hasTypeArguments() |
LightweightTypeReference |
internalGetResolvedTo() |
boolean |
internalIsResolved() |
boolean |
isAnonymous() |
boolean |
isAny() |
boolean |
isArray() |
boolean |
isInterfaceType() |
boolean |
isMultiType() |
boolean |
isPrimitive() |
boolean |
isPrimitiveVoid() |
boolean |
isRawType()
Returns
true is this type points to a raw type. |
boolean |
isResolved() |
boolean |
isSynonym() |
boolean |
isType(java.lang.Class<?> clazz)
Returns true if this type reference represents an type with the given
raw type
clazz . |
boolean |
isUnknown() |
boolean |
isVisible(IVisibilityHelper visibilityHelper)
Returns
true if this type is fully visible according to the given visibilityHelper . |
boolean |
isWildcard() |
boolean |
isWrapper() |
protected void |
propageResolvedTypeToConstraints(java.util.List<LightweightBoundTypeArgument> hints) |
LightweightTypeReference |
resolve()
Force this reference to be resolved.
|
protected void |
resolveAgainstConstraints() |
protected boolean |
resolveWithHints(java.util.List<LightweightBoundTypeArgument> allHints) |
JvmTypeReference |
toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper)
Converts this type reference to a
JvmTypeReference that can
be used in Java source code. |
LightweightTypeReference |
toJavaType()
Converts types to references that can be expressed as Java type references
in source code.
|
JvmTypeReference |
toTypeReference() |
ArrayTypeReference |
tryConvertToArray()
Returns the array representation of this reference if its represents a subtype of
Iterable
or already an array itself. |
FunctionTypeReference |
tryConvertToFunctionTypeReference(boolean rawType)
Converts this reference to a
FunctionTypeReference if the referenced type is a SAM type. |
LightweightTypeReference |
tryConvertToListType()
Returns the list representation of this reference if it represents an array or is
already a subtype of
List . |
void |
tryResolve()
Try to resolve this reference iff there are hints available.
|
void |
tryResolve(boolean constraintsAreSignificant)
Try to resolve this reference iff there are hints available.
|
collectSuperTypes, collectSuperTypes, createSubstitutor, expose, findNonNullType, findType, getAllSuperTypes, getAsFunctionTypeReference, getHumanReadableName, getNamedType, getNonInterfaceTypes, getOuter, getOwner, getRawTypeReference, getRawTypes, getServices, getSuperTypes, getTypesFactory, getUniqueIdentifier, internalFindTopLevelType, internalIsAssignableFrom, isAssignableFrom, isAssignableFrom, isAssignableFrom, isAssignableFrom, isFunctionType, isOwnedBy, isSubtypeOf, isSubtypeOf, isValidHint, toJavaCompliantTypeReference, toJavaCompliantTypeReference, toString
protected UnboundTypeReference(ITypeReferenceOwner owner, XExpression expression, JvmTypeParameter typeParameter)
protected UnboundTypeReference(ITypeReferenceOwner owner, XExpression expression, JvmTypeParameter typeParameter, java.lang.Object handle)
public static UnboundTypeReference create(ITypeExpectation expectation, XExpression expression, JvmTypeParameter typeParameter)
expression
- the expression that used / referenced the type parametertypeParameter
- the type parameterexpectation
- the decision path that uses the type parameterpublic int getKind()
getKind
in class LightweightTypeReference
public XExpression getExpression()
protected UnboundTypeReference createCopy(ITypeReferenceOwner owner)
public void tryResolve()
tryResolve(true)
.tryResolve(boolean)
public void tryResolve(boolean constraintsAreSignificant)
public boolean canResolveTo(LightweightTypeReference reference)
public boolean hasSignificantHints()
public boolean hasSignificantHints(java.util.List<LightweightBoundTypeArgument> hints)
protected boolean hasSignificantHints(java.util.List<LightweightBoundTypeArgument> hints, boolean constraintsAreSignificant)
public JvmTypeReference toTypeReference()
toTypeReference
in class LightweightTypeReference
public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper)
LightweightTypeReference
JvmTypeReference
that can
be used in Java source code.toJavaCompliantTypeReference
in class LightweightTypeReference
public boolean isRawType()
LightweightTypeReference
true
is this type points to a raw type.
That is, it points to a parameterized type but does not define type arguments or
it points to an external type parameter that has a raw type constraint.
Type parameters that are declared by the current owner are not considered to be raw types.
A type is also a raw type if it inherits from a raw type.isRawType
in class LightweightTypeReference
public boolean isAnonymous()
isAnonymous
in class LightweightTypeReference
public JvmTypeParameter getTypeParameter()
public java.lang.Object getHandle()
handle
public LightweightTypeReference getResolvedTo()
null
.public LightweightTypeReference getUpperBoundSubstitute()
getUpperBoundSubstitute
in class LightweightTypeReference
public LightweightTypeReference getLowerBoundSubstitute()
getLowerBoundSubstitute
in class LightweightTypeReference
public LightweightTypeReference getInvariantBoundSubstitute()
getInvariantBoundSubstitute
in class LightweightTypeReference
public LightweightTypeReference resolve()
null
.protected void resolveAgainstConstraints()
protected boolean canResolveTo(LightweightTypeReference reference, java.util.List<LightweightBoundTypeArgument> allHints)
protected boolean resolveWithHints(java.util.List<LightweightBoundTypeArgument> allHints)
protected void propageResolvedTypeToConstraints(java.util.List<LightweightBoundTypeArgument> hints)
public LightweightTypeReference copyInto(ITypeReferenceOwner owner)
copyInto
in class LightweightTypeReference
public boolean isResolved()
isResolved
in class LightweightTypeReference
public boolean internalIsResolved()
public LightweightTypeReference internalGetResolvedTo()
public java.util.List<LightweightTypeReference> getTypeArguments()
LightweightTypeReference
List<String>
is String
.
? extends List<String>
.
Raw types don't carry type arguments. Wildcards with more than one upper bound
don't carry type arguments.getTypeArguments
in class LightweightTypeReference
public boolean hasTypeArguments()
hasTypeArguments
in class LightweightTypeReference
public boolean isArray()
isArray
in class LightweightTypeReference
public boolean isVisible(IVisibilityHelper visibilityHelper)
LightweightTypeReference
true
if this type is fully visible according to the given visibilityHelper
.
All components and bounds are taken into account, e.g.
arrays
use their component type
and generified types
check their type arguments, too.isVisible
in class LightweightTypeReference
public boolean isAny()
isAny
in class LightweightTypeReference
public boolean isUnknown()
isUnknown
in class LightweightTypeReference
public FunctionTypeKind getFunctionTypeKind()
getFunctionTypeKind
in class LightweightTypeReference
public ArrayTypeReference tryConvertToArray()
LightweightTypeReference
Iterable
or already an array itself.
If the iterable's type is a primitive wrapper, the array is not the primitive array but
the wrapper array. May return null
if the conversion is not possible.tryConvertToArray
in class LightweightTypeReference
ArrayTypeReference
or null
.public FunctionTypeReference tryConvertToFunctionTypeReference(boolean rawType)
LightweightTypeReference
FunctionTypeReference
if the referenced type is a SAM type.
Returns null
if this reference does not point to a valid function type.tryConvertToFunctionTypeReference
in class LightweightTypeReference
rawType
- if a raw view on the function type is sufficient.LightweightTypeReference.getAsFunctionTypeReference()
public LightweightTypeReference tryConvertToListType()
LightweightTypeReference
List
.
If the array's type is a primitive, the list's element type is the wrapper.
May return null
if the conversion is not possible.tryConvertToListType
in class LightweightTypeReference
null
.public LightweightTypeReference getComponentType()
LightweightTypeReference
getComponentType
in class LightweightTypeReference
null
.LightweightTypeReference.isArray()
public boolean isWrapper()
isWrapper
in class LightweightTypeReference
public boolean isPrimitive()
isPrimitive
in class LightweightTypeReference
public Primitives.Primitive getPrimitiveKind()
getPrimitiveKind
in class LightweightTypeReference
public Primitives.Primitive getPrimitiveKindIfWrapperType()
getPrimitiveKindIfWrapperType
in class LightweightTypeReference
public boolean isPrimitiveVoid()
isPrimitiveVoid
in class LightweightTypeReference
public boolean isInterfaceType()
isInterfaceType
in class LightweightTypeReference
public LightweightTypeReference getPrimitiveIfWrapperType()
getPrimitiveIfWrapperType
in class LightweightTypeReference
public JvmType getType()
getType
in class LightweightTypeReference
public boolean isType(java.lang.Class<?> clazz)
LightweightTypeReference
clazz
.
Returns false if this is not exactly the given type, but a sub type, a
super type or a completely unrelated type.isType
in class LightweightTypeReference
protected java.util.List<LightweightTypeReference> getSuperTypes(TypeParameterSubstitutor<?> substitutor)
getSuperTypes
in class LightweightTypeReference
public LightweightTypeReference getSuperType(JvmType rawType)
LightweightTypeReference
getSuperType
in class LightweightTypeReference
rawType
- the raw type that should be resolved.public LightweightTypeReference getSuperType(java.lang.Class<?> rawType)
LightweightTypeReference
null
if the raw type
is not a valid super type of this type.getSuperType
in class LightweightTypeReference
rawType
- the raw type that should be resolved.public LightweightTypeReference getWrapperTypeIfPrimitive()
getWrapperTypeIfPrimitive
in class LightweightTypeReference
protected LightweightTypeReference doCopyInto(ITypeReferenceOwner owner)
doCopyInto
in class LightweightTypeReference
public java.lang.String getSimpleName()
LightweightTypeReference
getSimpleName
in class LightweightTypeReference
public java.lang.String getIdentifier()
LightweightTypeReference
getIdentifier
in class LightweightTypeReference
public java.lang.String getUniqueIdentifier()
LightweightTypeReference
getUniqueIdentifier
in class LightweightTypeReference
public java.lang.String getJavaIdentifier()
getJavaIdentifier
in class LightweightTypeReference
public void accept(TypeReferenceVisitor visitor)
accept
in class LightweightTypeReference
public <Param> void accept(TypeReferenceVisitorWithParameter<Param> visitor, Param param)
accept
in class LightweightTypeReference
public <Result> Result accept(TypeReferenceVisitorWithResult<Result> visitor)
accept
in class LightweightTypeReference
public <Param,Result> Result accept(TypeReferenceVisitorWithParameterAndResult<Param,Result> visitor, Param param)
accept
in class LightweightTypeReference
public void acceptHint(VarianceInfo variance)
public void acceptHint(LightweightTypeReference hint, BoundTypeArgumentSource source, java.lang.Object origin, VarianceInfo expectedVariance, VarianceInfo actualVariance)
Attach a resolution hint to this unbound type reference.
Only valid
hints can be accepted. The given source indicates the
quality of this hint. The variances
indicate how the hint was used and
how it was expected to be used. A hint from a co-variant location may not have the same impact
for a contra-variant usage as a contra-variant hint. Consider a return type of a method
<T> Collection<? extends T> m(..) { }
Collection<? super CharSequence> variable = m(..)
The hint that stems from the variable declaration may not be very useful since the variances are not compatible. Nevertheless, it can be accepted to produce better error messages.
hint
- the reference that provides the hint.source
- the source of this hint, e.g. an inferred hint, or an expectation.origin
- the object that produced the hint. Only for debugging purpose to trace the origin of a hint.expectedVariance
- the expected variance, e.g. where this unbound type reference is used.actualVariance
- how the hint is used.LightweightTypeReference.isValidHint()
public void acceptHint(LightweightBoundTypeArgument hint)
public java.util.List<LightweightBoundTypeArgument> getAllHints()
public boolean equalHandles(UnboundTypeReference reference)
public boolean isWildcard()
isWildcard
in class LightweightTypeReference
public boolean isMultiType()
isMultiType
in class LightweightTypeReference
public boolean isSynonym()
isSynonym
in class LightweightTypeReference
public LightweightTypeReference toJavaType()
LightweightTypeReference
toJavaType
in class LightweightTypeReference
public java.util.List<LightweightTypeReference> getMultiTypeComponents()
getMultiTypeComponents
in class LightweightTypeReference