Search in sources :

Example 1 with AttributeExpression

use of org.codehaus.groovy.ast.expr.AttributeExpression in project grails-core by grails.

the class AbstractGrailsArtefactTransformer method addApiLookupFieldAndSetter.

protected void addApiLookupFieldAndSetter(ClassNode classNode, ClassNode implementationNode, String apiProperty, Expression initialValueExpression) {
    FieldNode fieldNode = classNode.getField(apiProperty);
    if (fieldNode == null || !fieldNode.getDeclaringClass().equals(classNode)) {
        fieldNode = new FieldNode(apiProperty, Modifier.PRIVATE | Modifier.STATIC, implementationNode, classNode, initialValueExpression);
        classNode.addField(fieldNode);
        String setterName = "set" + MetaClassHelper.capitalize(apiProperty);
        Parameter setterParameter = new Parameter(implementationNode, apiProperty);
        BlockStatement setterBody = new BlockStatement();
        setterBody.addStatement(new ExpressionStatement(new BinaryExpression(new AttributeExpression(new ClassExpression(classNode), new ConstantExpression(apiProperty)), Token.newSymbol(Types.EQUAL, 0, 0), new VariableExpression(setterParameter))));
        GrailsASTUtils.addCompileStaticAnnotation(classNode.addMethod(setterName, Modifier.PUBLIC | Modifier.STATIC, ClassHelper.VOID_TYPE, new Parameter[] { setterParameter }, null, setterBody));
    }
}
Also used : FieldNode(org.codehaus.groovy.ast.FieldNode) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) Parameter(org.codehaus.groovy.ast.Parameter) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) AttributeExpression(org.codehaus.groovy.ast.expr.AttributeExpression)

Aggregations

FieldNode (org.codehaus.groovy.ast.FieldNode)1 Parameter (org.codehaus.groovy.ast.Parameter)1 AttributeExpression (org.codehaus.groovy.ast.expr.AttributeExpression)1 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)1 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)1 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)1 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)1 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)1 ExpressionStatement (org.codehaus.groovy.ast.stmt.ExpressionStatement)1