Class BField


  • public class BField
    extends java.lang.Object
    A wrapper for a field of a BlueJ class. Behaviour is similar to the Reflection API.
    Author:
    Damiano Bolla, University of Kent at Canterbury, 2003, Clive Miller, University of Kent at Canterbury, 2002
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.reflect.Field getJavaField()
      Returns the java Field for inspection.
      int getModifiers()
      Returns the modifier of this field.
      java.lang.String getName()
      Returns the name of the field.
      java.lang.Class<?> getType()
      Returns the type of the field.
      java.lang.Object getValue​(BObject onThis)
      Returns the value of this field for a given object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the name of the field. Similar to reflection API.
      • getType

        public java.lang.Class<?> getType()
        Returns the type of the field. Similar to Reflection API.
        Returns:
        A Class object representing the type of this field.
      • getJavaField

        public java.lang.reflect.Field getJavaField()
        Returns the java Field for inspection. This method can be used when more information is needed about the Field than is provided by the BField interface. E.g.: What is the declaring class of this Field? Note that this is for information only. To interact with BlueJ, an extension must use the methods provided in BField.
        Returns:
        The Field providing extra information about this BField.
      • getModifiers

        public int getModifiers()
        Returns the modifier of this field. The Modifier class can be used to decode the modifiers.
        Returns:
        An int value representing the modifiers which can be decoded with java.lang.reflect.Modifier.
      • getValue

        public java.lang.Object getValue​(BObject onThis)
                                  throws ProjectNotOpenException,
                                         PackageNotFoundException
        Returns the value of this field for a given object. This is similar to Reflection API. In the case that the field is of primitive type (int etc.), the return value is of the appropriate Java wrapper type (Integer etc.). In the case that the field contains an object then an appropriate BObject will be returned. The main reason that this method is on a field (derived from a class), rather than directly on an object, is to allow for the retrieval of static field values without having to create an object of the appropriate type. As in the Reflection API, in order to get the value of a static field pass null as the parameter to this method.
        Parameters:
        onThis - the BObject object for which this field's value should be retrieved.
        Returns:
        An Object object representing the field's value.
        Throws:
        ProjectNotOpenException - if the project to which the field belongs has been closed by the user.
        PackageNotFoundException - if the package to which the field belongs has been deleted by the user.