com.sun.codemodel
Class JMethod

java.lang.Object
  extended by com.sun.codemodel.JMethod
All Implemented Interfaces:
JAnnotatable, JDeclaration, JGenerifiable

public class JMethod
extends java.lang.Object
implements JDeclaration, JAnnotatable

Java method.


Method Summary
 JMethod _throws(java.lang.Class exception)
           
 JMethod _throws(JClass exception)
          Add an exception to the list of exceptions that this method may throw.
 JAnnotationUse annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
          Adds an annotation to this variable.
 JAnnotationUse annotate(JClass clazz)
          Adds an annotation to this variable.
<W extends JAnnotationWriter>
W
annotate2(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.
 JBlock body()
          Get the block that makes up body of this method
 void declare(JFormatter f)
           
 void declareDefaultValue(JExpression value)
          Specify the default value for this annotation member
 JTypeVar generify(java.lang.String name)
          Adds a new type variable to this declaration.
 JTypeVar generify(java.lang.String name, java.lang.Class bound)
          Adds a new type variable to this declaration with a bound.
 JTypeVar generify(java.lang.String name, JClass bound)
          Adds a new type variable to this declaration with a bound.
 JMods getMods()
          Deprecated. use mods()
 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.
 JDocComment javadoc()
          Creates, if necessary, and returns the class javadoc for this JDefinedClass
 JVar[] listParams()
          Returns all the parameters in an array.
 JType[] listParamTypes()
          Returns all the parameter types in an array.
 JVar listVarParam()
          Returns the variable parameter
 JType 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(java.lang.Class type, java.lang.String name)
           
 JVar param(int mods, java.lang.Class type, java.lang.String name)
           
 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(JType type, java.lang.String name)
           
 JType type()
          Returns the return type.
 void type(JType t)
          Overrides the return type.
 JTypeVar[] typeParams()
          Iterates all the type parameters of this class/interface.
 JVar varParam(java.lang.Class type, java.lang.String name)
           
 JVar varParam(JType type, java.lang.String name)
          Add the specified variable argument to the list of parameters for this method signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 exception)

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 added
name - Name of the parameter being added
Returns:
New parameter variable

param

public JVar param(JType type,
                  java.lang.String name)

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 interface JAnnotatable
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 interface JAnnotatable
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 interface JAnnotatable

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

Returns:
JDocComment containing javadocs for this class

declare

public void declare(JFormatter f)
Specified by:
declare in interface JDeclaration

mods

public JMods mods()
Returns:
the current modifiers of this method. Always return non-null valid object.

getMods

public JMods getMods()
Deprecated. use mods()


owner

protected JCodeModel owner()

generify

public JTypeVar generify(java.lang.String name)
Description copied from interface: JGenerifiable
Adds a new type variable to this declaration.

Specified by:
generify in interface JGenerifiable

generify

public JTypeVar generify(java.lang.String name,
                         java.lang.Class bound)
Description copied from interface: JGenerifiable
Adds a new type variable to this declaration with a bound.

Specified by:
generify in interface JGenerifiable

generify

public JTypeVar generify(java.lang.String name,
                         JClass bound)
Description copied from interface: JGenerifiable
Adds a new type variable to this declaration with a bound.

Specified by:
generify in interface JGenerifiable

typeParams

public JTypeVar[] typeParams()
Description copied from interface: JGenerifiable
Iterates all the type parameters of this class/interface.

Specified by:
typeParams in interface JGenerifiable


Copyright © 2005-2011 Sun Microsystems. All Rights Reserved.