Interface JMethodSig
-
- All Superinterfaces:
JTypeVisitable
public interface JMethodSig extends JTypeVisitable
Represents the signature of methods and constructors. An instance of this interface is aJMethodSymbol
viewed under a particular substitution.All the types returned by
getFormalParameters()
,getReturnType()
,getTypeParameters()
andgetThrownExceptions()
can mention type parameters of the method, of its declaring type and all its enclosing types.Typically the output of type inference is a method symbol whose type parameters have been given a specific instantiation. But If a signature is produced by type inference, it may not match its symbol exactly (ie, not just be a substitution applied to the symbol's type parameters), to account for special cases depending on context information. For example, the actual return type of a method whose applicability required an unchecked conversion is the erasure of the return type of the declaration.
-
-
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.JTypeMirror
getAnnotatedReceiverType()
Return the type ofthis
in the body of the method.default int
getArity()
Number of formal parameters.JTypeMirror
getDeclaringType()
Return the type that declares this method.JMethodSig
getErasure()
The erasure of a method is a new, non-generic method, whose parameters, owner, and return type, are erased.List<JTypeMirror>
getFormalParameters()
Return the types of the formal parameters.default int
getModifiers()
Return method modifiers as decodable byModifier
.default String
getName()
Return the name of the method.JTypeMirror
getReturnType()
Return the result type of the method.JExecutableSymbol
getSymbol()
Return the symbol of the method or constructor.List<JTypeMirror>
getThrownExceptions()
Return the list of thrown exception types.List<JTypeVar>
getTypeParameters()
Return the type parameters of the method.TypeSystem
getTypeSystem()
Return the type system with which this method was created.net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf
internalApi()
Internal API, should not be used outside of the type inference implementation.default boolean
isAbstract()
Return true if this method is abstract.default boolean
isConstructor()
Return whether this is a constructor.default boolean
isGeneric()
Return true if this method signature declares type parameters.default boolean
isStatic()
Return true if this method is static.default boolean
isVarargs()
Return true if this method has a varargs parameter.JMethodSig
subst(Function<? super SubstVar,? extends @NonNull JTypeMirror> subst)
Replace the type variables occurring in the given type by their image by the given function.
-
-
-
Method Detail
-
getTypeSystem
TypeSystem getTypeSystem()
Return the type system with which this method was created.
-
getSymbol
JExecutableSymbol getSymbol()
Return the symbol of the method or constructor.
-
getName
default String getName()
Return the name of the method. If this is a constructor, returnsJConstructorSymbol.CTOR_NAME
.
-
isConstructor
default boolean isConstructor()
Return whether this is a constructor.
-
getModifiers
default int getModifiers()
Return method modifiers as decodable byModifier
.
-
getDeclaringType
JTypeMirror getDeclaringType()
Return the type that declares this method. May be an array type, a class type. If this is a constructor for a generic class, returns the generic type declaration of the constructor.
-
getAnnotatedReceiverType
JTypeMirror getAnnotatedReceiverType()
Return the type ofthis
in the body of the method. This is the declaring type with
-
getReturnType
JTypeMirror getReturnType()
Return the result type of the method. If this is a constructor, returns the type of the instance produced by the constructor. In particular, for a diamond constructor call, returns the inferred type. For example forList<String> l = new ArrayList<>()
, returnsArrayList<String>
.
-
getErasure
JMethodSig getErasure()
The erasure of a method is a new, non-generic method, whose parameters, owner, and return type, are erased. For example:
erases to<N extends Number, U> U fun(N, Supplier<U>, U);
Object fun(Number, Supplier, Object);
-
getFormalParameters
List<JTypeMirror> getFormalParameters()
Return the types of the formal parameters. If this is a varargs method, the last parameter should have an array type. For generic methods that have been inferred, these are substituted with the inferred type parameters. For example forArrays.asList("a", "b")
, returns a singleton list containingString[]
.
-
getArity
default int getArity()
Number of formal parameters. A varargs parameter counts as one.
-
getTypeParameters
List<JTypeVar> getTypeParameters()
Return the type parameters of the method. After type inference, occurrences of these type parameters are replaced by their instantiation in formals, return type and thrown exceptions (but not type parameter bounds). If instantiation failed, some variables might have been substituted withTypeSystem.ERROR
.
-
getThrownExceptions
List<JTypeMirror> getThrownExceptions()
Return the list of thrown exception types. Exception types may be type variables of the method or of an enclosing context, that extend Throwable.
-
isAbstract
default boolean isAbstract()
Return true if this method is abstract.
-
isStatic
default boolean isStatic()
Return true if this method is static.
-
isVarargs
default boolean isVarargs()
Return true if this method has a varargs parameter.
-
isGeneric
default boolean isGeneric()
Return true if this method signature declares type parameters.
-
subst
JMethodSig 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 interfaceJTypeVisitable
- Parameters:
subst
- Substitution function, eg aSubstitution
-
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
-
internalApi
@InternalApi net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf internalApi()
Internal API, should not be used outside of the type inference implementation.
-
-