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
Fields Modifier and Type Field Description private java.util.Set<JClass>
_throws
Set of exceptions that this method may throw.private java.util.List<JAnnotationUse>
annotations
Annotations on this variable.private JBlock
body
JBlock of statements that makes up the body this methodprivate JExpression
defaultValue
To set the default value for the annotation memberprivate JDocComment
jdoc
javadoc comments for this JMethodprivate JMods
mods
Modifiers for this methodprivate java.lang.String
name
Name of this methodprivate JDefinedClass
outer
private java.util.List<JVar>
params
List of parameters for this method's declarationprivate JType
type
Return type for this methodprivate JVar
varParam
Variable parameter for this method's varargs declaration introduced in J2SE 1.5
-
Constructor Summary
Constructors Constructor Description JMethod(int mods, JDefinedClass _class)
Constructor constructorJMethod(JDefinedClass outer, int mods, JType type, java.lang.String name)
JMethod constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JMethod
_throws(JClass exception)
Add an exception to the list of exceptions that this method may throw.JMethod
_throws(java.lang.Class<? extends java.lang.Throwable> exception)
JAnnotationUse
annotate(JClass clazz)
Adds an annotation to this variable.JAnnotationUse
annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Adds an annotation to this variable.<W extends JAnnotationWriter>
Wannotate2(java.lang.Class<W> clazz)
Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.java.util.Collection<JAnnotationUse>
annotations()
Read-only live view of all annotations on thisJAnnotatable
JBlock
body()
Get the block that makes up body of this methodvoid
declare(JFormatter f)
void
declareDefaultValue(JExpression value)
Specify the default value for this annotation memberJMods
getMods()
Deprecated.usemods()
private java.util.Set<JClass>
getThrows()
boolean
hasSignature(JType[] argTypes)
Returns true if the method has the specified signature.boolean
hasVarArgs()
Check if there are any varargs declared for this method signature.private boolean
isConstructor()
JDocComment
javadoc()
Creates, if necessary, and returns the class javadoc for this JDefinedClassJVar[]
listParams()
Returns all the parameters in an array.JType[]
listParamTypes()
Returns all the parameter types in an array.JVar
listVarParam()
Returns the variable parameterJType
listVarParamType()
Returns the varags parameter type.JMods
mods()
java.lang.String
name()
void
name(java.lang.String n)
Changes the name of the method.protected JCodeModel
owner()
JVar
param(int mods, JType type, java.lang.String name)
Add the specified variable to the list of parameters for this method signature.JVar
param(int mods, java.lang.Class<?> type, java.lang.String name)
JVar
param(JType type, java.lang.String name)
JVar
param(java.lang.Class<?> type, java.lang.String name)
java.util.List<JVar>
params()
Returns the list of variable of this method.JType
type()
Returns the return type.void
type(JType t)
Overrides the return type.JVar
varParam(JType type, java.lang.String name)
Add the specified variable argument to the list of parameters for this method signature.JVar
varParam(java.lang.Class<?> type, java.lang.String name)
-
Methods inherited from class com.sun.codemodel.JGenerifiableImpl
generify, generify, generify, typeParams
-
-
-
-
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
-
outer
private JDefinedClass outer
-
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 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 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 addedname
- Name of the parameter being added- Returns:
- New parameter variable
-
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(java.lang.Class<?> type, java.lang.String name)
- See Also:
varParam(JType, String)
-
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 interfaceJAnnotatable
- 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 interfaceJAnnotatable
- 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 interfaceJAnnotatable
-
annotations
public java.util.Collection<JAnnotationUse> 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
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 interfaceJDocCommentable
- Returns:
- JDocComment containing javadocs for this class
-
declare
public void declare(JFormatter f)
- Specified by:
declare
in interfaceJDeclaration
- Overrides:
declare
in classJGenerifiableImpl
-
mods
public JMods mods()
- Returns:
- the current modifiers of this method. Always return non-null valid object.
-
owner
protected JCodeModel owner()
- Specified by:
owner
in classJGenerifiableImpl
-
-