Package bluej.extensions2
Class BConstructor
- java.lang.Object
-
- bluej.extensions2.BConstructor
-
public class BConstructor extends java.lang.Object
A wrapper for a constructor of a BlueJ class. Behaviour is similar to reflection API.- Author:
- Damiano Bolla, University of Kent at Canterbury, 2003,2004
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getModifiers()
Returns the modifier of this constructor.java.lang.Class<?>[]
getParametersTypes()
Returns the parameters' types of this constructor.boolean
matches(java.lang.Class<?>[] parameter)
Tests if this constructor matches the given signature.BObject
newInstance(java.lang.Object[] initargs)
Creates a new instance of the object described by this constructor.java.lang.String
toString()
Returns a string representation of the Object.
-
-
-
Method Detail
-
matches
public boolean matches(java.lang.Class<?>[] parameter)
Tests if this constructor matches the given signature.- Parameters:
parameter
- signature of the constructor to compare.- Returns:
- true if it does, false otherwise.
-
getParametersTypes
public java.lang.Class<?>[] getParametersTypes()
Returns the parameters' types of this constructor. Similar to reflection API.- Returns:
- An array of
Class
objects representing the parameters' types of the constructor.
-
newInstance
public BObject newInstance(java.lang.Object[] initargs) throws ProjectNotOpenException, PackageNotFoundException, InvocationArgumentException, InvocationErrorException
Creates a new instance of the object described by this constructor. Similar to reflection API. Note that this method should not be called from the JavaFX (GUI) thread.The arguments passed in the initargs array may have any type, but the type will determine exactly what is passed to the constructor:
- String - the String will be passed directly to the constructor
- BObject - the object will be passed directly to the constructor, though it must be on the object bench for this to work
- Anything else - toString() is called on the object and the result is treated as a Java expression, which is evaluated and passed to the constructor.
An attempt is made to ensure that the argument types are suitable for the constructor. 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.
- Parameters:
initargs
- An array ofObject
objects representing the arguments of this constructor.- Returns:
- A
BObject
object instancied with this constructor. - Throws:
ProjectNotOpenException
- if the project to which this constructor belongs has been closed by the user.PackageNotFoundException
- if the package to which this constructor belongs has been deleted by the user.InvocationArgumentException
- if theinitargs
don't match the constructor's arguments.InvocationErrorException
- if an error occurs during the invocation.
-
getModifiers
public int getModifiers()
Returns the modifier of this constructor. TheModifier
class can be used to decode the modifiers.- Returns:
- An int value representing the modifiers which can be decoded with
java.lang.reflect.Modifier
.
-
toString
public java.lang.String toString()
Returns a string representation of the Object.- Overrides:
toString
in classjava.lang.Object
-
-