Package org.codehaus.groovy.ast

Examples of org.codehaus.groovy.ast.Parameter


            if (classNode.equals(value.getDeclaringClass())) {
                Parameter[] parameters = value.getParameters();
                if (parameters != null && parameters.length == 1) {
                    final String methodName = value.getName();
                    if (methodName.startsWith("set")) {
                        final Parameter parameter = parameters[0];
                        final ClassNode paramType = parameter.getType();
                        if (!paramType.equals(new ClassNode(Object.class))) {
                            final String restOfMethodName = methodName.substring(3);
                            final String propertyName = GrailsNameUtils.getPropertyName(restOfMethodName);
                            if (!unbindablePropertyNames.contains(propertyName)) {
                                propertyNamesToIncludeInWhiteList.add(propertyName);
View Full Code Here


    private void applyDelegateAsyncTransform(ClassNode classNode, ClassNode targetApi, String fieldName) {

        List<MethodNode> methods = targetApi.getAllDeclaredMethods();

        ClassNode promisesClass = ClassHelper.make(Promises.class).getPlainNodeReference();
        MethodNode createPromiseMethodTargetWithDecorators = promisesClass.getDeclaredMethod("createPromise", new Parameter[]{new Parameter(new ClassNode(Closure.class), "c"), new Parameter(new ClassNode(List.class), "c")});

        DelegateAsyncTransactionalMethodTransformer delegateAsyncTransactionalMethodTransformer = lookupAsyncTransactionalMethodTransformer();
        for(MethodNode m : methods) {
            if (isCandidateMethod(m)) {
                MethodNode existingMethod = classNode.getMethod(m.getName(), m.getParameters());
View Full Code Here

    }

    private static Parameter[] copyParameters(Parameter[] parameterTypes) {
        Parameter[] newParameterTypes = new Parameter[parameterTypes.length];
        for (int i = 0; i < parameterTypes.length; i++) {
            Parameter parameterType = parameterTypes[i];
            ClassNode parameterTypeCN = parameterType.getType();
            ClassNode newParameterTypeCN = parameterTypeCN.getPlainNodeReference();
            if(parameterTypeCN.isUsingGenerics() && !parameterTypeCN.isGenericsPlaceHolder()) {
                newParameterTypeCN.setGenericsTypes(parameterTypeCN.getGenericsTypes());
            }
            Parameter newParameter = new Parameter(newParameterTypeCN, parameterType.getName(), parameterType.getInitialExpression());
            newParameter.addAnnotations(parameterType.getAnnotations());
            newParameterTypes[i] = newParameter;
        }
        return newParameterTypes;
    }
View Full Code Here

    }

    protected void addSetErrorsMethod(final ClassNode paramTypeClassNode) {
        final String errorsArgumentName = "$errorsArg";
        MethodNode setErrorsMethod = paramTypeClassNode.getMethod(SET_ERRORS_METHOD_NAME,
             new Parameter[] { new Parameter(ERRORS_CLASS_NODE, errorsArgumentName)});
        if (setErrorsMethod == null) {
            final Expression assignErrorsExpression = new BinaryExpression(ERRORS_EXPRESSION,
                    EQUALS_SYMBOL, new VariableExpression(errorsArgumentName));
            setErrorsMethod = new MethodNode(SET_ERRORS_METHOD_NAME,
                    Modifier.PUBLIC, ClassHelper.VOID_TYPE,
                    new Parameter[]{new Parameter(ERRORS_CLASS_NODE, errorsArgumentName)}, GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, new ExpressionStatement(assignErrorsExpression));
            paramTypeClassNode.addMethod(setErrorsMethod);
        }
    }
View Full Code Here

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

                new ArgumentListExpression(initExpression, blocking));
        ((FieldNode) fieldNode).setInitialValueExpression(newInitExpression);
    }

    private static void validatePoolClass(final Expression classExpression, final AnnotatedNode fieldNode, final SourceUnit source) {
        final Parameter[] parameters = {new Parameter(ClassHelper.CLOSURE_TYPE, "a1"),
                new Parameter(ClassHelper.boolean_TYPE, "a2")};
        final MethodNode asyncFunMethod = classExpression.getType().getMethod("asyncFun", parameters);
        if (asyncFunMethod == null || !asyncFunMethod.isStatic())
            addError("Supplied pool class has no static asyncFun(Closure, boolean) method", fieldNode, source);
    }
View Full Code Here

            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;
                args.addExpression(new VariableExpression(newParam));
            }

            final MethodNode newMethod = owner.addMethod(findSuitablePrivateMethodName(owner, original),
View Full Code Here

    public void testDetectsDuplicateMethodsForClassNoParams() throws Exception {
        checkDetectsDuplicateMethods(0, EXPECTED_DUPLICATE_METHOD_ERROR_CLASS_MESSAGE, Parameter.EMPTY_ARRAY);
    }

    public void testDetectsDuplicateMethodsForInterfaceOneParam() throws Exception {
        Parameter[] stringParam = {new Parameter(ClassHelper.STRING_TYPE, "x")};
        checkDetectsDuplicateMethods(ACC_INTERFACE, EXPECTED_DUPLICATE_METHOD_ERROR_INTERFACE_MESSAGE, stringParam);
    }
View Full Code Here

    private static void createSoftSetter(FieldNode fieldNode, ClassNode type) {
        final BlockStatement body = new BlockStatement();
        final Expression fieldExpr = varX(fieldNode);
        final String name = "set" + MetaClassHelper.capitalize(fieldNode.getName().substring(1));
        final Parameter parameter = param(type, "value");
        final Expression paramExpr = varX(parameter);
        body.addStatement(ifElseS(
                notNullX(paramExpr),
                assignS(fieldExpr, ctorX(SOFT_REF, paramExpr)),
                assignS(fieldExpr, NULL_EXPR)
View Full Code Here

        Parameter[] params = new Parameter[origParams.length];
        List<Expression> theArgs = new ArrayList<Expression>();
        Map<String, ClassNode> genericsSpec = createGenericsSpec(classNode);
        extractSuperClassGenerics(classNode, classNode.getSuperClass(), genericsSpec);
        for (int i = 0; i < origParams.length; i++) {
            Parameter p = origParams[i];
            ClassNode newType = correctToGenericsSpecRecurse(genericsSpec, p.getType());
            params[i] = p.hasInitialExpression() ? param(newType, p.getName(), p.getInitialExpression()) : param(newType, p.getName());
            theArgs.add(varX(p.getName(), newType));
        }
        if (isExisting(classNode, params)) return;
        classNode.addConstructor(consNode.getModifiers(), params, consNode.getExceptions(), block(ctorSuperS(args(theArgs))));
    }
View Full Code Here

TOP

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

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.