Class JArrayType
- java.lang.Object
-
- net.sourceforge.pmd.lang.java.types.JArrayType
-
- All Implemented Interfaces:
JTypeMirror
,JTypeVisitable
public final class JArrayType extends Object implements JTypeMirror
An array type (1 dimension). Multi-level arrays have an array type as component themselves.
-
-
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.boolean
equals(Object o)
Returns true if the object is a type equivalent to this one.JTypeMirror
getComponentType()
Gets the component type of this array.List<JMethodSig>
getConstructors()
Returns a list of all the declared constructors for this type.JTypeMirror
getElementType()
Gets the element type of this array.JArrayType
getErasure()
Returns the erasure of this type.@NonNull JClassSymbol
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.int
hashCode()
boolean
isInterface()
Returns true if this is an interface type.boolean
isRaw()
Returns true if this is a raw type.Stream<JMethodSig>
streamDeclaredMethods(Predicate<? super JMethodSymbol> prefilter)
LikestreamMethods
, but does not recurse into supertypes.Stream<JMethodSig>
streamMethods(Predicate<? super JMethodSymbol> prefilter)
Returns a stream of method signatures declared in and inherited by this type.JArrayType
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.JArrayType
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, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sourceforge.pmd.lang.java.types.JTypeMirror
addAnnotation, box, getAsSuper, getSuperTypeSet, isArray, isBottom, isBoxedPrimitive, isClassOrInterface, isConvertibleTo, isFloatingPoint, isGeneric, isGenericTypeDeclaration, isIntegral, isNumeric, isParameterizedType, isPrimitive, isPrimitive, isReifiable, isSubtypeOf, isTop, isTypeVariable, isVoid, unbox
-
-
-
-
Method Detail
-
getTypeSystem
public TypeSystem getTypeSystem()
Description copied from interface:JTypeMirror
Returns the type system that built this type.- Specified by:
getTypeSystem
in interfaceJTypeMirror
-
getSymbol
public @NonNull JClassSymbol 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
-
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
-
withAnnotations
public JArrayType 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
-
isInterface
public boolean isInterface()
Description copied from interface:JTypeMirror
Returns true if this is an interface type. Annotations are also interface types.- Specified by:
isInterface
in interfaceJTypeMirror
-
getErasure
public JArrayType getErasure()
Description copied from interface:JTypeMirror
Returns the erasure of this type. Erasure is defined by JLS§4.6, an adapted definition follows:- The erasure of a parameterized type (§4.5) G<T1,...,Tn> is |G|.
- The erasure of a nested type T.C is |T|.C.
- The erasure of an array type T[] is |T|[].
- The erasure of a type variable (§4.4) is the erasure of its upper bound.
- The erasure of an intersection type is the erasure of its leftmost component.
- The erasure of every other type is the type itself.
The JVM representation of a type is in general the symbol of its erasure. So to get a
Class
instance for the runtime representation of a type, you should dot.getErasure().getSymbol()
. The erasure procedure gets rid of types that have no symbol (except ift
is a wildcard type, or theTypeSystem.NULL_TYPE
)- Specified by:
getErasure
in interfaceJTypeMirror
-
getComponentType
public JTypeMirror getComponentType()
Gets the component type of this array. This is the same type as the array, stripped of a single array dimensions, e.g. the component type ofint[][][]
isint[][]
.- Returns:
- The component type of this array type
- See Also:
getElementType()
-
getElementType
public JTypeMirror getElementType()
Gets the element type of this array. This is the same type as the array, stripped of all array dimensions, e.g. the element type ofint[][][]
isint
.- Returns:
- The element type of this array type
- See Also:
getComponentType()
-
streamMethods
public 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
-
streamDeclaredMethods
public Stream<JMethodSig> streamDeclaredMethods(Predicate<? super JMethodSymbol> prefilter)
Description copied from interface:JTypeMirror
LikestreamMethods
, but does not recurse into supertypes. Note that only class and array types declare methods themselves.See also note in
JTypeMirror.streamMethods(Predicate)
.- Specified by:
streamDeclaredMethods
in interfaceJTypeMirror
- See Also:
JTypeMirror.streamMethods(Predicate)
-
getConstructors
public List<JMethodSig> getConstructors()
Description copied from interface:JTypeMirror
Returns a list of all the declared constructors for this type. Abstract types like type variables and interfaces have no constructors.- Specified by:
getConstructors
in interfaceJTypeMirror
-
isRaw
public boolean isRaw()
Description copied from interface:JTypeMirror
Returns true if this is a raw type. This may be- A generic class or interface type for which no type arguments were provided
- An array type whose element type is raw
- A non-static member type of a raw type
https://docs.oracle.com/javase/specs/jls/se11/html/jls-4.html#jls-4.8
- Specified by:
isRaw
in interfaceJTypeMirror
- See Also:
JClassType.isRaw()
-
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
-
subst
public JArrayType 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
- Parameters:
subst
- Substitution function, eg aSubstitution
-
equals
public boolean equals(Object o)
Description copied from interface:JTypeMirror
Returns true if the object is a type equivalent to this one. A few kinds of types use reference identity, like captured type variables, or the null type. A few special types are represented by constants (seeTypeSystem
). Apart from those, types should always be compared using this method. orTypeOps.isSameType(JTypeMirror, JTypeMirror)
(which is null-safe).Note that types belonging to different type systems do not test equal. The type system object is global to the analysis though, so this should not ever happen in rules.
- Specified by:
equals
in interfaceJTypeMirror
- Overrides:
equals
in classObject
- Parameters:
o
-- Returns:
-
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
-
-