Search in sources :

Example 1 with AutoCloneStyle

use of groovy.transform.AutoCloneStyle in project groovy-core by groovy.

the class AutoCloneASTTransformation method visit.

public void visit(ASTNode[] nodes, SourceUnit source) {
    init(nodes, source);
    AnnotatedNode parent = (AnnotatedNode) nodes[1];
    AnnotationNode anno = (AnnotationNode) nodes[0];
    if (!MY_TYPE.equals(anno.getClassNode()))
        return;
    if (parent instanceof ClassNode) {
        ClassNode cNode = (ClassNode) parent;
        if (!checkNotInterface(cNode, MY_TYPE_NAME))
            return;
        cNode.addInterface(CLONEABLE_TYPE);
        boolean includeFields = memberHasValue(anno, "includeFields", true);
        AutoCloneStyle style = getStyle(anno, "style");
        List<String> excludes = getMemberList(anno, "excludes");
        List<FieldNode> list = getInstancePropertyFields(cNode);
        if (includeFields) {
            list.addAll(getInstanceNonPropertyFields(cNode));
        }
        if (style == null)
            style = AutoCloneStyle.CLONE;
        switch(style) {
            case COPY_CONSTRUCTOR:
                createCloneCopyConstructor(cNode, list, excludes);
                break;
            case SERIALIZATION:
                createCloneSerialization(cNode);
                break;
            case CLONE:
                createClone(cNode, list, excludes);
                break;
            case SIMPLE:
                createSimpleClone(cNode, list, excludes);
                break;
        }
    }
}
Also used : AutoCloneStyle(groovy.transform.AutoCloneStyle) ClassNode(org.codehaus.groovy.ast.ClassNode) FieldNode(org.codehaus.groovy.ast.FieldNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) AnnotatedNode(org.codehaus.groovy.ast.AnnotatedNode)

Example 2 with AutoCloneStyle

use of groovy.transform.AutoCloneStyle in project groovy by apache.

the class AutoCloneASTTransformation method visit.

public void visit(ASTNode[] nodes, SourceUnit source) {
    init(nodes, source);
    AnnotatedNode parent = (AnnotatedNode) nodes[1];
    AnnotationNode anno = (AnnotationNode) nodes[0];
    if (!MY_TYPE.equals(anno.getClassNode()))
        return;
    if (parent instanceof ClassNode) {
        ClassNode cNode = (ClassNode) parent;
        if (!checkNotInterface(cNode, MY_TYPE_NAME))
            return;
        cNode.addInterface(CLONEABLE_TYPE);
        boolean includeFields = memberHasValue(anno, "includeFields", true);
        AutoCloneStyle style = getStyle(anno, "style");
        List<String> excludes = getMemberStringList(anno, "excludes");
        if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields))
            return;
        List<FieldNode> list = getInstancePropertyFields(cNode);
        if (includeFields) {
            list.addAll(getInstanceNonPropertyFields(cNode));
        }
        if (style == null)
            style = AutoCloneStyle.CLONE;
        switch(style) {
            case COPY_CONSTRUCTOR:
                createCloneCopyConstructor(cNode, list, excludes);
                break;
            case SERIALIZATION:
                createCloneSerialization(cNode);
                break;
            case SIMPLE:
                createSimpleClone(cNode, list, excludes);
                break;
            default:
                createClone(cNode, list, excludes);
                break;
        }
    }
}
Also used : AutoCloneStyle(groovy.transform.AutoCloneStyle) ClassNode(org.codehaus.groovy.ast.ClassNode) FieldNode(org.codehaus.groovy.ast.FieldNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) AnnotatedNode(org.codehaus.groovy.ast.AnnotatedNode)

Aggregations

AutoCloneStyle (groovy.transform.AutoCloneStyle)2 AnnotatedNode (org.codehaus.groovy.ast.AnnotatedNode)2 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)2 ClassNode (org.codehaus.groovy.ast.ClassNode)2 FieldNode (org.codehaus.groovy.ast.FieldNode)2