CheckedMethod

A helper class for referring to a method. It verifies at construction time that the referenced method is marked with the ReferencedInGeneratedCode annotation, and that the specified argument types are correct. When it generates a call, it uses the appropriate invoke instruction, and even generates a Opcodes.CHECKCAST instruction if the result type isn't strong enough.

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 method isn't marked with ReferencedInGeneratedCode, helping to keep critical methods from changing or disappearing under maintenance. It also keeps method names out of the code generator, making it easier to find the real uses of methods in generator code.

Factory methods that indicate the method is part of the Java library are not expected to have the ReferencedInGeneratedCode annotation.

Author

Mark van Gulik

Todd L Smith

Parameters

verifyAnnotation

Whether to look for the ReferencedInGeneratedCode annotation.

isStatic

Whether the method is expected to be static.

receiverClass

The type of the receiver of the method.

methodNameString

The name of the method.

returnClass

The required return type.

argumentTypes

A vararg array of argument types.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun generateCall(methodVisitor: MethodVisitor)

Emit a call to this method on the given MethodVisitor. The arguments must already be ready on the stack.