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);
            String grailsVersion = getGrailsVersion();
            if(grailsVersion == null) {
                grailsVersion = System.getProperty("grails.version");
            }
            if(grailsVersion != null) {
                enhancedAnnotationNode.setMember("version", new ConstantExpression(grailsVersion));
            }
            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) {
                    if(expression instanceof ConstantExpression && feature.equals(((ConstantExpression)expression).getValue())) {
                        exists = true;
                        break;
                    }
                }
                if(!exists) {
                    featureNameExpressions.add(new ConstantExpression(feature));
                }
            }
        }

        return enhancedAnnotationNode;
    }
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 ) ; String grailsVersion = getGrailsVersion ( ) ; if ( grailsVersion == null ) { grailsVersion = System . getProperty ( "grails.version" ) ; } if ( grailsVersion != null ) { enhancedAnnotationNode . setMember ( "version" , new ConstantExpression ( grailsVersion ) ) ; } 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 ) { if ( expression instanceof ConstantExpression && feature . equals ( ( ( ConstantExpression ) expression ) . getValue ( ) ) ) { exists = true ; break ; } } if ( ! exists ) { featureNameExpressions . add ( new ConstantExpression ( feature ) ) ; } } } return enhancedAnnotationNode ; }
Add the grails.artefact.Enhanced annotation to classNode if it does not already exist and ensure that
all of the features in the enhancedFor array are represented in the enhancedFor attribute of the
Enhanced annnotation
@param classNode the class to add the Enhanced annotation to
@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