Interface JMethodSig
-
- All Superinterfaces:
JTypeVisitable
public interface JMethodSig extends JTypeVisitable
Represents the signature of methods and constructors. An instance of this interface is aJMethodSymbolviewed 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.JTypeMirrorgetAnnotatedReceiverType()Return the type ofthisin the body of the method.default intgetArity()Number of formal parameters.JTypeMirrorgetDeclaringType()Return the type that declares this method.JMethodSiggetErasure()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 intgetModifiers()Return method modifiers as decodable byModifier.default StringgetName()Return the name of the method.JTypeMirrorgetReturnType()Return the result type of the method.JExecutableSymbolgetSymbol()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.TypeSystemgetTypeSystem()Return the type system with which this method was created.default booleanisAbstract()Return true if this method is abstract.default booleanisConstructor()Return whether this is a constructor.default booleanisGeneric()Return true if this method signature declares type parameters.default booleanisStatic()Return true if this method is static.default booleanisVarargs()Return true if this method has a varargs parameter.default JTypeMirrorithFormalParam(int i, boolean varargs)Returns the type of the i-th formal parameter of the method.JMethodSigsubst(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 ofthisin 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.
-
ithFormalParam
default JTypeMirror ithFormalParam(int i, boolean varargs)
Returns the type of the i-th formal parameter of the method. This is relevant when the call is varargs:ican 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
JMethodSig subst(Function<? super SubstVar,? extends @NonNull JTypeMirror> subst)
Description copied from interface:JTypeVisitableReplace 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:
substin interfaceJTypeVisitable- Parameters:
subst- Substitution function, eg aSubstitution
-
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
-
-