Interface PlasticField

    • Method Detail

      • getHandle

        FieldHandle getHandle()
        Returns a handle that can be used to directly access a private field of a transformed class instance.
      • getTypeName

        String getTypeName()
        Returns the fully qualified class name for the field's type or (for a primitive type) the primitive type name ("int", "char", etc.). For array types, the returned name includes a "[]" suffix.
      • claim

        PlasticField claim​(Object tag)
        Claims the field, used to indicate that the field is "processed". A field may only be claimed once. Claiming a field is intended as a mechanism to detect or prevent conflicts between different isolated transformations of the field. The tag value used does not matter, and is typically either an annotation (that drove the transformation) or the instance of PlasticClassTransformer that performed the transformation. That tag value is only used when generating the error message for the case where a field is claimed for than once.
        Returns:
        the field for further manipulation
        Throws:
        RuntimeException - if the field is claimed a second time
        AssertionError - if tag is null
        See Also:
        PlasticClass.getUnclaimedFields()
      • inject

        PlasticField inject​(Object value)
        Converts the field to be read-only, and provide the indicated value. The field's value will be set inside the class' constructor.
        Parameters:
        value - to inject, which must be type compatible with the field (possibly, a wrapper type if the field is a primitive value). The value may not be null.
        Returns:
        the field for further manipulation
        Throws:
        IllegalStateException - if the field already has an injection, or the field has a conduit
      • injectComputed

        PlasticField injectComputed​(ComputedValue<?> computedValue)
        Converts the field to be read-only, and provide the value, which is computed indirectly inside the class' constructor.
        Parameters:
        computedValue - provides the actual value to be injected, and must return a value type compatible with the field (possibly a wrapper type if the field is a primitive value). The computedValue may not be null.
        Returns:
        the field for further manipulation
        Throws:
        IllegalStateException - if the field already has an injection, or the field has a conduit
      • setConduit

        <F> PlasticField setConduit​(FieldConduit<F> conduit)
        Intercepts all access to the field, replacing such access with calls on the conduit. Even access via the FieldHandle will instead delegate to the conduit. Once a conduit is provided, it is not possible to inject a value into the field. Normally, once a conduit is in place, the field will never be actually read or written. This is problematic for debugging, so TransformationOption.FIELD_WRITEBEHIND is useful when operating in a non-production mode.
        Returns:
        the field for further manipulation
        Throws:
        IllegalStateException - if the field already has an injection or a conduit
      • setComputedConduit

        <F> PlasticField setComputedConduit​(ComputedValue<FieldConduit<F>> computedConduit)
        Sets the conduit for the field to a value computed when the class is instantiated
        Parameters:
        computedConduit - object that will compute the actual conduit to be used
        Returns:
        this field for further manipulation
      • createAccessors

        PlasticField createAccessors​(PropertyAccessType accessType)
        Creates access to the field, using the default property name derived from the name of the field. The default property name is the same as the name of the field, but with any leading or trailing underscore characters removed (a common convention among some programmers). Also, strips leading "m_" from the field name (another common convention).
        Parameters:
        accessType - which methods to create
        Returns:
        the field for further manipulation
        Throws:
        IllegalArgumentException - if an accessor method to be created already exists (possibly inherited from a base class)
      • createAccessors

        PlasticField createAccessors​(PropertyAccessType accessType,
                                     String propertyName)
        Creates accessors, possibly replacing existing methods (or overriding methods from a super class). The method names consist of the property name, with its first character converted to upper-case, prefixed with "get" or "set". The accessor methods must not already exist.
        Parameters:
        accessType - which methods to create
        propertyName - the name of the property (from which the names of the methods are generated)
        Returns:
        the field for further manipulation
        Throws:
        IllegalArgumentException - if an accessor method to be created already exists (possibly inherited from a base class)
      • getGenericSignature

        String getGenericSignature()
        Returns the field's fully qualified generic type, or null if not defined.
      • getModifiers

        int getModifiers()
        Returns the modifiers on the field.