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 Deprecated 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 JTypeVaraddAnnotation(@NonNull SymbolicValue.SymAnnot newAnnot)Returns a type mirror that is equal to this instance but has one more type annotation.JTypeVarcloneWithBounds(JTypeMirror lower, JTypeMirror upper)@Nullable JWildcardTypegetCapturedOrigin()Returns the original wildcard, if this is a capture variable.@NonNull JTypeMirrorgetLowerBound()Gets the lower bound.@NonNull StringgetName()Returns the name of this variable, which may something autogenerated if this is a captured variable.@Nullable JTypeParameterSymbolgetSymbol()Returns the reflected type variable this instance represents, or null if this is a capture variable.@NonNull JTypeMirrorgetUpperBound()Gets the upper bound.booleanisCaptured()Returns true if this is a capture variable, ie this variable originates from the capture of a wildcard type argument.booleanisCaptureOf(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.JTypeVarsubstInBounds(Function<? super SubstVar,? extends @NonNull JTypeMirror> substitution)LikeSubstVar.subst(Function), except this typevar is not the subject of the substitution, only its bounds.JTypeVarwithAnnotations(org.pcollections.PSet<SymbolicValue.SymAnnot> newTypeAnnots)Returns a type mirror that is equal to this instance but has different type annotations.JTypeVarwithUpperBound(@NonNull JTypeMirror newUB)Deprecated.Since 7.12.0.-
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:
getSymbolin 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
glbed with the declared bound of the wildcard. For example, givenclass Foo<T extends List<T>>, thenFoo<?>will haveTypeSystem.UNBOUNDED_WILDas 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_TYPEconventionally 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:JTypeVisitableAccept a type visitor, dispatching on this object's runtime type to the correct method of the visitor.- Specified by:
acceptVisitorin 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 varNote that this is only supposed to be used internally.
-
withUpperBound
@Deprecated JTypeVar withUpperBound(@NonNull JTypeMirror newUB)
Deprecated.Since 7.12.0. There is no real use case for mutating the upper bound. Also, the bound could have been changed to really anything, which means it wasn't necessarily correct for two of those type vars to compare equals.Return a new type variable with the same underlying symbol or capture variable, but the upper bound is now the given type.Note that this is only supposed to be used internally. For now it only serves to apply type annotations to the upper bound when parsing class files. Some implementations may therefore throw
UnsupportedOperationException.- Parameters:
newUB- New upper bound- Returns:
- a new tvar
-
withAnnotations
JTypeVar withAnnotations(org.pcollections.PSet<SymbolicValue.SymAnnot> newTypeAnnots)
Description copied from interface:JTypeMirrorReturns 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 or void type cannot be annotated.- Specified by:
withAnnotationsin 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:JTypeMirrorReturns a type mirror that is equal to this instance but has one more type annotation.- Specified by:
addAnnotationin interfaceJTypeMirror- See Also:
JTypeMirror.withAnnotations(PSet)
-
streamMethods
default Stream<JMethodSig> streamMethods(Predicate<? super JMethodSymbol> prefilter)
Description copied from interface:JTypeMirrorReturns 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:
streamMethodsin interfaceJTypeMirror- Parameters:
prefilter- Filter selecting symbols for which a signature should be created and yielded by the stream
-
-