Class InferenceVar
- java.lang.Object
-
- net.sourceforge.pmd.lang.java.types.internal.infer.InferenceVar
-
- All Implemented Interfaces:
JTypeMirror
,JTypeVisitable
,SubstVar
public final class InferenceVar extends Object implements JTypeMirror, SubstVar
Represents an inference variable. Inference variables are just placeholder for types, used during the inference process. After type inference they should have been erased and hence this type is of no importance outside the implementation of this framework.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InferenceVar.BoundKind
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T,P>
TacceptVisitor(JTypeVisitor<T,P> visitor, P p)
Accept a type visitor, dispatching on this object's runtime type to the correct method of the visitor.void
addBound(InferenceVar.BoundKind kind, JTypeMirror type)
Adds a new bound on this variable.void
addPrimaryBound(InferenceVar.BoundKind kind, JTypeMirror type)
String
getName()
@Nullable JTypeDeclSymbol
getSymbol()
Returns the symbol declaring this type.org.pcollections.PSet<SymbolicValue.SymAnnot>
getTypeAnnotations()
Return a list of annotations on this type.TypeSystem
getTypeSystem()
Returns the type system that built this type.boolean
isEquivalentTo(JTypeMirror t)
boolean
isSubtypeNoSideEffect(@NonNull JTypeMirror other)
boolean
isSupertypeNoSideEffect(@NonNull JTypeMirror other)
JTypeMirror
subst(Function<? super SubstVar,? extends @NonNull JTypeMirror> subst)
Replace the type variables occurring in the given type by their image by the given function.String
toString()
The toString of type mirrors prints useful debug information, but shouldn't be relied on anywhere, as it may change anytime.JTypeMirror
withAnnotations(org.pcollections.PSet<SymbolicValue.SymAnnot> newTypeAnnots)
Returns a type mirror that is equal to this instance but has different type annotations.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sourceforge.pmd.lang.java.types.JTypeMirror
addAnnotation, box, equals, getAsSuper, getConstructors, getErasure, getSuperTypeSet, isArray, isBottom, isBoxedPrimitive, isClassOrInterface, isConvertibleTo, isFloatingPoint, isGeneric, isGenericTypeDeclaration, isIntegral, isInterface, isNumeric, isParameterizedType, isPrimitive, isPrimitive, isRaw, isReifiable, isSubtypeOf, isTop, isTypeVariable, isVoid, streamDeclaredMethods, streamMethods, unbox
-
-
-
-
Method Detail
-
withAnnotations
public JTypeMirror withAnnotations(org.pcollections.PSet<SymbolicValue.SymAnnot> newTypeAnnots)
Description copied from interface:JTypeMirror
Returns a type mirror that is equal to this instance but has different type annotations. Note that some types ignore this method and return themselves without changing. Eg the null type cannot be annotated.- Specified by:
withAnnotations
in interfaceJTypeMirror
- Parameters:
newTypeAnnots
- New type annotations (not null)- Returns:
- A new type, maybe this one
-
getTypeAnnotations
public org.pcollections.PSet<SymbolicValue.SymAnnot> getTypeAnnotations()
Description copied from interface:JTypeMirror
Return a list of annotations on this type. Annotations can be written on nearly any type (eg@A Out.@B In<@C T>
,@A ? extends @B Up
).For
JTypeVar
, this includes both the annotations defined on the type var and those defined at use site. For instance
The T type var will have annotation<@A T> void accept(@B T t);
@A
in the symbol (AnnotableSymbol.getDeclaredAnnotations()
) and in the type var that is in theJMethodSig.getTypeParameters()
. In the formal parameter, the type var will have annotations@B @A
.- Specified by:
getTypeAnnotations
in interfaceJTypeMirror
-
getName
public String getName()
-
getTypeSystem
public TypeSystem getTypeSystem()
Description copied from interface:JTypeMirror
Returns the type system that built this type.- Specified by:
getTypeSystem
in interfaceJTypeMirror
-
addBound
public void addBound(InferenceVar.BoundKind kind, JTypeMirror type)
Adds a new bound on this variable.
-
addPrimaryBound
public void addPrimaryBound(InferenceVar.BoundKind kind, JTypeMirror type)
-
isEquivalentTo
public boolean isEquivalentTo(JTypeMirror t)
-
isSubtypeNoSideEffect
public boolean isSubtypeNoSideEffect(@NonNull JTypeMirror other)
-
isSupertypeNoSideEffect
public boolean isSupertypeNoSideEffect(@NonNull JTypeMirror other)
-
getSymbol
public @Nullable JTypeDeclSymbol getSymbol()
Description copied from interface:JTypeMirror
Returns the symbol declaring this type. Reifiable types present a symbol, and some other types too. This method's return value depends on this type:JClassType
: aJClassSymbol
, always (even if not reifiable)JPrimitiveType
: aJClassSymbol
, alwaysJArrayType
: aJClassSymbol
, if the element type does present a symbol.JTypeVar
: aJTypeParameterSymbol
, or null if this is a capture variable. Note that the erasure yields a different symbol (eg Object for unbounded tvars).JIntersectionType
: null, though their erasure always presents a symbol.JWildcardType
,the null type
: null, always
Note that type annotations are not reflected on the symbol, but only on the type.
- Specified by:
getSymbol
in interfaceJTypeMirror
-
subst
public JTypeMirror subst(Function<? super SubstVar,? extends @NonNull JTypeMirror> subst)
Description copied from interface:JTypeVisitable
Replace the type variables occurring in the given type by their image by the given function. Substitutions are not applied recursively (ie, is not applied on the result of a substitution).- Specified by:
subst
in interfaceJTypeMirror
- Specified by:
subst
in interfaceJTypeVisitable
- Specified by:
subst
in interfaceSubstVar
- Parameters:
subst
- Substitution function, eg aSubstitution
-
acceptVisitor
public <T,P> T acceptVisitor(JTypeVisitor<T,P> visitor, P p)
Description copied from interface:JTypeVisitable
Accept a type visitor, dispatching on this object's runtime type to the correct method of the visitor.- Specified by:
acceptVisitor
in interfaceJTypeVisitable
- Type Parameters:
T
- Type of result of the visitorP
- Type of data of the visitor
-
toString
public String toString()
Description copied from interface:JTypeMirror
The toString of type mirrors prints useful debug information, but shouldn't be relied on anywhere, as it may change anytime. UseTypePrettyPrint
to display types.- Specified by:
toString
in interfaceJTypeMirror
- Overrides:
toString
in classObject
-
-