Package com.sun.codemodel
Class JMethod
java.lang.Object
com.sun.codemodel.JGenerifiableImpl
com.sun.codemodel.JMethod
- All Implemented Interfaces:
JAnnotatable
,JDeclaration
,JDocCommentable
,JGenerifiable
public class JMethod
extends JGenerifiableImpl
implements JDeclaration, JAnnotatable, JDocCommentable
Java method.
-
Field Summary
FieldsModifier and TypeFieldDescriptionSet of exceptions that this method may throw.private List
<JAnnotationUse> Annotations on this variable.private JBlock
JBlock of statements that makes up the body this methodprivate JExpression
To set the default value for the annotation memberprivate JDocComment
javadoc comments for this JMethodprivate JMods
Modifiers for this methodprivate String
Name of this methodprivate JDefinedClass
List of parameters for this method's declarationprivate JType
Return type for this methodprivate JVar
Variable parameter for this method's varargs declaration introduced in J2SE 1.5 -
Constructor Summary
ConstructorsConstructorDescriptionJMethod
(int mods, JDefinedClass _class) Constructor constructorJMethod
(JDefinedClass outer, int mods, JType type, String name) JMethod constructor -
Method Summary
Modifier and TypeMethodDescriptionAdd an exception to the list of exceptions that this method may throw.Adds an annotation to this variable.annotate
(Class<? extends Annotation> clazz) Adds an annotation to this variable.<W extends JAnnotationWriter>
WAdds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.Read-only live view of all annotations on thisJAnnotatable
body()
Get the block that makes up body of this methodvoid
void
declareDefaultValue
(JExpression value) Specify the default value for this annotation membergetMods()
Deprecated.boolean
hasSignature
(JType[] argTypes) Returns true if the method has the specified signature.boolean
Check if there are any varargs declared for this method signature.private boolean
javadoc()
Creates, if necessary, and returns the class javadoc for this JDefinedClassJVar[]
Returns all the parameters in an array.JType[]
Returns all the parameter types in an array.Returns the variable parameterReturns the varags parameter type.mods()
name()
void
Changes the name of the method.protected JCodeModel
owner()
Add the specified variable to the list of parameters for this method signature.params()
Returns the list of variable of this method.type()
Returns the return type.void
Overrides the return type.Add the specified variable argument to the list of parameters for this method signature.Methods inherited from class com.sun.codemodel.JGenerifiableImpl
generify, generify, generify, typeParams
-
Field Details
-
mods
Modifiers for this method -
type
Return type for this method -
name
Name of this method -
params
List of parameters for this method's declaration -
_throws
Set of exceptions that this method may throw. A set instance lazily created. -
body
JBlock of statements that makes up the body this method -
outer
-
jdoc
javadoc comments for this JMethod -
varParam
Variable parameter for this method's varargs declaration introduced in J2SE 1.5 -
annotations
Annotations on this variable. Lazily created. -
defaultValue
To set the default value for the annotation member
-
-
Constructor Details
-
JMethod
JMethod(JDefinedClass outer, int mods, JType type, String name) JMethod constructor- Parameters:
mods
- Modifiers for this method's declarationtype
- Return type for the methodname
- 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 Details
-
isConstructor
private boolean isConstructor() -
getThrows
-
_throws
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
-
params
Returns the list of variable of this method.- Returns:
- List of parameters of this method. This list is not modifiable.
-
param
Add the specified variable to the list of parameters for this method signature.- Parameters:
type
- JType of the parameter being addedname
- Name of the parameter being added- Returns:
- New parameter variable
-
param
-
param
-
param
-
varParam
- See Also:
-
varParam
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
Adds an annotation to this variable.- Specified by:
annotate
in interfaceJAnnotatable
- Parameters:
clazz
- The annotation class to annotate the field with
-
annotate
Adds an annotation to this variable.- Specified by:
annotate
in interfaceJAnnotatable
- Parameters:
clazz
- The annotation class to annotate the field with
-
annotate2
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 interfaceJAnnotatable
-
annotations
Description copied from interface:JAnnotatable
Read-only live view of all annotations on thisJAnnotatable
- Specified by:
annotations
in interfaceJAnnotatable
- Returns:
- Can be empty but never null.
-
hasVarArgs
public boolean hasVarArgs()Check if there are any varargs declared for this method signature. -
name
-
name
Changes the name of the method. -
type
Returns the return type. -
type
Overrides the return type. -
listParamTypes
Returns all the parameter types in an array.- Returns:
- If there's no parameter, an empty array will be returned.
-
listVarParamType
Returns the varags parameter type.- Returns:
- If there's no vararg parameter type, null will be returned.
-
listParams
Returns all the parameters in an array.- Returns:
- If there's no parameter, an empty array will be returned.
-
listVarParam
Returns the variable parameter- Returns:
- If there's no parameter, null will be returned.
-
hasSignature
Returns true if the method has the specified signature. -
body
Get the block that makes up body of this method- Returns:
- Body of method
-
declareDefaultValue
Specify the default value for this annotation member- Parameters:
value
- Default value for the annotation member
-
javadoc
Creates, if necessary, and returns the class javadoc for this JDefinedClass- Specified by:
javadoc
in interfaceJDocCommentable
- Returns:
- JDocComment containing javadocs for this class
-
declare
- Specified by:
declare
in interfaceJDeclaration
- Overrides:
declare
in classJGenerifiableImpl
-
mods
- Returns:
- the current modifiers of this method. Always return non-null valid object.
-
getMods
Deprecated.usemods()
-
owner
- Specified by:
owner
in classJGenerifiableImpl
-
mods()