Top Description Fields Constructors Methods
com.sun.codemodel

public Class JMethod

extends JGenerifiableImpl
implements JDeclaration, JAnnotatable, JDocCommentable
Class Inheritance
All Implemented Interfaces
com.sun.codemodel.JDocCommentable, com.sun.codemodel.JAnnotatable, com.sun.codemodel.JDeclaration
Imports
java.lang.annotation.Annotation, java.util.ArrayList, .List, .Set, .TreeSet, .Collections, .Collection, com.sun.codemodel.util.ClassNameComparator

Java method.

Field Summary

Modifier and TypeField and Description
private Set<JClass>
_throws

Set of exceptions that this method may throw.

private List<JAnnotationUse>
annotations

Annotations on this variable.

private JBlock
body

JBlock of statements that makes up the body this method

private JExpression
defaultValue

To set the default value for the annotation member

private JDocComment
jdoc

javadoc comments for this JMethod

private JMods
mods

Modifiers for this method

private String
name

Name of this method

private JDefinedClass
private final List<JVar>
params

List of parameters for this method's declaration

private JType
type

Return type for this method

private JVar
varParam

Variable parameter for this method's varargs declaration introduced in J2SE 1.5

Constructor Summary

AccessConstructor and Description
pack-priv
JMethod(JDefinedClass outer, int
Modifiers for this method's declaration
mods
,
JType
Return type for the method
type
,
String
Name of this method
name
)

JMethod constructor

pack-priv
JMethod(int
Modifiers for this constructor's declaration
mods
,
JDefinedClass
JClass containing this constructor
_class
)

Constructor constructor

Method Summary

Modifier and TypeMethod and Description
public JMethod
_throws(JClass
Name of an exception that this method may throw
exception
)

Add an exception to the list of exceptions that this method may throw.

public JMethod
_throws(Class<? extends Throwable> exception)

public JAnnotationUse
annotate(JClass
The annotation class to annotate the field with
clazz
)

Implements com.sun.codemodel.JAnnotatable.annotate.

Adds an annotation to this variable.

public JAnnotationUse
annotate(Class<? extends Annotation>
The annotation class to annotate the field with
clazz
)

Implements com.sun.codemodel.JAnnotatable.annotate.

Adds an annotation to this variable.

public <W extends JAnnotationWriter<? extends Annotation>> W
annotate2(Class<W> clazz)

Implements com.sun.codemodel.JAnnotatable.annotate2.

Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.

public Collection<JAnnotationUse>
annotations()

Implements com.sun.codemodel.JAnnotatable.annotations.

Read-only live view of all annotations on this

public JBlock

Returns:

Body of method
body
()

Get the block that makes up body of this method

public void
public void
declareDefaultValue(JExpression
Default value for the annotation member
value
)

Specify the default value for this annotation member

private Set<JClass>
public boolean
hasSignature(JType[] argTypes)

Returns true if the method has the specified signature.

public boolean
hasVarArgs()

Check if there are any varargs declared for this method signature.

private boolean
public JDocComment

Returns:

JDocComment containing javadocs for this class
javadoc
()

Implements com.sun.codemodel.JDocCommentable.javadoc.

Creates, if necessary, and returns the class javadoc for this JDefinedClass

public JVar[]

Returns:

If there's no parameter, an empty array will be returned.
listParams
()

Returns all the parameters in an array.

public JType[]

Returns:

If there's no parameter, an empty array will be returned.
listParamTypes
()

Returns all the parameter types in an array.

public JVar

Returns:

If there's no parameter, null will be returned.
listVarParam
()

Returns the variable parameter

public JType

Returns:

If there's no vararg parameter type, null will be returned.
listVarParamType
()

Returns the varags parameter type.

public JMods
mods()

Returns: the current modifiers of this method.

public String
name()

public void
name(String n)

Changes the name of the method.

protected JCodeModel
public JVar

Returns:

New parameter variable
param
(int mods, JType
JType of the parameter being added
type
,
String
Name of the parameter being added
name
)

Add the specified variable to the list of parameters for this method signature.

public JVar
param(JType type, String name)

public JVar
param(int mods, Class<?> type, String name)

public JVar
param(Class<?> type, String name)

public List<JVar>

Returns:

List of parameters of this method. This list is not modifiable.
params
()

Returns the list of variable of this method.

public boolean
removeAnnotation(JAnnotationUse annotation)

Implements com.sun.codemodel.JAnnotatable.removeAnnotation.

Removes annotation from this program element.

public JType
type()

Returns the return type.

public void
type(JType t)

Overrides the return type.

public JVar
varParam(Class<?> type, String name)

public JVar

Returns:

the variable parameter
varParam
(JType
Type of the parameter being added.
type
,
String
Name of the parameter being added
name
)

Add the specified variable argument to the list of parameters for this method signature.

Inherited from com.sun.codemodel.JGenerifiableImpl:
generifygenerifygenerifytypeParams

Field Detail

_throwsback to summary
private Set<JClass> _throws

Set of exceptions that this method may throw. A set instance lazily created.

annotationsback to summary
private List<JAnnotationUse> annotations

Annotations on this variable. Lazily created.

bodyback to summary
private JBlock body

JBlock of statements that makes up the body this method

defaultValueback to summary
private JExpression defaultValue

To set the default value for the annotation member

jdocback to summary
private JDocComment jdoc

javadoc comments for this JMethod

modsback to summary
private JMods mods

Modifiers for this method

nameback to summary
private String name

Name of this method

outerback to summary
private JDefinedClass outer
paramsback to summary
private final List<JVar> params

List of parameters for this method's declaration

typeback to summary
private JType type

Return type for this method

varParamback to summary
private JVar varParam

Variable parameter for this method's varargs declaration introduced in J2SE 1.5

Constructor Detail

JMethodback to summary
pack-priv JMethod(JDefinedClass outer, int mods, JType type, String name)

JMethod constructor

Parameters
mods:int

Modifiers for this method's declaration

type:JType

Return type for the method

name:String

Name of this method

JMethodback to summary
pack-priv JMethod(int mods, JDefinedClass _class)

Constructor constructor

Parameters
mods:int

Modifiers for this constructor's declaration

_class:JDefinedClass

JClass containing this constructor

Method Detail

_throwsback to summary
public JMethod _throws(JClass exception)

Add an exception to the list of exceptions that this method may throw.

Parameters
exception:JClass

Name of an exception that this method may throw

_throwsback to summary
public JMethod _throws(Class<? extends Throwable> exception)
annotateback to summary
public JAnnotationUse annotate(JClass clazz)

Implements com.sun.codemodel.JAnnotatable.annotate.

Adds an annotation to this variable.

Parameters
clazz:JClass

The annotation class to annotate the field with

Annotations
@Override
annotateback to summary
public JAnnotationUse annotate(Class<? extends Annotation> clazz)

Implements com.sun.codemodel.JAnnotatable.annotate.

Adds an annotation to this variable.

Parameters
clazz:Class<? extends Annotation>

The annotation class to annotate the field with

Annotations
@Override
annotate2back to summary
public <W extends JAnnotationWriter<? extends Annotation>> W annotate2(Class<W> clazz)

Implements com.sun.codemodel.JAnnotatable.annotate2.

Doc from com.sun.codemodel.JAnnotatable.annotate2.

Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.

Annotations
@Override
annotationsback to summary
public Collection<JAnnotationUse> annotations()

Implements com.sun.codemodel.JAnnotatable.annotations.

Doc from com.sun.codemodel.JAnnotatable.annotations.

Read-only live view of all annotations on this

Annotations
@Override
bodyback to summary
public JBlock body()

Get the block that makes up body of this method

Returns:JBlock

Body of method

declareback to summary
public void declare(JFormatter f)

Overrides com.sun.codemodel.JGenerifiableImpl.declare.

Implements com.sun.codemodel.JDeclaration.declare.

Annotations
@Override
declareDefaultValueback to summary
public void declareDefaultValue(JExpression value)

Specify the default value for this annotation member

Parameters
value:JExpression

Default value for the annotation member

getThrowsback to summary
private Set<JClass> getThrows()
hasSignatureback to summary
public boolean hasSignature(JType[] argTypes)

Returns true if the method has the specified signature.

hasVarArgsback to summary
public boolean hasVarArgs()

Check if there are any varargs declared for this method signature.

isConstructorback to summary
private boolean isConstructor()
javadocback to summary
public JDocComment javadoc()

Implements com.sun.codemodel.JDocCommentable.javadoc.

Creates, if necessary, and returns the class javadoc for this JDefinedClass

Returns:JDocComment

JDocComment containing javadocs for this class

Annotations
@Override
listParamsback to summary
public JVar[] listParams()

Returns all the parameters in an array.

Returns:JVar[]

If there's no parameter, an empty array will be returned.

listParamTypesback to summary
public JType[] listParamTypes()

Returns all the parameter types in an array.

Returns:JType[]

If there's no parameter, an empty array will be returned.

listVarParamback to summary
public JVar listVarParam()

Returns the variable parameter

Returns:JVar

If there's no parameter, null will be returned.

listVarParamTypeback to summary
public JType listVarParamType()

Returns the varags parameter type.

Returns:JType

If there's no vararg parameter type, null will be returned.

modsback to summary
public JMods mods()
Returns:JMods

the current modifiers of this method. Always return non-null valid object.

nameback to summary
public String name()
nameback to summary
public void name(String n)

Changes the name of the method.

ownerback to summary
protected JCodeModel owner()

Implements abstract com.sun.codemodel.JGenerifiableImpl.owner.

Annotations
@Override
paramback to summary
public JVar param(int mods, JType type, String name)

Add the specified variable to the list of parameters for this method signature.

Parameters
type:JType

JType of the parameter being added

name:String

Name of the parameter being added

Returns:JVar

New parameter variable

paramback to summary
public JVar param(JType type, String name)
paramback to summary
public JVar param(int mods, Class<?> type, String name)
paramback to summary
public JVar param(Class<?> type, String name)
paramsback to summary
public List<JVar> params()

Returns the list of variable of this method.

Returns:List<JVar>

List of parameters of this method. This list is not modifiable.

removeAnnotationback to summary
public boolean removeAnnotation(JAnnotationUse annotation)

Implements com.sun.codemodel.JAnnotatable.removeAnnotation.

Doc from com.sun.codemodel.JAnnotatable.removeAnnotation.

Removes annotation from this program element.

Annotations
@Override
typeback to summary
public JType type()

Returns the return type.

typeback to summary
public void type(JType t)

Overrides the return type.

varParamback to summary
public JVar varParam(Class<?> type, String name)
See Also
varParam(JType, String)
varParamback to summary
public JVar varParam(JType type, String name)

Add the specified variable argument to the list of parameters for this method signature.

Parameters
type:JType

Type of the parameter being added.

name:String

Name of the parameter being added

Returns:JVar

the variable parameter

Exceptions
IllegalStateException:
If this method is called twice. varargs in J2SE 1.5 can appear only once in the method signature.