org.exolab.javasource
Class JMethod

java.lang.Object
  extended by org.exolab.javasource.JMethod
All Implemented Interfaces:
JAnnotatedElement, JMember

public class JMethod
extends java.lang.Object
implements JMember, JAnnotatedElement

A class which holds information about the methods of a JClass. Modelled closely after the Java Reflection API. This class is part of package which is used to create source code.

Version:
$Revision: 1.4 $ $Date: 2004/12/03 18:47:32 $
Author:
Keith Visco

Constructor Summary
JMethod(JType returnType, java.lang.String name)
          Creates a new JMethod with the given name and returnType.
JMethod(java.lang.String name)
          Creates a new JMethod with the given name and "void" return type.
 
Method Summary
 void addAnnotation(JAnnotation annotation)
          Adds a JAnnotation to this source element.
protected  void addDeclaringClass(JClass jClass)
          Adds the given JClass to the set of classes that contain this method.
 void addException(JClass exp)
          Adds the given Exception to this Method's throws clause.
 void addParameter(JParameter parameter)
          Adds the given parameter to this JMethod's list of parameters.
 JAnnotation getAnnotation(JAnnotationType annotationType)
          Retrieves a JAnnotation for the given JAnnotationType, returns null if no annotation has been set.
 JAnnotation[] getAnnotations()
          Returns a list of JAnnotation's already set on this source element
 JClass[] getExceptions()
          Returns the exceptions that this JMember throws.
 JDocComment getJDocComment()
          Returns the JDocComment describing this member.
 JModifiers getModifiers()
          Returns the modifiers for this JMember.
 java.lang.String getName()
          Returns the name of this JMember.
 JParameter getParameter(int index)
          Returns the JParameter at the given index.
protected  java.lang.String[] getParameterClassNames()
           
 JParameter[] getParameters()
          Returns the set of JParameters for this JMethod.
 JType getReturnType()
          Returns the JType that represents the return type of the method.
 JMethodSignature getSignature()
          Returns the JMethodSignature for this JMethod.
 JSourceCode getSourceCode()
          Returns the JSourceCode for the method body.
 boolean hasAnnotations()
          Returns true if annotations have been added to this source element
 boolean isAnnotationPresent(JAnnotationType annotationType)
          Returns true if a JAnnotation exists for the given JAnnotationType
 void print(JSourceWriter jsw)
          Prints this JMethod to the given JSourceWriter.
 JAnnotation removeAnnotation(JAnnotationType annotationType)
          Removes the JAnnotation from this source element for the given JAnnotationType, throws a IllegalArgumentException if no JAnnotation has been added.
protected  void removeDeclaringClass(JClass jClass)
          Removes the given JClass from the set of classes that contain this method.
 void setComment(java.lang.String comment)
          Sets the comment describing this member.
 void setModifiers(JModifiers modifiers)
          Sets the JModifiers for this JMethod.
 void setName(java.lang.String name)
          Sets the name of this JMember.
 void setSourceCode(JSourceCode source)
          Sets the given JSourceCode as the source code (method body) for this JMethod.
 void setSourceCode(java.lang.String source)
          Sets the given string as the source code (method body) for this JMethod.
 java.lang.String toString()
          Returns the String representation of this JMethod, which is the method prototype.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JMethod

public JMethod(java.lang.String name)
Creates a new JMethod with the given name and "void" return type.

Parameters:
name, - the method name. Must not be null.

JMethod

public JMethod(JType returnType,
               java.lang.String name)
Creates a new JMethod with the given name and returnType. For "void" return types, simply pass in null as the returnType.

Parameters:
name, - the method name. Must not be null.
returnType - the return type of the method. May be null.
Method Detail

addException

public void addException(JClass exp)
Adds the given Exception to this Method's throws clause.

Parameters:
exp - the JClass representing the Exception

addParameter

public void addParameter(JParameter parameter)
                  throws java.lang.IllegalArgumentException
Adds the given parameter to this JMethod's list of parameters.

Parameters:
parameter - the parameter to add to the this Methods list of parameters.
Throws:
java.lang.IllegalArgumentException - when a parameter already exists for this Method with the same name as the new parameter

getJDocComment

public JDocComment getJDocComment()
Returns the JDocComment describing this member.

Returns:
the JDocComment describing this member.

getExceptions

public JClass[] getExceptions()
Returns the exceptions that this JMember throws.

Returns:
the exceptions that this JMember throws.

getModifiers

public JModifiers getModifiers()
Returns the modifiers for this JMember.

Specified by:
getModifiers in interface JMember
Returns:
the modifiers for this JMember.

getName

public java.lang.String getName()
Returns the name of this JMember.

Specified by:
getName in interface JMember
Returns:
the name of this JMember.

getParameter

public JParameter getParameter(int index)
Returns the JParameter at the given index.

Parameters:
index - the index of the JParameter to return.
Returns:
the JParameter at the given index.

getParameters

public JParameter[] getParameters()
Returns the set of JParameters for this JMethod.
Note: the array is a copy, the params in the array are the actual references.

Returns:
the set of JParameters for this JMethod

getReturnType

public JType getReturnType()
Returns the JType that represents the return type of the method.

Returns:
the JType that represents the return type of the method.

getSignature

public JMethodSignature getSignature()
Returns the JMethodSignature for this JMethod.

Returns:
the JMethodSignature for this JMethod.

getSourceCode

public JSourceCode getSourceCode()
Returns the JSourceCode for the method body.

Returns:
the JSourceCode for the method body.

setName

public void setName(java.lang.String name)
Sets the name of this JMember.

Parameters:
name - the name of this method

setComment

public void setComment(java.lang.String comment)
Sets the comment describing this member. The comment will be printed when this member is printed with the Class Printer.

Parameters:
comment - the comment for this member
See Also:
getJDocComment()

setModifiers

public void setModifiers(JModifiers modifiers)
Sets the JModifiers for this JMethod. This JMethod will use only a copy of the JModifiers. Note: The JModifiers will be set in the containing JMethodSignature. If the JMethodSignature is used by other methods, keep in mind that it will be changed.

Parameters:
modifiers - the JModifiers to set.

setSourceCode

public void setSourceCode(java.lang.String source)
Sets the given string as the source code (method body) for this JMethod.

Parameters:
source - the String that represents the method body.

setSourceCode

public void setSourceCode(JSourceCode source)
Sets the given JSourceCode as the source code (method body) for this JMethod.

Parameters:
source - the JSourceCode that represents the method body.

print

public void print(JSourceWriter jsw)
Prints this JMethod to the given JSourceWriter.

Parameters:
jsw - the JSourceWriter to print to.

toString

public java.lang.String toString()
Returns the String representation of this JMethod, which is the method prototype.

Overrides:
toString in class java.lang.Object
Returns:
the String representation of this JMethod, which is simply the method prototype

getAnnotation

public JAnnotation getAnnotation(JAnnotationType annotationType)
Description copied from interface: JAnnotatedElement
Retrieves a JAnnotation for the given JAnnotationType, returns null if no annotation has been set.

Specified by:
getAnnotation in interface JAnnotatedElement
Returns:
A JAnnotation for the given JAnnotationType

getAnnotations

public JAnnotation[] getAnnotations()
Description copied from interface: JAnnotatedElement
Returns a list of JAnnotation's already set on this source element

Specified by:
getAnnotations in interface JAnnotatedElement
Returns:
A list of all JAnnotations associated with this source element

isAnnotationPresent

public boolean isAnnotationPresent(JAnnotationType annotationType)
Description copied from interface: JAnnotatedElement
Returns true if a JAnnotation exists for the given JAnnotationType

Specified by:
isAnnotationPresent in interface JAnnotatedElement
Returns:
True if a JAnnotation has been added for the given JAnnotationType

addAnnotation

public void addAnnotation(JAnnotation annotation)
                   throws java.lang.IllegalArgumentException
Description copied from interface: JAnnotatedElement
Adds a JAnnotation to this source element. An IllegalArgumentException is thrown if one already exists for the associated JAnnotationType.

Specified by:
addAnnotation in interface JAnnotatedElement
Throws:
java.lang.IllegalArgumentException

removeAnnotation

public JAnnotation removeAnnotation(JAnnotationType annotationType)
                             throws java.lang.IllegalArgumentException
Description copied from interface: JAnnotatedElement
Removes the JAnnotation from this source element for the given JAnnotationType, throws a IllegalArgumentException if no JAnnotation has been added.

Specified by:
removeAnnotation in interface JAnnotatedElement
Returns:
The JAnnotation that was associated with this source element
Throws:
java.lang.IllegalArgumentException

hasAnnotations

public boolean hasAnnotations()
Description copied from interface: JAnnotatedElement
Returns true if annotations have been added to this source element

Specified by:
hasAnnotations in interface JAnnotatedElement
Returns:
Returns true if annotations have been added to this source element

addDeclaringClass

protected void addDeclaringClass(JClass jClass)
Adds the given JClass to the set of classes that contain this method.

Parameters:
jClass - the JClass to add as one of the JClasses that contain this method.

removeDeclaringClass

protected void removeDeclaringClass(JClass jClass)
Removes the given JClass from the set of classes that contain this method.

Parameters:
jClass - the JClass to add as one of the JClasses that contain this method.

getParameterClassNames

protected java.lang.String[] getParameterClassNames()


Intalio Inc. (C) 1999-2004. All rights reserved http://www.intalio.com