Interface PlasticField

All Superinterfaces:
AnnotationAccess

public interface PlasticField extends AnnotationAccess
Represents a field of a class being transformed. No methods of this object should be invoked after the class transformation is completed.
  • Method Details

    • getPlasticClass

      Returns the class containing this field.
    • getHandle

      Returns a handle that can be used to directly access a private field of a transformed class instance.
    • getName

      Returns the name of the field.
    • 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

      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:
    • isClaimed

      boolean isClaimed()
      Returns true if the field has already been claimed.
      See Also:
    • inject

      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

      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
    • injectFromInstanceContext

      As with inject(Object), but the value is extracted from the InstanceContext.
      Returns:
      this field for further manipulation
    • setConduit

      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

      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

      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

      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

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

      Returns the modifiers on the field.