bluej.extensions
Class BMethod

java.lang.Object
  extended by bluej.extensions.BMethod

public class BMethod
extends java.lang.Object

A wrapper for a method of a BlueJ class. Allows an extension to invoke a method on an object that is on the BlueJ object bench. When values representing types are returned, there are two cases: In the case that the returned value is of primitive type (int etc.), it is represented in the appropriate Java wrapper type (Integer etc.). In the case that the returned value is an object type then an appropriate BObject will be returned, allowing the returned object itself to be placed on the BlueJ object bench.

Author:
Clive Miller, University of Kent at Canterbury, 2002, Damiano Bolla, University of Kent at Canterbury 2003

Method Summary
 java.lang.String getDeclaringClass()
          Returns the class that declares this method.
 int getModifiers()
          Returns the modifiers for this method.
 java.lang.String getName()
          Returns the name of this method.
 java.lang.Class<?>[] getParameterTypes()
          Returns the types of the parameters of this method.
 java.lang.Class<?> getReturnType()
          Returns the return type of this method Similar to Reflection API
 java.lang.Object invoke(BObject onThis, java.lang.Object[] params)
          Invoke this method on the given object.
 boolean matches(java.lang.String methodName, java.lang.Class<?>[] parameter)
          Tests if this method matches against the given signature.
 java.lang.String toString()
          Returns a string representing the return type, name and signature of this method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

matches

public boolean matches(java.lang.String methodName,
                       java.lang.Class<?>[] parameter)
Tests if this method matches against the given signature. Returns true if there is a match, false otherwise. Pass a zero length parameter array if the method takes no arguments.


getDeclaringClass

public java.lang.String getDeclaringClass()
Returns the class that declares this method. Similar to Reflection API


getParameterTypes

public java.lang.Class<?>[] getParameterTypes()
Returns the types of the parameters of this method. Similar to Reflection API


getName

public java.lang.String getName()
Returns the name of this method. Similar to Reflection API


getReturnType

public java.lang.Class<?> getReturnType()
Returns the return type of this method Similar to Reflection API


getModifiers

public int getModifiers()
Returns the modifiers for this method. The java.lang.reflect.Modifier class can be used to decode the modifiers.


invoke

public java.lang.Object invoke(BObject onThis,
                               java.lang.Object[] params)
                        throws ProjectNotOpenException,
                               PackageNotFoundException,
                               InvocationArgumentException,
                               InvocationErrorException
Invoke this method on the given object. Note that this method should not be called from the AWT/Swing event-dispatching thread.

The arguments passed in the initargs array may have any type, but the type will determine exactly what is passed to the method:

An attempt is made to ensure that the argument types are suitable for the method. InvocationArgumentException will be thrown if the arguments are clearly unsuitable, however some cases will generate an InvocationErrorException instead. In such cases no expression arguments will be evaluated.

If the method invoked is public static void main(String [] args), then the invocation will, as a side-effect, reset the VM used by BlueJ to run user code in this project, and clear the object bench. This behaviour matches the effect of invoking a main method through the BlueJ GUI.

Parameters:
onThis - The BObject to which the method call should be applied, null if a static method.
params - an array containing the arguments, or null if there are none
Returns:
the resulting Object. It can be a wrapper for a primitive type or a BObject
Throws:
ProjectNotOpenException - if the project to which this object belongs has been closed by the user.
PackageNotFoundException - if the package to which this object belongs has been deleted by the user.
InvocationArgumentException - if the params don't match the object's arguments.
InvocationErrorException - if an error occurs during the invocation.

toString

public java.lang.String toString()
Returns a string representing the return type, name and signature of this method

Overrides:
toString in class java.lang.Object


BlueJ homepage