Package com.sun.codemodel
Class JMethod
java.lang.Object
com.sun.codemodel.JMethod
- All Implemented Interfaces:
JAnnotatable
,JDeclaration
,JDocCommentable
,JGenerifiable
Java method.
-
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<? extends Annotation>>
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 thisbody()
Get the block that makes up body of this methodvoid
void
declareDefaultValue
(JExpression value) Specify the default value for this annotation memberAdds a new type variable to this declaration.Adds a new type variable to this declaration with a bound.Adds a new type variable to this declaration with a bound.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.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.boolean
removeAnnotation
(JAnnotationUse annotation) Removes annotation from this program element.type()
Returns the return type.void
Overrides the return type.JTypeVar[]
Iterates all the type parameters of this class/interface.Add the specified variable argument to the list of parameters for this method signature.
-
Method Details
-
_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
-
removeAnnotation
Description copied from interface:JAnnotatable
Removes annotation from this program element.- Specified by:
removeAnnotation
in interfaceJAnnotatable
- Parameters:
annotation
- The annotation to be removed from the program element
-
annotations
Description copied from interface:JAnnotatable
Read-only live view of all annotations on this- 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
-
mods
- Returns:
- the current modifiers of this method. Always return non-null valid object.
-
owner
-
generify
Description copied from interface:JGenerifiable
Adds a new type variable to this declaration.- Specified by:
generify
in interfaceJGenerifiable
-
generify
Description copied from interface:JGenerifiable
Adds a new type variable to this declaration with a bound.- Specified by:
generify
in interfaceJGenerifiable
-
generify
Description copied from interface:JGenerifiable
Adds a new type variable to this declaration with a bound.- Specified by:
generify
in interfaceJGenerifiable
-
typeParams
Description copied from interface:JGenerifiable
Iterates all the type parameters of this class/interface.- Specified by:
typeParams
in interfaceJGenerifiable
-