Package bluej.extensions2
Class BClass
- java.lang.Object
-
- bluej.extensions2.BClass
-
public class BClass extends java.lang.ObjectA wrapper for a class. This is used to represent both classes which have a representation within the BlueJ project, and those that don't.From an instance of this class, an extension can create BlueJ objects and call their methods. Behaviour is similar to the Java reflection API.
- Author:
- Damiano Bolla, University of Kent at Canterbury, 2002,2003,2004
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcompile(boolean waitCompileEnd)Compiles this class, and any dependents.voidcompile(boolean waitCompileEnd, boolean forceQuiet)Compiles this class, and any dependents, optionally without showing compilation errors to the user.voidconvertJavaToStride()Converts a Java class to Stride.voidconvertStrideToJava()Converts a Stride class to Java, by removing the Stride file and retaining the generated Java.java.io.FilegetClassFile()Returns this class's .class file.BConstructorgetConstructor(java.lang.Class<?>[] signature)Returns the constructor for this class which has the given signature.BConstructor[]getConstructors()Returns all the constructors of this class.BMethodgetDeclaredMethod(java.lang.String methodName, java.lang.Class<?>[] params)Returns the declared method of this class which has the given signature.BMethod[]getDeclaredMethods()Returns the declared methods of this class.BFieldgetField(java.lang.String fieldName)Returns the field of this class which has the given name.BField[]getFields()Returns all the fields of this class.java.lang.Class<?>getJavaClass()Returns the Java Class object being wrapped by this BClass.JavaEditorgetJavaEditor()Returns a proxy object that provide an interface to the Java editor for this BClass.JavaEditorgetJavaEditorIfOpen()Returns a proxy object that provide an interface to the Java editor for this BClass.java.io.FilegetJavaFile()Returns this class's .java file.BMethodgetMethod(java.lang.String methodName, java.lang.Class<?>[] params)Returns the method of this class with the given signature.BMethod[]getMethods()Returns all methods of this class, those declared and those inherited from all ancestors.java.lang.StringgetName()Returns the name of this BClass.BPackagegetPackage()Returns the BPackage this class belongs to.SourceTypegetSourceType()Finds out whether this class has source code available, and whether it's Java or StrideStrideEditorgetStrideEditor()Returns a proxy object that provide an interface to the Stride editor for this BClass.StrideEditorgetStrideEditorIfOpen()Returns a proxy object that provide an interface to the Stride editor for this BClass.BClassgetSuperclass()Returns the superclass of this class.booleanisCompiled()Checks to see if this class has been compiled.voidremove()Removes this class from BlueJ, including the underlying files.java.lang.StringtoString()Returns a string representation of the Object
-
-
-
Method Detail
-
getName
public final java.lang.String getName()
Returns the name of this BClass.- Returns:
- The fully qualified name of the wrapped BlueJ class.
-
remove
public void remove() throws ProjectNotOpenException, PackageNotFoundException, ClassNotFoundExceptionRemoves this class from BlueJ, including the underlying files.- Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.ClassNotFoundException- if the class has been deleted by the user, or if the class does not otherwise have a representation within the project.
-
convertStrideToJava
public void convertStrideToJava() throws ProjectNotOpenException, PackageNotFoundException, ClassNotFoundExceptionConverts a Stride class to Java, by removing the Stride file and retaining the generated Java.
-
convertJavaToStride
public void convertJavaToStride() throws ProjectNotOpenException, PackageNotFoundException, ClassNotFoundExceptionConverts a Java class to Stride.
-
getJavaClass
public java.lang.Class<?> getJavaClass() throws ProjectNotOpenException, ClassNotFoundExceptionReturns the Java Class object being wrapped by this BClass. An extension uses this method when more information about the class than is provided by the BClass interface is needed. E.g.:- What is the real class being hidden?
- Is it an array?
- What is the type of the array element?
Note that this is for information only. To interact with BlueJ, an extension must use the methods provided in BClass.
- Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.ClassNotFoundException- if the class has been deleted by the user.
-
getPackage
public BPackage getPackage() throws ProjectNotOpenException, PackageNotFoundException
Returns the BPackage this class belongs to. Similar to reflection API.- Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.
-
getJavaEditor
public JavaEditor getJavaEditor() throws ProjectNotOpenException, PackageNotFoundException
Returns a proxy object that provide an interface to the Java editor for this BClass. If an editor already exists, a proxy for it is returned. Otherwise, an editor is created but not made visible. If the class is not a Java class (e.g. Stride) the method returnsnull.- Returns:
- A proxy
JavaEditorobject or null if it cannot be created or if the class is not of type Java - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.
-
getJavaEditorIfOpen
public JavaEditor getJavaEditorIfOpen() throws PackageNotFoundException, ProjectNotOpenException
Returns a proxy object that provide an interface to the Java editor for this BClass. If the editor is open, a proxy for it is returned. Otherwise, null is returned. If the class is not a Java class (e.g. Stride) the method returnsnull.- Returns:
- A proxy
JavaEditorobject or null if it cannot be created or if the class is not of type Java or the editor is not opened. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.- Since:
- Extension API 3.2 (BlueJ 5.0.2)
-
getStrideEditor
public StrideEditor getStrideEditor() throws ProjectNotOpenException, PackageNotFoundException
Returns a proxy object that provide an interface to the Stride editor for this BClass. If an editor already exists, a proxy for it is returned. Otherwise, an editor is created but not made visible. If the class is not a Stride class the method returnsnull.- Returns:
- A proxy
JavaEditorobject or null if it cannot be created or if the class is not of type Java - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.
-
getStrideEditorIfOpen
public StrideEditor getStrideEditorIfOpen() throws PackageNotFoundException, ProjectNotOpenException
Returns a proxy object that provide an interface to the Stride editor for this BClass. If the editor is open, a proxy for it is returned. Otherwise, null is returned. If the class is not a Stride class the method returnsnull.- Returns:
- A proxy
JavaEditorobject or null if it cannot be created or if the class is not of type Java or the editor is not opened. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.- Since:
- Extension API 3.2 (BlueJ 5.0.2)
-
getSourceType
public SourceType getSourceType() throws ProjectNotOpenException, PackageNotFoundException
Finds out whether this class has source code available, and whether it's Java or Stride- Returns:
- Either
SourceType.JavaorSourceType.Strideif the type can be found out, otherwisenull. - Throws:
ProjectNotOpenExceptionPackageNotFoundException
-
isCompiled
public boolean isCompiled() throws ProjectNotOpenException, PackageNotFoundExceptionChecks to see if this class has been compiled.- Returns:
- True if it is compiled, false otherwise.
- Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.
-
compile
public void compile(boolean waitCompileEnd) throws ProjectNotOpenException, PackageNotFoundException, CompilationNotStartedExceptionCompiles this class, and any dependents.After the compilation has finished the method isCompiled() can be used to determined the class status.
A single CompileEvent will be generated with all dependent files listed.
A call to this method is equivalent to:
compile(waitCompileEnd, false).- Parameters:
waitCompileEnd-truewaits for the compilation to be finished.- Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed.PackageNotFoundException- if the package to which this class belongs has been deleted.CompilationNotStartedException- if BlueJ is currently executing Java code.
-
compile
public void compile(boolean waitCompileEnd, boolean forceQuiet) throws ProjectNotOpenException, PackageNotFoundException, CompilationNotStartedExceptionCompiles this class, and any dependents, optionally without showing compilation errors to the user.After the compilation has finished the method isCompiled() can be used to determined the class status.
A single CompileEvent with all dependent files listed will be generated.
- Parameters:
waitCompileEnd-truewaits for the compilation to be finished.forceQuiet- if true, compilation errors will not be shown/highlighted to the user.- Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed.PackageNotFoundException- if the package to which this class belongs has been deleted.CompilationNotStartedException- if BlueJ is currently executing Java code.
-
getSuperclass
public BClass getSuperclass() throws ProjectNotOpenException, PackageNotFoundException, ClassNotFoundException
Returns the superclass of this class. Similar to reflection API.- Returns:
- The superclass wrapped in a BClass object. If this class represents either the Object class or an interface then
nullis returned. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.ClassNotFoundException- if the class has been deleted by the user.
-
getConstructors
public BConstructor[] getConstructors() throws ProjectNotOpenException, ClassNotFoundException
Returns all the constructors of this class. Similar to reflection API.- Returns:
- An array of
BConstructorobjects wrapping the constructors of this class. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.ClassNotFoundException- if the class has been deleted by the user.
-
getConstructor
public BConstructor getConstructor(java.lang.Class<?>[] signature) throws ProjectNotOpenException, ClassNotFoundException
Returns the constructor for this class which has the given signature. Similar to reflection API.- Parameters:
signature- the signature of the required constructor.- Returns:
- The
BConstructorobject wrapping the matching constructor of this class, or null if the class has not been compiled or the constructor cannot be found. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.ClassNotFoundException- if the class has been deleted by the user.
-
getDeclaredMethods
public BMethod[] getDeclaredMethods() throws ProjectNotOpenException, ClassNotFoundException
Returns the declared methods of this class. Similar to reflection API.- Returns:
- An array of
BMethodobjects wrapping the methods of this class. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.ClassNotFoundException- if the class has been deleted by the user.
-
getDeclaredMethod
public BMethod getDeclaredMethod(java.lang.String methodName, java.lang.Class<?>[] params) throws ProjectNotOpenException, ClassNotFoundException
Returns the declared method of this class which has the given signature. Similar to reflection API.- Parameters:
methodName- The name of the method.params- The parameters of the method. Pass a zero length array if the method takes no arguments.- Returns:
- The
BMethodobject wrapping the matching method ornullif the method is not found. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.ClassNotFoundException- if the class has been deleted by the user.
-
getMethods
public BMethod[] getMethods() throws ProjectNotOpenException, ClassNotFoundException
Returns all methods of this class, those declared and those inherited from all ancestors. Similar to reflection API, except that all methods, declared and inherited, are returned, and not only the public ones. That is, it returns all public, private, protected, and package-access methods, inherited or declared. The elements in the array returned are not sorted and are not in any particular order.- Returns:
- An array of
BMethodobjects wrapping the methods of this class. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.ClassNotFoundException- if the class has been deleted by the user.
-
getMethod
public BMethod getMethod(java.lang.String methodName, java.lang.Class<?>[] params) throws ProjectNotOpenException, ClassNotFoundException
Returns the method of this class with the given signature. Similar to reflection API, except that all methods, declared and inherited, are searched, and not only the public ones. That is, it searches all public, private, protected, and package-access methods, declared or inherited from all ancestors. If the searched method has been redefined, the returned method is chosen arbitrarily from the list of inherited and declared methods.- Parameters:
methodName- The name of the methodparams- The parameters of the method. Pass a zero length array if the method takes no arguments.- Returns:
- The
BMethodobject wrapping the matching method ornullif the method is not found. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the userClassNotFoundException- if the class has been deleted by the user
-
getFields
public BField[] getFields() throws ProjectNotOpenException, ClassNotFoundException
Returns all the fields of this class. Similar to reflection API.- Returns:
- An array of
BFieldobjects wrapping this class's fields. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.ClassNotFoundException- if the class has been deleted by the user.
-
getField
public BField getField(java.lang.String fieldName) throws ProjectNotOpenException, ClassNotFoundException
Returns the field of this class which has the given name. Similar to Reflection API.- Parameters:
fieldName- name of the field- Returns:
- The
BFieldobject wrapping the matching field, ornullif no field is found. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.ClassNotFoundException- if the class has been deleted by the user.
-
getClassFile
public java.io.File getClassFile() throws ProjectNotOpenException, PackageNotFoundExceptionReturns this class's .class file.- Returns:
- A
Fileobject for the class's .class file,nullif the class no longer exists in the project. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.
-
getJavaFile
public java.io.File getJavaFile() throws ProjectNotOpenException, PackageNotFoundExceptionReturns this class's .java file. If the file is currently being edited, calling this method will cause it to be saved.- Returns:
- A
Fileobject for the class's .java file. - Throws:
ProjectNotOpenException- if the project to which this class belongs has been closed by the user.PackageNotFoundException- if the package to which this class belongs has been deleted by the user.
-
toString
public java.lang.String toString()
Returns a string representation of the Object- Overrides:
toStringin classjava.lang.Object
-
-