Interface JMethodSig
- All Superinterfaces:
JTypeVisitable
Represents the signature of methods and constructors. An instance of
this interface is a
JMethodSymbol
viewed under a particular
substitution.
All the types returned by getFormalParameters()
,
getReturnType()
, getTypeParameters()
and
getThrownExceptions()
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
Modifier and TypeMethodDescriptiondefault <T,
P> T acceptVisitor
(JTypeVisitor<T, P> visitor, P p) Accept a type visitor, dispatching on this object's runtime type to the correct method of the visitor.Return the type ofthis
in the body of the method.default int
getArity()
Number of formal parameters.Return the type that declares this method.The erasure of a method is a new, non-generic method, whose parameters, owner, and return type, are erased.Return the types of the formal parameters.default int
Return method modifiers as decodable byModifier
.default String
getName()
Return the name of the method.Return the result type of the method.Return the symbol of the method or constructor.Return the list of thrown exception types.Return the type parameters of the method.Return the type system with which this method was created.default boolean
Return true if this method is abstract.default boolean
Return whether this is a constructor.default boolean
Return true if this method signature declares type parameters.default boolean
isStatic()
Return true if this method is static.default boolean
Return true if this method has a varargs parameter.default JTypeMirror
ithFormalParam
(int i, boolean varargs) Returns the type of the i-th formal parameter of the method.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 Details
-
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
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
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. -
ithFormalParam
Returns the type of the i-th formal parameter of the method. This is relevant when the call is varargs:i
can in that case be greater that the number of formal parameters.- Parameters:
i
- Index for a formalvarargs
- Whether this is a varags call- Throws:
AssertionError
- If the parameter is negative, or greater than the number of argument expressions to the method
-
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
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
-