public class BoundSet extends java.lang.Object implements DeepCopyable<BoundSet>
A bound set contains a number of InferenceVariable
instances, and
maintains a set of bounds between them and between other types. Types which
are not inference variables, and do not mention inference variables, are
considered proper types.
Note that instances of InferenceVariable
which are not contained
within a bound set are not considered inference variables within that
context, and are treated as proper types. Inference variables are considered
contained within a bound set if they were added through
withInferenceVariables(Collection)
, or as part of a capture
conversion added through a BoundSet.IncorporationTarget
belonging to that
bound set.
The types of bounds which may be included in a bound set are as follows:
CaptureConversion
which mention inference variables.
An equality bound between an inference variable and a proper type is considered that inference variable's instantiation.
When you add such a bound to a bound set, it may imply the addition of
further bounds, or the reduction of any number of ConstraintFormula
instances into the bound set.
Bound sets, along with the processes of incorporation and reduction described, are typically used to facilitate inference of the type arguments of a generic method invocations, and to resolve overloads for such invocations between multiple methods when some are generic. This implementation therefore allows us to type check and resolve such an invocations at runtime.
We may also employ these processes towards other ends, such as type checking for data serialization formats and libraries, injection frameworks, etc., which may have slightly different rules and requirements to generic method invocation. There are also applications further outside these areas, such as inference of the type arguments of a generic supertype of a given type.
Modifier and Type | Class and Description |
---|---|
class |
BoundSet.IncorporationTarget
Consumer of different sorts of bounds which can be a applied to inference
variables, as per chapter 18 of the Java 8 language specification.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsInferenceVariable(java.lang.reflect.Type type) |
BoundSet |
copy()
Create a copy of an existing bound set.
|
protected BoundSet |
copyInternal() |
BoundSet |
deepCopy(Isomorphism isomorphism)
Create a copy of an existing bound set.
|
static BoundSet |
emptyBoundSet() |
InferenceVariableBounds |
getBoundsOn(InferenceVariable inferenceVariable) |
java.util.stream.Stream<CaptureConversion> |
getCaptureConversions() |
java.util.stream.Stream<InferenceVariableBounds> |
getInferenceVariableBounds() |
java.util.stream.Stream<InferenceVariable> |
getInferenceVariables() |
java.util.stream.Stream<CaptureConversion> |
getRelatedCaptureConversions(java.util.Collection<? extends InferenceVariable> variables) |
protected void |
incorporateCaptureConversion(CaptureConversion captureConversion) |
protected void |
incorporateEquality(java.lang.reflect.Type first,
java.lang.reflect.Type second) |
protected void |
incorporateFalsehood(java.lang.String message) |
protected void |
incorporateSubtype(java.lang.reflect.Type subtype,
java.lang.reflect.Type supertype) |
boolean |
isEmpty() |
java.lang.String |
toString() |
BoundSet |
withBounds(BoundSet boundSet)
Incorporate each bound from this given bound set into the receiver bound
set.
|
BoundSet.IncorporationTarget |
withIncorporated() |
BoundSet |
withInferenceVariables(java.util.Collection<? extends InferenceVariable> inferenceVariables)
Add an inference variable to this bound set such that bounds can be
inferred over it.
|
BoundSet |
withInferenceVariables(InferenceVariable... inferenceVariables)
Add an inference variable to this bound set such that bounds can be
inferred over it.
|
protected BoundSet |
withInferenceVariableSubstitution(Isomorphism isomorphism) |
BoundSet |
withInstantiations(java.util.Map<InferenceVariable,java.lang.reflect.Type> typeVariableCaptures) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
deepCopy
public BoundSet(BoundSet boundSet)
public static BoundSet emptyBoundSet()
public BoundSet copy()
protected BoundSet copyInternal()
public BoundSet deepCopy(Isomorphism isomorphism)
Inference variables which already have proper instantiations may not be substituted, as this is generally unnecessary in practice and so avoiding it can save time.
protected BoundSet withInferenceVariableSubstitution(Isomorphism isomorphism)
protected void incorporateFalsehood(java.lang.String message)
protected void incorporateEquality(java.lang.reflect.Type first, java.lang.reflect.Type second)
protected void incorporateSubtype(java.lang.reflect.Type subtype, java.lang.reflect.Type supertype)
protected void incorporateCaptureConversion(CaptureConversion captureConversion)
public java.util.stream.Stream<InferenceVariable> getInferenceVariables()
public boolean isEmpty()
public java.util.stream.Stream<InferenceVariableBounds> getInferenceVariableBounds()
public InferenceVariableBounds getBoundsOn(InferenceVariable inferenceVariable)
inferenceVariable
- An inference variable whose state we wish to query.public java.util.stream.Stream<CaptureConversion> getCaptureConversions()
public java.util.stream.Stream<CaptureConversion> getRelatedCaptureConversions(java.util.Collection<? extends InferenceVariable> variables)
variables
- inference variables mentioned by the capture conversions we wish
to identifypublic boolean containsInferenceVariable(java.lang.reflect.Type type)
type
- the type we wish to classifypublic java.lang.String toString()
toString
in class java.lang.Object
public BoundSet.IncorporationTarget withIncorporated()
public BoundSet withBounds(BoundSet boundSet)
boundSet
- The bound set whose bounds we wish to incorporate.public BoundSet withInferenceVariables(InferenceVariable... inferenceVariables)
inferenceVariables
- the inference variables to add to the bound setpublic BoundSet withInferenceVariables(java.util.Collection<? extends InferenceVariable> inferenceVariables)
inferenceVariables
- the inference variable to add to the bound setpublic BoundSet withInstantiations(java.util.Map<InferenceVariable,java.lang.reflect.Type> typeVariableCaptures)