Class JMethod

    • Method Detail

      • _throws

        public JMethod _throws​(JClass exception)
        Add an exception to the list of exceptions that this method may throw.
        Parameters:
        exception - Name of an exception that this method may throw
      • params

        public List<JVar> params()
        Returns the list of variable of this method.
        Returns:
        List of parameters of this method. This list is not modifiable.
      • param

        public JVar param​(int mods,
                          JType type,
                          String name)
        Add the specified variable to the list of parameters for this method signature.
        Parameters:
        type - JType of the parameter being added
        name - Name of the parameter being added
        Returns:
        New parameter variable
      • varParam

        public JVar varParam​(JType type,
                             String name)
        Add the specified variable argument to the list of parameters for this method signature.
        Parameters:
        type - Type of the parameter being added.
        name - Name of the parameter being added
        Returns:
        the variable parameter
        Throws:
        IllegalStateException - If this method is called twice. varargs in J2SE 1.5 can appear only once in the method signature.
      • annotate

        public JAnnotationUse annotate​(JClass clazz)
        Adds an annotation to this variable.
        Specified by:
        annotate in interface JAnnotatable
        Parameters:
        clazz - The annotation class to annotate the field with
      • annotate2

        public <W extends JAnnotationWriter<? extends Annotation>> W annotate2​(Class<W> clazz)
        Description copied from interface: JAnnotatable
        Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.
        Specified by:
        annotate2 in interface JAnnotatable
        Returns:
      • removeAnnotation

        public boolean removeAnnotation​(JAnnotationUse annotation)
        Description copied from interface: JAnnotatable
        Removes annotation from this program element.
        Specified by:
        removeAnnotation in interface JAnnotatable
        Parameters:
        annotation - The annotation to be removed from the program element
      • hasVarArgs

        public boolean hasVarArgs()
        Check if there are any varargs declared for this method signature.
      • name

        public void name​(String n)
        Changes the name of the method.
      • type

        public JType type()
        Returns the return type.
      • type

        public void type​(JType t)
        Overrides the return type.
      • listParamTypes

        public JType[] listParamTypes()
        Returns all the parameter types in an array.
        Returns:
        If there's no parameter, an empty array will be returned.
      • listVarParamType

        public JType listVarParamType()
        Returns the varags parameter type.
        Returns:
        If there's no vararg parameter type, null will be returned.
      • listParams

        public JVar[] listParams()
        Returns all the parameters in an array.
        Returns:
        If there's no parameter, an empty array will be returned.
      • listVarParam

        public JVar listVarParam()
        Returns the variable parameter
        Returns:
        If there's no parameter, null will be returned.
      • hasSignature

        public boolean hasSignature​(JType[] argTypes)
        Returns true if the method has the specified signature.
      • body

        public JBlock body()
        Get the block that makes up body of this method
        Returns:
        Body of method
      • declareDefaultValue

        public void declareDefaultValue​(JExpression value)
        Specify the default value for this annotation member
        Parameters:
        value - Default value for the annotation member
      • javadoc

        public JDocComment javadoc()
        Creates, if necessary, and returns the class javadoc for this JDefinedClass
        Specified by:
        javadoc in interface JDocCommentable
        Returns:
        JDocComment containing javadocs for this class
      • mods

        public JMods mods()
        Returns:
        the current modifiers of this method. Always return non-null valid object.