public class Verifier
extends Object
implements GroovyClassVisitor, org.objectweb.asm.Opcodes
Verifies the AST node and adds any default AST code before bytecode generation occurs.
Checks include:
| Modifiers | Name | Description |
|---|---|---|
interface |
Verifier.DefaultArgsAction |
Strategy invoked for each synthetic method or constructor generated for default arguments. |
| Modifiers | Name | Description |
|---|---|---|
static String |
DEFAULT_PARAMETER_GENERATED |
Metadata key marking methods generated to support default arguments. |
static String |
INITIAL_EXPRESSION |
Metadata key used to retain a property's original initializer expression. |
static String |
STATIC_METACLASS_BOOL |
Synthetic field name used to cache static metaclass initialization checks. |
static String |
SWAP_INIT |
Metadata key used when swapping initializer statements during verification. |
static String |
__TIMESTAMP |
Synthetic timestamp field used for backwards-compatible script metadata. |
static String |
__TIMESTAMP__ |
Alternate synthetic timestamp field retained for binary compatibility. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected void |
addClosureCode(InnerClassNode node)Adds the synthetic support code required by a generated closure class. |
|
protected void |
addConstructor(Parameter[] newParams, ConstructorNode ctor, Statement code, ClassNode type)Adds a synthetic constructor variant for default arguments. |
|
protected void |
addCovariantMethods(ClassNode classNode)Adds bridge methods needed to support covariant overrides. |
|
protected void |
addDefaultConstructor(ClassNode node)Adds a synthetic no-arg constructor when the class requires one. |
|
protected void |
addDefaultParameterConstructors(ClassNode type)Creates a new constructor for each combination of default parameter expressions. |
|
protected void |
addDefaultParameterMethods(ClassNode type)Creates a new method for each combination of default parameter expressions. |
|
protected void |
addDefaultParameters(List<? extends MethodNode> methods, Verifier.DefaultArgsAction action)Creates a new helper method for each combination of default parameter expressions. |
|
protected void |
addDefaultParameters(Verifier.DefaultArgsAction action, MethodNode method)Applies default-argument generation to a single method or constructor. |
|
protected void |
addFieldInitialization(List list, List staticList, FieldNode fieldNode, boolean isEnumClassNode, List initStmtsAfterEnumValuesInit, Set explicitStaticPropsInEnum)Routes a field initializer into the appropriate instance or static initialization block. |
|
protected void |
addGroovyObjectInterfaceAndMethods(ClassNode node, String classInternalName)Adds the GroovyObject contract and supporting methods when needed. |
|
protected void |
addInitialization(ClassNode node)Adds object and static initializer wiring for the supplied class. |
|
protected void |
addInitialization(ClassNode node, ConstructorNode constructorNode)Adds initializer statements to the supplied constructor context. |
|
protected MethodNode |
addMethod(ClassNode node, boolean shouldBeSynthetic, String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)Helper method to add a new method to a ClassNode. |
|
protected void |
addPropertyMethod(MethodNode method)Registers a generated property accessor or mutator with the current class. |
|
protected void |
addReturnIfNeeded(MethodNode node)Ensures the supplied method has an explicit return statement when required. |
|
protected void |
addTimeStamp(ClassNode node)Adds legacy synthetic timestamp fields for scripts and generated classes. |
|
public static String |
capitalize(String name)Capitalizes the start of the given bean property name. |
|
protected Statement |
createGetterBlock(PropertyNode propertyNode, FieldNode field)Creates the bytecode-backed statement block for a generated property getter. |
|
protected Statement |
createSetterBlock(PropertyNode propertyNode, FieldNode field)Creates the bytecode-backed statement block for a generated property setter. |
|
public ClassNode |
getClassNode()Returns the class node currently being verified. |
|
protected VariableNotFinalCallback |
getFinalVariablesCallback()Creates the callback used when final-variable analysis finds invalid assignments. |
|
public MethodNode |
getMethodNode()Returns the method node currently being verified. |
|
public static long |
getTimestamp(Class<?> clazz)Looks up the synthetic timestamp stored on a generated class. |
|
public static Long |
getTimestampFromFieldName(String fieldName)Extracts a timestamp value from a synthetic timestamp field name. |
|
protected void |
setClassNode(ClassNode classNode)Sets the class node to be verified. |
|
public static ConstantExpression |
transformToPrimitiveConstantIfPossible(ConstantExpression constantExpression)When constant expressions are created, the value is always wrapped to a non-primitive type. |
|
public void |
visitClass(ClassNode node)* Visit a ClassNode. |
|
public void |
visitConstructor(ConstructorNode node)* Visit a ConstructorNode. |
|
public void |
visitField(FieldNode node)* Visit a FieldNode. |
|
public void |
visitGenericType(GenericsType genericsType)Extension point invoked when traversing a generic type; the default implementation does nothing. |
|
public void |
visitMethod(MethodNode node)* Visit a MethodNode. |
|
public void |
visitProperty(PropertyNode node)* Visit a PropertyNode. |
Metadata key marking methods generated to support default arguments.
Metadata key used to retain a property's original initializer expression.
Synthetic field name used to cache static metaclass initialization checks.
Metadata key used when swapping initializer statements during verification.
Synthetic timestamp field used for backwards-compatible script metadata.
Alternate synthetic timestamp field retained for binary compatibility.
Adds the synthetic support code required by a generated closure class.
node - the closure class nodeAdds a synthetic constructor variant for default arguments.
newParams - the parameters of the generated constructorctor - the source constructorcode - the generated constructor bodytype - the declaring typeAdds bridge methods needed to support covariant overrides.
classNode - the class being enhancedAdds a synthetic no-arg constructor when the class requires one.
node - the class being verifiedCreates a new constructor for each combination of default parameter expressions.
Creates a new method for each combination of default parameter expressions.
Creates a new helper method for each combination of default parameter expressions.
Applies default-argument generation to a single method or constructor.
action - the generation strategymethod - the method or constructor to expandRoutes a field initializer into the appropriate instance or static initialization block.
list - the instance-initializer statementsstaticList - the static-initializer statementsfieldNode - the field whose initializer is being processedisEnumClassNode - whether the declaring class is an enuminitStmtsAfterEnumValuesInit - enum statements that must run after constant initializationexplicitStaticPropsInEnum - explicitly declared static enum properties Adds the GroovyObject contract and supporting methods when needed.
node - the class being enhancedclassInternalName - the internal JVM name of the classAdds object and static initializer wiring for the supplied class.
node - the class being enhancedAdds initializer statements to the supplied constructor context.
node - the class being enhancedconstructorNode - the constructor receiving initialization codeHelper method to add a new method to a ClassNode. Depending on the shouldBeSynthetic flag the call will either be made to ClassNode.addSyntheticMethod() or ClassNode.addMethod(). If a non-synthetic method is to be added the ACC_SYNTHETIC modifier is removed if it has been accidentally supplied.
Registers a generated property accessor or mutator with the current class.
method - the generated property methodEnsures the supplied method has an explicit return statement when required.
node - the method to normalizeAdds legacy synthetic timestamp fields for scripts and generated classes.
node - the class being enhancedCreates the bytecode-backed statement block for a generated property getter.
propertyNode - the property being servedfield - the backing fieldCreates the bytecode-backed statement block for a generated property setter.
propertyNode - the property being updatedfield - the backing fieldReturns the class node currently being verified.
Creates the callback used when final-variable analysis finds invalid assignments.
Returns the method node currently being verified.
Looks up the synthetic timestamp stored on a generated class.
clazz - the generated class to inspectLong.MAX_VALUE if none is availableExtracts a timestamp value from a synthetic timestamp field name.
fieldName - the field name to inspectnull if the name is not a timestamp fieldSets the class node to be verified.
classNode - the class node to verifyWhen constant expressions are created, the value is always wrapped to a non-primitive type. Some constant expressions are optimized to return primitive types, but not all primitives are handled. This method guarantees to return a similar constant expression but with a primitive type instead of a boxed type.
Additionally, single char strings are converted to 'char' types.constantExpression - a constant expression* Visit a ClassNode.
* Visit a ConstructorNode.
* Visit a FieldNode.
Extension point invoked when traversing a generic type; the default implementation does nothing.
* Visit a MethodNode.
* Visit a PropertyNode.