Examples of AnnotationNode


Examples of org.codehaus.groovy.ast.AnnotationNode

     * @param enhancedFor an array of feature names to include in the enhancedFor attribute of the annotation
     * @return the AnnotationNode associated with the Enhanced annotation for classNode
     * @see Enhanced
     */
    public static AnnotationNode addEnhancedAnnotation(final ClassNode classNode, final String... enhancedFor) {
        final AnnotationNode enhancedAnnotationNode;
        final List<AnnotationNode> annotations = classNode.getAnnotations(ENHANCED_CLASS_NODE);
        if (annotations.isEmpty()) {
            enhancedAnnotationNode = new AnnotationNode(ENHANCED_CLASS_NODE);
            enhancedAnnotationNode.setMember("version", new ConstantExpression(GrailsUtil.getGrailsVersion()));
            classNode.addAnnotation(enhancedAnnotationNode);
        } else {
            enhancedAnnotationNode = annotations.get(0);
        }
       
        if(enhancedFor != null && enhancedFor.length > 0) {
            ListExpression enhancedForArray = (ListExpression) enhancedAnnotationNode.getMember("enhancedFor");
            if(enhancedForArray == null) {
                enhancedForArray = new ListExpression();
                enhancedAnnotationNode.setMember("enhancedFor", enhancedForArray);
            }
            final List<Expression> featureNameExpressions = enhancedForArray.getExpressions();
            for(final String feature : enhancedFor) {
                boolean exists = false;
                for(Expression expression : featureNameExpressions) {
View Full Code Here

Examples of org.codehaus.groovy.ast.AnnotationNode

     * @param skip
     * @return The annotated method
     */
    public static AnnotatedNode addCompileStaticAnnotation(AnnotatedNode annotatedNode, boolean skip) {
        if(annotatedNode != null) {
            AnnotationNode an = new AnnotationNode(COMPILESTATIC_CLASS_NODE);
            if(skip) {
                an.addMember("value", new PropertyExpression(new ClassExpression(TYPECHECKINGMODE_CLASS_NODE), "SKIP"));
            }
            annotatedNode.addAnnotation(an);
            if(!skip) {
                annotatedNode.getDeclaringClass().addTransform(StaticCompileTransformation.class, an);
            }
View Full Code Here

Examples of org.codehaus.groovy.ast.AnnotationNode

        final List<AnnotationNode> annotationsToCopy = from.getAnnotations();
        for(final AnnotationNode node : annotationsToCopy) {
            String annotationClassName = node.getClassNode().getName();
            if((excluded==null || !excluded.contains(annotationClassName)) &&
               (included==null || included.contains(annotationClassName))) {
                final AnnotationNode copyOfAnnotationNode = cloneAnnotation(node);
                to.addAnnotation(copyOfAnnotationNode);
            }
        }
    }
View Full Code Here

Examples of org.codehaus.groovy.ast.AnnotationNode

            }
        }
    }

    public static AnnotationNode cloneAnnotation(final AnnotationNode node) {
        final AnnotationNode copyOfAnnotationNode = new AnnotationNode(node.getClassNode());
        final Map<String, Expression> members = node.getMembers();
        for(final Map.Entry<String, Expression> entry : members.entrySet()) {
            copyOfAnnotationNode.addMember(entry.getKey(), entry.getValue());
        }
        return copyOfAnnotationNode;
    }
View Full Code Here

Examples of org.codehaus.groovy.ast.AnnotationNode

        return copyOfAnnotationNode;
    }
   
    public static void filterAnnotations(final AnnotatedNode annotatedNode, final Set<String> classNamesToRetain, final Set<String> classNamesToRemove) {
        for(Iterator<AnnotationNode> iterator = annotatedNode.getAnnotations().iterator(); iterator.hasNext(); ) {
            final AnnotationNode node = iterator.next();
            String annotationClassName = node.getClassNode().getName();
            if((classNamesToRemove==null || classNamesToRemove.contains(annotationClassName)) &&
               (classNamesToRetain==null || !classNamesToRetain.contains(annotationClassName))) {
                iterator.remove();
            }
        }
View Full Code Here

Examples of org.codehaus.groovy.ast.AnnotationNode

//    static final Log LOG = LogFactory.getLog(LineNumberTransform)

    public void visit(ASTNode[] nodes, SourceUnit source) {
        List<ClassNode> classes = source.getAST().getClasses();

        AnnotationNode annotation = null;
        for (ClassNode clazz : classes) {
            annotation = findAnnotation(clazz);
            if (annotation != null) {
                break;
            }
View Full Code Here

Examples of org.codehaus.groovy.ast.AnnotationNode

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

        AnnotatedNode parent = (AnnotatedNode) astNodes[1];
        AnnotationNode node = (AnnotationNode) astNodes[0];
        if (!VALIDATEABLE_CLASS_NODE.equals(node.getClassNode())) {
            return;
        }

        ClassNode cNode = (ClassNode) parent;
        String cName = cNode.getName();
        if (cNode.isInterface()) {
            throw new RuntimeException("Error processing interface '" + cName + "'.  @Validateable not allowed for interfaces.");
        }

        // GRAILS-11416 - Allow override of default nullability
        boolean defaultNullable = false;
        Expression nullable = node.getMember("nullable");
        if (nullable != null) {
            defaultNullable = Boolean.parseBoolean(nullable.getText());
        }

        new DefaultASTValidateableHelper().injectValidateableCode(cNode, defaultNullable);
View Full Code Here

Examples of org.codehaus.groovy.ast.AnnotationNode

        if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
            throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
        }

        AnnotatedNode parent = (AnnotatedNode) nodes[1];
        AnnotationNode annotationNode = (AnnotationNode) nodes[0];

        if (parent instanceof FieldNode) {
            Expression value = annotationNode.getMember("value");
            FieldNode fieldNode = (FieldNode) parent;
            final ClassNode type = fieldNode.getType();
            final ClassNode owner = fieldNode.getOwner();
            ClassNode supportedType = owner;
            if (value instanceof ClassExpression) {
View Full Code Here

Examples of org.codehaus.groovy.ast.AnnotationNode

        if (isCommandObjectAction(parameters)) {
            ListExpression initArray = new ListExpression();
            for (Parameter parameter : parameters) {
                initArray.addExpression(new ClassExpression(parameter.getType()));
            }
            AnnotationNode paramActionAnn = new AnnotationNode(new ClassNode(Action.class));
            paramActionAnn.setMember(ACTION_MEMBER_TARGET, initArray);
            methodNode.addAnnotation(paramActionAnn);

        } else {
            methodNode.addAnnotation(ACTION_ANNOTATION_NODE);
        }
View Full Code Here

Examples of org.codehaus.groovy.ast.AnnotationNode

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

        AnnotatedNode parent = (AnnotatedNode) astNodes[1];
        AnnotationNode node = (AnnotationNode) astNodes[0];
        if (!MY_TYPE.equals(node.getClassNode()) || !(parent instanceof ClassNode)) {
            return;
        }

        ClassNode cNode = (ClassNode) parent;
        String cName = cNode.getName();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.