CheckedField

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

verifyAnnotation

Whether to look for the ReferencedInGeneratedCode annotation.

isStatic

Whether the field is expected to be static.

receiverClass

The class in which the field should be found.

fieldNameString

The name of the field.

fieldClass

The type of the field.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The reflected Field to be accessed.

Functions

Link copied to clipboard
fun generateRead(methodVisitor: MethodVisitor)

Emit a read of this field. The receiver, if this is not static, must already be on the stack.

Link copied to clipboard
fun generateWrite(methodVisitor: MethodVisitor)

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.