Class JMethod

    • Field Detail

      • mods

        private JMods mods
        Modifiers for this method
      • type

        private JType type
        Return type for this method
      • name

        private java.lang.String name
        Name of this method
      • params

        private final java.util.List<JVar> params
        List of parameters for this method's declaration
      • _throws

        private java.util.Set<JClass> _throws
        Set of exceptions that this method may throw. A set instance lazily created.
      • body

        private JBlock body
        JBlock of statements that makes up the body this method
      • jdoc

        private JDocComment jdoc
        javadoc comments for this JMethod
      • varParam

        private JVar varParam
        Variable parameter for this method's varargs declaration introduced in J2SE 1.5
      • annotations

        private java.util.List<JAnnotationUse> annotations
        Annotations on this variable. Lazily created.
      • defaultValue

        private JExpression defaultValue
        To set the default value for the annotation member
    • Constructor Detail

      • JMethod

        JMethod​(JDefinedClass outer,
                int mods,
                JType type,
                java.lang.String name)
        JMethod constructor
        Parameters:
        mods - Modifiers for this method's declaration
        type - Return type for the method
        name - Name of this method
      • JMethod

        JMethod​(int mods,
                JDefinedClass _class)
        Constructor constructor
        Parameters:
        mods - Modifiers for this constructor's declaration
        _class - JClass containing this constructor
    • Method Detail

      • isConstructor

        private boolean isConstructor()
      • getThrows

        private java.util.Set<JClass> getThrows()
      • _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
      • _throws

        public JMethod _throws​(java.lang.Class<? extends java.lang.Throwable> exception)
      • params

        public java.util.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,
                          java.lang.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
      • param

        public JVar param​(JType type,
                          java.lang.String name)
      • param

        public JVar param​(int mods,
                          java.lang.Class<?> type,
                          java.lang.String name)
      • param

        public JVar param​(java.lang.Class<?> type,
                          java.lang.String name)
      • varParam

        public JVar varParam​(JType type,
                             java.lang.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:
        java.lang.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
      • annotate

        public JAnnotationUse annotate​(java.lang.Class<? extends java.lang.annotation.Annotation> 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> W annotate2​(java.lang.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
      • hasVarArgs

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

        public java.lang.String name()
      • name

        public void name​(java.lang.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.
      • getMods

        public JMods getMods()
        Deprecated.
        use mods()