Package org.codehaus.groovy.ast.expr

Examples of org.codehaus.groovy.ast.expr.ConstantExpression


        ClassNode targetAwareInterface = GrailsASTUtils.findInterface(fieldType, new ClassNode(TestMixinTargetAware.class).getPlainNodeReference());
        if (classNode != null && classNode.getField(fieldName) == null) {
            Expression constructorArgument = new ArgumentListExpression();
            if(targetAwareInterface != null) {
                MapExpression namedArguments = new MapExpression();
                namedArguments.addMapEntryExpression(new MapEntryExpression(new ConstantExpression("target"), new VariableExpression("this")));
                constructorArgument = namedArguments;
            }
            return classNode.addField(fieldName, Modifier.PRIVATE, fieldType,
                new ConstructorCallExpression(fieldType, constructorArgument));
        }
View Full Code Here


       
        VariableExpression apiVar = new VariableExpression(apiProperty, implementationNode);
       
        BlockStatement ifBlock = new BlockStatement();
        ArgumentListExpression arguments = new ArgumentListExpression();
        arguments.addExpression(new ConstantExpression("Method on class ["+classNode+"] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly."));
        ifBlock.addStatement(new ThrowStatement(new ConstructorCallExpression(new ClassNode(IllegalStateException.class), arguments)));       
        BlockStatement elseBlock = new BlockStatement();
        elseBlock.addStatement(new ReturnStatement(apiVar));
        methodBody.addStatement(new IfStatement(new BooleanExpression(new BinaryExpression(apiVar, GrailsASTUtils.EQUALS_OPERATOR, GrailsASTUtils.NULL_EXPRESSION)),ifBlock,elseBlock));
       
View Full Code Here

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

    protected void postProcess(SourceUnit sourceUnit, AnnotationNode annotationNode, ClassNode classNode, String artefactType) {
        if(!getAnnotationType().equals(annotationNode.getClassNode())) {
            // add @Artefact annotation to resulting class so that "short cut" annotations like @TagLib
            // also produce an @Artefact annotation in the resulting class file
            AnnotationNode annotation=new AnnotationNode(getAnnotationType());
            annotation.addMember("value", new ConstantExpression(artefactType));
            classNode.addAnnotation(annotation);
        }
    }
View Full Code Here

    protected String resolveArtefactType(SourceUnit sourceUnit, AnnotationNode annotationNode, ClassNode classNode) {
        Expression value = annotationNode.getMember("value");

        if (value != null && (value instanceof ConstantExpression)) {
            ConstantExpression ce = (ConstantExpression) value;
            return ce.getText();
        }
        else {
            throw new RuntimeException("Class ["+classNode.getName()+"] contains an invalid @Artefact annotation. No artefact found for value specified.");
        }
    }
View Full Code Here

                        Token.newSymbol("&&",0,0),
                new BinaryExpression(appCtxVar, GrailsASTUtils.NOT_EQUALS_OPERATOR, GrailsASTUtils.NULL_EXPRESSION)));
        BlockStatement performAutowireBlock = new BlockStatement();
        ArgumentListExpression arguments = new ArgumentListExpression();
        arguments.addExpression(fieldExpression);
        arguments.addExpression(new ConstantExpression(1));
        arguments.addExpression(new ConstantExpression(false));
        BlockStatement assignFromApplicationContext = new BlockStatement();
        ArgumentListExpression argWithClassName = new ArgumentListExpression();
        MethodCallExpression getClassNameMethodCall = new MethodCallExpression(targetClass, "getName", new ArgumentListExpression());
        argWithClassName.addExpression(getClassNameMethodCall);
View Full Code Here

            classExpression = new ClassExpression(ClassHelper.make(GParsPoolUtil.class));
        }

        validatePoolClass(classExpression, fieldNode, source);
        final Expression initExpression = ((FieldNode) fieldNode).getInitialValueExpression();
        final ConstantExpression blocking = new ConstantExpression(memberHasValue(annotation, "blocking", true));

        final Expression newInitExpression = new StaticMethodCallExpression(
                classExpression.getType(),
                "asyncFun",
                new ArgumentListExpression(initExpression, blocking));
View Full Code Here

            final ArgumentListExpression args = new ArgumentListExpression();
            final Parameter[] params = original.getParameters();
            final Parameter[] newParams = new Parameter[params.length];

            args.addExpression(new VariableExpression("this"));
            args.addExpression(new ConstantExpression(original.getName()));

            for (int i = 0; i < newParams.length; i++) {
                final Parameter newParam = new Parameter(nonGeneric(params[i].getType()), params[i].getName());
                newParam.setInitialExpression(params[i].getInitialExpression());
                newParams[i] = newParam;
View Full Code Here

            }
        }

        private static FieldNode addActorFieldToClass(final ClassNode classNode, final String logFieldName, final String actorGroupName) {
            final ArgumentListExpression args = new ArgumentListExpression();
            args.addExpression(new ConstantExpression(actorGroupName));

            return classNode.addField(logFieldName,
                    Modifier.FINAL | Modifier.TRANSIENT | Modifier.PROTECTED,
                    new ClassNode(InternalActor.class),
                    new MethodCallExpression(
View Full Code Here

         return new VariableExpression(name, objectCN);
      }
      else
      {
         Expression left = createExpr(packageName.subList(0, packageName.size() - 1));
         ConstantExpression right = new ConstantExpression(packageName.get(packageName.size() - 1));
         return new PropertyExpression(left, right);
      }
   }
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.ast.expr.ConstantExpression

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.