Package org.codehaus.groovy.ast

Examples of org.codehaus.groovy.ast.FieldNode


                propertyNode.addAnnotation(getMarkerAnnotation());
            }
            classNode.addProperty(propertyNode);
        }
        else {
            FieldNode fieldNode = classNode.getField(apiInstanceProperty);
            if (fieldNode == null || (Modifier.isPrivate(fieldNode.getModifiers()) && !fieldNode.getDeclaringClass().equals(classNode))) {
                fieldNode = new FieldNode(apiInstanceProperty, PRIVATE_STATIC_MODIFIER,implementationNode, classNode,constructorCallExpression);
                classNode.addField(fieldNode);
            }
        }

        while (!implementationNode.equals(AbstractGrailsArtefactTransformer.OBJECT_CLASS)) {
View Full Code Here


        return methodNode;
    }

    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();
View Full Code Here

        autoAnnotateSetupTeardown(classNode);
        boolean isJunit3Test = isJunit3Test(classNode);

        // make sure the 'log' property is not the one from GroovyTestCase
        FieldNode log = classNode.getField("log");
        if (log == null || log.getDeclaringClass().equals(GROOVY_TEST_CASE_CLASS)) {
            LoggingTransformer.addLogField(classNode, classNode.getName());
        }
        boolean isSpockTest = isSpockTest(classNode);

        boolean isJunit4 = !isSpockTest && !isJunit3Test;
View Full Code Here

    if (!(astNodes[0] instanceof AnnotationNode) || !(astNodes[1] instanceof FieldNode)) {
      throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
    }

    final AnnotationNode annotationNode = (AnnotationNode) astNodes[0];
    final FieldNode fieldNode = (FieldNode) astNodes[1];
    final Map<String, Expression> members = annotationNode.getMembers();
    if(members == null || (!members.containsKey("code") && !members.containsKey("value"))) {
      final String message = "The @BindingFormat annotation on the field ["
          + fieldNode.getName() +
          "] in class [" +
          fieldNode.getDeclaringClass().getName() +
          "] must provide a value for either the value() or code() attribute.";
     
      error(source, fieldNode, message);
    }
  }
View Full Code Here

        }

        @Override
        public void visitClass(final ClassNode node) {

            final FieldNode actorField = node.getField(actorFieldName);
            if (actorField != null) {
                if (actorField.getType().getName().contains("groovyx.gpars.activeobject.InternalActor")) {
                    actorNode = actorField;
                } else
                    this.addError("Active Object cannot have a field named " + actorFieldName + " declared", actorField);
            } else {
                actorNode = addActorFieldToClass(node, actorFieldName, actorGroupName);
View Full Code Here

*/
public class LoggingTransformer implements ClassInjector{
  public static final String LOG_PROPERTY = "log";

  public void performInjection(SourceUnit source, GeneratorContext context, ClassNode classNode) {
    final FieldNode existingField = classNode.getDeclaredField(LOG_PROPERTY);
    if (existingField == null && !classNode.isInterface()) {
      String logName = "plugins." + classNode.getName();
      addLogField(classNode, logName);
    }
  }
View Full Code Here

      addLogField(classNode, logName);
    }
  }

  public static void addLogField(ClassNode classNode, String logName) {
    FieldNode logVariable = new FieldNode(LOG_PROPERTY,
                        Modifier.STATIC | Modifier.PRIVATE,
                        new ClassNode(Log.class),
                        classNode,
                        new MethodCallExpression(new ClassExpression(new ClassNode(LogFactory.class)), "getLog", new ArgumentListExpression(new ConstantExpression(logName))));
View Full Code Here

        ));
    }

    private static FieldNode createFieldCopy(ClassNode builderClass, PropertyInfo prop) {
        String propName = prop.getName();
        return new FieldNode(propName.equals("class") ? "clazz" : propName, ACC_PRIVATE, newClass(prop.getType()), builderClass, DEFAULT_INITIAL_VALUE);
    }
View Full Code Here

        init(nodes, source);
        AnnotatedNode parent = (AnnotatedNode) nodes[1];
        AnnotationNode node = (AnnotationNode) nodes[0];

        if (parent instanceof FieldNode) {
            final FieldNode fieldNode = (FieldNode) parent;
            visitField(node, fieldNode);
        }
    }
View Full Code Here

                    String operation = methodNode.getName().substring(suffixIdx + 1);
                    boolean getter = "get".equals(operation);
                    ClassNode returnType = correctToGenericsSpecRecurse(genericsSpec, methodNode.getReturnType());
                    int isStatic = 0;
                    boolean publicField = true;
                    FieldNode helperField = fieldHelperClassNode.getField(Traits.FIELD_PREFIX + Traits.PUBLIC_FIELD_PREFIX + fieldName);
                    if (helperField==null) {
                        publicField = false;
                        helperField = fieldHelperClassNode.getField(Traits.FIELD_PREFIX + Traits.PRIVATE_FIELD_PREFIX + fieldName);
                    }
                    if (helperField==null) {
                        publicField = true;
                        // try to find a static one
                        helperField = fieldHelperClassNode.getField(Traits.STATIC_FIELD_PREFIX+Traits.PUBLIC_FIELD_PREFIX+fieldName);
                        if (helperField==null) {
                            publicField = false;
                            helperField = fieldHelperClassNode.getField(Traits.STATIC_FIELD_PREFIX+Traits.PRIVATE_FIELD_PREFIX +fieldName);
                        }
                        isStatic = Opcodes.ACC_STATIC;
                    }
                    if (getter) {
                        // add field
                        if (helperField!=null) {
                            List<AnnotationNode> copied = new LinkedList<AnnotationNode>();
                            List<AnnotationNode> notCopied = new LinkedList<AnnotationNode>();
                            GeneralUtils.copyAnnotatedNodeAnnotations(helperField, copied, notCopied);
                            FieldNode fieldNode = cNode.addField(fieldName, (publicField?Opcodes.ACC_PUBLIC:Opcodes.ACC_PRIVATE) | isStatic, returnType, null);
                            fieldNode.addAnnotations(copied);
                        }
                    }
                    Parameter[] newParams;
                    if (getter) {
                        newParams = Parameter.EMPTY_ARRAY;
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.ast.FieldNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.