Interface JMethodSig

  • All Superinterfaces:
    JTypeVisitable

    public interface JMethodSig
    extends 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 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.
      • isConstructor

        default boolean isConstructor()
        Return whether this is a constructor.
      • getModifiers

        default int getModifiers()
        Return method modifiers as decodable by Modifier.
      • 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 of this 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 for List<String> l = new ArrayList<>(), returns ArrayList<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:
        
             <N extends Number, U> U fun(N, Supplier<U>, U);
         
        erases to
             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 for Arrays.asList("a", "b"), returns a singleton list containing String[].
      • 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 with TypeSystem.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 interface JTypeVisitable
        Parameters:
        subst - Substitution function, eg a Substitution
      • 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 interface JTypeVisitable
        Type Parameters:
        T - Type of result of the visitor
        P - 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.