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.UniqueIdentifierFunctionKIND_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,
org.eclipse.xtext.common.types.JvmTypeParameter typeParameter) |
protected |
UnboundTypeReference(ITypeReferenceOwner owner,
XExpression expression,
org.eclipse.xtext.common.types.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,
org.eclipse.xtext.common.types.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() |
org.eclipse.xtext.common.types.util.Primitives.Primitive |
getPrimitiveKind() |
org.eclipse.xtext.common.types.util.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(org.eclipse.xtext.common.types.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) |
org.eclipse.xtext.common.types.JvmType |
getType() |
java.util.List<LightweightTypeReference> |
getTypeArguments()
Returns the type arguments of this reference if it has any.
|
org.eclipse.xtext.common.types.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) |
org.eclipse.xtext.common.types.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.
|
org.eclipse.xtext.common.types.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, toStringprotected UnboundTypeReference(ITypeReferenceOwner owner, XExpression expression, org.eclipse.xtext.common.types.JvmTypeParameter typeParameter)
protected UnboundTypeReference(ITypeReferenceOwner owner, XExpression expression, org.eclipse.xtext.common.types.JvmTypeParameter typeParameter, java.lang.Object handle)
public static UnboundTypeReference create(ITypeExpectation expectation, XExpression expression, org.eclipse.xtext.common.types.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 LightweightTypeReferencepublic 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 org.eclipse.xtext.common.types.JvmTypeReference toTypeReference()
toTypeReference in class LightweightTypeReferencepublic org.eclipse.xtext.common.types.JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper)
LightweightTypeReferenceJvmTypeReference that can
be used in Java source code.toJavaCompliantTypeReference in class LightweightTypeReferencepublic boolean isRawType()
LightweightTypeReferencetrue 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 LightweightTypeReferencepublic boolean isAnonymous()
isAnonymous in class LightweightTypeReferencepublic org.eclipse.xtext.common.types.JvmTypeParameter getTypeParameter()
public java.lang.Object getHandle()
handlepublic LightweightTypeReference getResolvedTo()
null.public LightweightTypeReference getUpperBoundSubstitute()
getUpperBoundSubstitute in class LightweightTypeReferencepublic LightweightTypeReference getLowerBoundSubstitute()
getLowerBoundSubstitute in class LightweightTypeReferencepublic LightweightTypeReference getInvariantBoundSubstitute()
getInvariantBoundSubstitute in class LightweightTypeReferencepublic 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 LightweightTypeReferencepublic boolean isResolved()
isResolved in class LightweightTypeReferencepublic boolean internalIsResolved()
public LightweightTypeReference internalGetResolvedTo()
public java.util.List<LightweightTypeReference> getTypeArguments()
LightweightTypeReferenceList<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 LightweightTypeReferencepublic boolean hasTypeArguments()
hasTypeArguments in class LightweightTypeReferencepublic boolean isArray()
isArray in class LightweightTypeReferencepublic boolean isVisible(IVisibilityHelper visibilityHelper)
LightweightTypeReferencetrue 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 LightweightTypeReferencepublic boolean isAny()
isAny in class LightweightTypeReferencepublic boolean isUnknown()
isUnknown in class LightweightTypeReferencepublic FunctionTypeKind getFunctionTypeKind()
getFunctionTypeKind in class LightweightTypeReferencepublic ArrayTypeReference tryConvertToArray()
LightweightTypeReferenceIterable
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 LightweightTypeReferenceArrayTypeReference or null.public FunctionTypeReference tryConvertToFunctionTypeReference(boolean rawType)
LightweightTypeReferenceFunctionTypeReference if the referenced type is a SAM type.
Returns null if this reference does not point to a valid function type.tryConvertToFunctionTypeReference in class LightweightTypeReferencerawType - if a raw view on the function type is sufficient.LightweightTypeReference.getAsFunctionTypeReference()public LightweightTypeReference tryConvertToListType()
LightweightTypeReferenceList.
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 LightweightTypeReferencenull.public LightweightTypeReference getComponentType()
LightweightTypeReferencegetComponentType in class LightweightTypeReferencenull.LightweightTypeReference.isArray()public boolean isWrapper()
isWrapper in class LightweightTypeReferencepublic boolean isPrimitive()
isPrimitive in class LightweightTypeReferencepublic org.eclipse.xtext.common.types.util.Primitives.Primitive getPrimitiveKind()
getPrimitiveKind in class LightweightTypeReferencepublic org.eclipse.xtext.common.types.util.Primitives.Primitive getPrimitiveKindIfWrapperType()
getPrimitiveKindIfWrapperType in class LightweightTypeReferencepublic boolean isPrimitiveVoid()
isPrimitiveVoid in class LightweightTypeReferencepublic boolean isInterfaceType()
isInterfaceType in class LightweightTypeReferencepublic LightweightTypeReference getPrimitiveIfWrapperType()
getPrimitiveIfWrapperType in class LightweightTypeReferencepublic org.eclipse.xtext.common.types.JvmType getType()
getType in class LightweightTypeReferencepublic boolean isType(java.lang.Class<?> clazz)
LightweightTypeReferenceclazz.
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 LightweightTypeReferenceprotected java.util.List<LightweightTypeReference> getSuperTypes(TypeParameterSubstitutor<?> substitutor)
getSuperTypes in class LightweightTypeReferencepublic LightweightTypeReference getSuperType(org.eclipse.xtext.common.types.JvmType rawType)
LightweightTypeReferencegetSuperType in class LightweightTypeReferencerawType - the raw type that should be resolved.public LightweightTypeReference getSuperType(java.lang.Class<?> rawType)
LightweightTypeReferencenull if the raw type
is not a valid super type of this type.getSuperType in class LightweightTypeReferencerawType - the raw type that should be resolved.public LightweightTypeReference getWrapperTypeIfPrimitive()
getWrapperTypeIfPrimitive in class LightweightTypeReferenceprotected LightweightTypeReference doCopyInto(ITypeReferenceOwner owner)
doCopyInto in class LightweightTypeReferencepublic java.lang.String getSimpleName()
LightweightTypeReferencegetSimpleName in class LightweightTypeReferencepublic java.lang.String getIdentifier()
LightweightTypeReferencegetIdentifier in class LightweightTypeReferencepublic java.lang.String getUniqueIdentifier()
LightweightTypeReferencegetUniqueIdentifier in class LightweightTypeReferencepublic java.lang.String getJavaIdentifier()
getJavaIdentifier in class LightweightTypeReferencepublic void accept(TypeReferenceVisitor visitor)
accept in class LightweightTypeReferencepublic <Param> void accept(TypeReferenceVisitorWithParameter<Param> visitor, Param param)
accept in class LightweightTypeReferencepublic <Result> Result accept(TypeReferenceVisitorWithResult<Result> visitor)
accept in class LightweightTypeReferencepublic <Param,Result> Result accept(TypeReferenceVisitorWithParameterAndResult<Param,Result> visitor, Param param)
accept in class LightweightTypeReferencepublic 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 LightweightTypeReferencepublic boolean isMultiType()
isMultiType in class LightweightTypeReferencepublic boolean isSynonym()
isSynonym in class LightweightTypeReferencepublic LightweightTypeReference toJavaType()
LightweightTypeReferencetoJavaType in class LightweightTypeReferencepublic java.util.List<LightweightTypeReference> getMultiTypeComponents()
getMultiTypeComponents in class LightweightTypeReference