Search in sources :

Example 1 with Configurator

use of org.apache.groovy.contracts.generation.Configurator in project groovy by apache.

the class ConfigurationSetup method init.

/**
 * Adds an instance field which allows to control whether GContract assertions
 * are enabled or not. Before assertions are evaluated this field will be checked.
 *
 * @param type the current {@link ClassNode}
 * @see Configurator
 */
public void init(final ClassNode type) {
    Validate.notNull(type);
    StaticMethodCallExpression checkAssertionsEnabledMethodCall = callX(ClassHelper.makeWithoutCaching(Configurator.class), "checkAssertionsEnabled", args(constX(type.getName())));
    final FieldNode fieldNode = type.addField(BaseVisitor.GCONTRACTS_ENABLED_VAR, Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_FINAL, ClassHelper.boolean_TYPE, checkAssertionsEnabledMethodCall);
    fieldNode.setSynthetic(true);
}
Also used : FieldNode(org.codehaus.groovy.ast.FieldNode) Configurator(org.apache.groovy.contracts.generation.Configurator) StaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression)

Aggregations

Configurator (org.apache.groovy.contracts.generation.Configurator)1 FieldNode (org.codehaus.groovy.ast.FieldNode)1 StaticMethodCallExpression (org.codehaus.groovy.ast.expr.StaticMethodCallExpression)1