- java.lang.Object
-
- com.sun.codemodel.JMethod
-
- All Implemented Interfaces:
JAnnotatable,JDeclaration,JDocCommentable,JGenerifiable
public class JMethod extends java.lang.Object implements JDeclaration, JAnnotatable, JDocCommentable
Java method.
-
-
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)JAnnotationUseannotate(JClass clazz)Adds an annotation to this variable.JAnnotationUseannotate(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 thisJAnnotatableJBlockbody()Get the block that makes up body of this methodvoiddeclare(JFormatter f)voiddeclareDefaultValue(JExpression value)Specify the default value for this annotation memberJTypeVargenerify(java.lang.String name)Adds a new type variable to this declaration.JTypeVargenerify(java.lang.String name, JClass bound)Adds a new type variable to this declaration with a bound.JTypeVargenerify(java.lang.String name, java.lang.Class<?> bound)Adds a new type variable to this declaration with a bound.JModsgetMods()Deprecated.usemods()booleanhasSignature(JType[] argTypes)Returns true if the method has the specified signature.booleanhasVarArgs()Check if there are any varargs declared for this method signature.JDocCommentjavadoc()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.JVarlistVarParam()Returns the variable parameterJTypelistVarParamType()Returns the varags parameter type.JModsmods()java.lang.Stringname()voidname(java.lang.String n)Changes the name of the method.protected JCodeModelowner()JVarparam(int mods, JType type, java.lang.String name)Add the specified variable to the list of parameters for this method signature.JVarparam(int mods, java.lang.Class<?> type, java.lang.String name)JVarparam(JType type, java.lang.String name)JVarparam(java.lang.Class<?> type, java.lang.String name)java.util.List<JVar>params()Returns the list of variable of this method.booleanremoveAnnotation(JAnnotationUse annotation)Removes annotation from this program element.JTypetype()Returns the return type.voidtype(JType t)Overrides the return type.JTypeVar[]typeParams()Iterates all the type parameters of this class/interface.JVarvarParam(JType type, java.lang.String name)Add the specified variable argument to the list of parameters for this method signature.JVarvarParam(java.lang.Class<?> type, java.lang.String name)
-
-
-
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
-
_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:
annotatein 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:
annotatein 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:JAnnotatableAdds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.- Specified by:
annotate2in interfaceJAnnotatable
-
removeAnnotation
public boolean removeAnnotation(JAnnotationUse annotation)
Description copied from interface:JAnnotatableRemoves annotation from this program element.- Specified by:
removeAnnotationin interfaceJAnnotatable- Parameters:
annotation- The annotation to be removed from the program element
-
annotations
public java.util.Collection<JAnnotationUse> annotations()
Description copied from interface:JAnnotatableRead-only live view of all annotations on thisJAnnotatable- Specified by:
annotationsin 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:
javadocin interfaceJDocCommentable- Returns:
- JDocComment containing javadocs for this class
-
declare
public void declare(JFormatter f)
- Specified by:
declarein interfaceJDeclaration
-
mods
public JMods mods()
- Returns:
- the current modifiers of this method. Always return non-null valid object.
-
owner
protected JCodeModel owner()
-
generify
public JTypeVar generify(java.lang.String name)
Description copied from interface:JGenerifiableAdds a new type variable to this declaration.- Specified by:
generifyin interfaceJGenerifiable
-
generify
public JTypeVar generify(java.lang.String name, java.lang.Class<?> bound)
Description copied from interface:JGenerifiableAdds a new type variable to this declaration with a bound.- Specified by:
generifyin interfaceJGenerifiable
-
generify
public JTypeVar generify(java.lang.String name, JClass bound)
Description copied from interface:JGenerifiableAdds a new type variable to this declaration with a bound.- Specified by:
generifyin interfaceJGenerifiable
-
typeParams
public JTypeVar[] typeParams()
Description copied from interface:JGenerifiableIterates all the type parameters of this class/interface.- Specified by:
typeParamsin interfaceJGenerifiable
-
-