Checked Field
A helper class for referring to a field. It verifies at construction time that the referenced field is marked with the ReferencedInGeneratedCode annotation, and that the specified type agrees. When it generates a read (getfield/getstatic) or write (putfield/putstatic), it uses the appropriate instruction. It substitutes a literal if the field is final, and forbids generating a write to it.
The main power this class brings is the ability to check the type signature prior to code generation, rather than have the JVM verifier be the failure point. It also fails early if the referenced field isn't marked with ReferencedInGeneratedCode, helping to keep critical fields from changing or disappearing under maintenance. It also keeps field names out of the code generator, making it easier to find the real uses of fields in generator code.
Author
Mark van Gulik
Todd L Smith
Parameters
Whether to look for the ReferencedInGeneratedCode annotation.
Whether the field is expected to be static.
The class in which the field should be found.
The name of the field.
The type of the field.
Functions
Emit a read of this field. The receiver, if this is not static, must already be on the stack.
Emit a write of this field for the given JVMTranslator and MethodVisitor. The receiver, if any, and the new field value must already be on the stack. Fail right away if the field is final.