Interface JTypeVar
-
- All Superinterfaces:
JTypeMirror
,JTypeVisitable
,SubstVar
public interface JTypeVar extends SubstVar
The type of a type variable. There are two sorts of those:- Types of type parameters, which have a user-defined name, and an origin. Those may only have an upper bound.
- Types of captured variables, which arise from capture-conversion. Those can have a non-trivial lower bound.
Type variables may appear in their own bound (F-bound), and we have to make sure all those occurrences are represented by the same instance. We have to pay attention to cycles in our algos too.
Type variables do not, in general, use reference identity. Use equals to compare them.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <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.default JTypeVar
addAnnotation(@NonNull SymbolicValue.SymAnnot newAnnot)
Returns a type mirror that is equal to this instance but has one more type annotation.JTypeVar
cloneWithBounds(JTypeMirror lower, JTypeMirror upper)
@Nullable JWildcardType
getCapturedOrigin()
Returns the original wildcard, if this is a capture variable.@NonNull JTypeMirror
getLowerBound()
Gets the lower bound.@NonNull String
getName()
Returns the name of this variable, which may something autogenerated if this is a captured variable.@Nullable JTypeParameterSymbol
getSymbol()
Returns the reflected type variable this instance represents, or null if this is a capture variable.@NonNull JTypeMirror
getUpperBound()
Gets the upper bound.boolean
isCaptured()
Returns true if this is a capture variable, ie this variable originates from the capture of a wildcard type argument.boolean
isCaptureOf(JWildcardType wildcard)
Returns true if this is a capture variable for the given wildcard.default Stream<JMethodSig>
streamMethods(Predicate<? super JMethodSymbol> prefilter)
Returns a stream of method signatures declared in and inherited by this type.JTypeVar
substInBounds(Function<? super SubstVar,? extends @NonNull JTypeMirror> substitution)
LikeSubstVar.subst(Function)
, except this typevar is not the subject of the substitution, only its bounds.JTypeVar
withAnnotations(org.pcollections.PSet<SymbolicValue.SymAnnot> newTypeAnnots)
Returns a type mirror that is equal to this instance but has different type annotations.JTypeVar
withUpperBound(@NonNull JTypeMirror newUB)
Return a new type variable with the same underlying symbol or capture variable, but the upper bound is now the given type.-
Methods inherited from interface net.sourceforge.pmd.lang.java.types.JTypeMirror
box, equals, getAsSuper, getConstructors, getErasure, getSuperTypeSet, getTypeAnnotations, getTypeSystem, isArray, isBottom, isBoxedPrimitive, isClassOrInterface, isConvertibleTo, isFloatingPoint, isGeneric, isGenericTypeDeclaration, isIntegral, isInterface, isNumeric, isParameterizedType, isPrimitive, isPrimitive, isRaw, isReifiable, isSubtypeOf, isTop, isTypeVariable, isVoid, streamDeclaredMethods, toString, unbox
-
-
-
-
Method Detail
-
getSymbol
@Nullable JTypeParameterSymbol getSymbol()
Returns the reflected type variable this instance represents, or null if this is a capture variable.- Specified by:
getSymbol
in interfaceJTypeMirror
-
getName
@NonNull String getName()
Returns the name of this variable, which may something autogenerated if this is a captured variable. This is not necessarily an identifier.
-
getUpperBound
@NonNull JTypeMirror getUpperBound()
Gets the upper bound. This defaults to Object, and may be an intersection type.Note that the upper bound of a capture variable is not necessarily the upper bound of the captured wildcard. The declared bound of each variable is
glb
ed with the declared bound of the wildcard. For example, givenclass Foo<T extends List<T>>
, thenFoo<?>
will haveTypeSystem.UNBOUNDED_WILD
as a type argument. But the capture ofFoo<?>
will look likeFoo<capture#.. of ?>
, where the capture var's upper bound is actuallyList<?>
.
-
getLowerBound
@NonNull JTypeMirror getLowerBound()
Gets the lower bound.TypeSystem.NULL_TYPE
conventionally represents the bottom type (a trivial lower bound).
-
isCaptured
boolean isCaptured()
Returns true if this is a capture variable, ie this variable originates from the capture of a wildcard type argument. Capture variables use reference identity.
-
isCaptureOf
boolean isCaptureOf(JWildcardType wildcard)
Returns true if this is a capture variable for the given wildcard.
-
getCapturedOrigin
@Nullable JWildcardType getCapturedOrigin()
Returns the original wildcard, if this is a capture variable. Otherwise returns null.
-
acceptVisitor
default <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
-
substInBounds
JTypeVar substInBounds(Function<? super SubstVar,? extends @NonNull JTypeMirror> substitution)
LikeSubstVar.subst(Function)
, except this typevar is not the subject of the substitution, only its bounds. May return a new tvar, must return this is the bound is unchanged.
-
cloneWithBounds
JTypeVar cloneWithBounds(JTypeMirror lower, JTypeMirror upper)
- Throws:
UnsupportedOperationException
- If this is not a capture var
-
withUpperBound
JTypeVar withUpperBound(@NonNull JTypeMirror newUB)
Return a new type variable with the same underlying symbol or capture variable, but the upper bound is now the given type.- Parameters:
newUB
- New upper bound- Returns:
- a new tvar
-
withAnnotations
JTypeVar 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
-
addAnnotation
default JTypeVar addAnnotation(@NonNull SymbolicValue.SymAnnot newAnnot)
Description copied from interface:JTypeMirror
Returns a type mirror that is equal to this instance but has one more type annotation.- Specified by:
addAnnotation
in interfaceJTypeMirror
- See Also:
JTypeMirror.withAnnotations(PSet)
-
streamMethods
default Stream<JMethodSig> streamMethods(Predicate<? super JMethodSymbol> prefilter)
Description copied from interface:JTypeMirror
Returns a stream of method signatures declared in and inherited by this type. Method signatures are created on-demand by this method, they're not reused between calls. This stream does not include constructors.Note: streams are a bit impractical when it comes to configuring the filter. Possibly a specialized API should be introduced. We need to support the use cases of the symbol table, ie filter by name + accessibility + staticity, and also possibly use cases for rules, like getting a method from a known signature. See also
JClassType.getDeclaredMethod(JExecutableSymbol)
, which looks like this. Unifying this API would be nice.- Specified by:
streamMethods
in interfaceJTypeMirror
- Parameters:
prefilter
- Filter selecting symbols for which a signature should be created and yielded by the stream
-
-