Search in sources :

Example 1 with MethodNodeUtils

use of org.apache.groovy.ast.tools.MethodNodeUtils in project groovy by apache.

the class RecordTypeASTTransformation method adjustPropertyForShallowImmutability.

// guarantee shallow immutability but property handler may do defensive copying
private static void adjustPropertyForShallowImmutability(ClassNode cNode, PropertyNode pNode, PropertyHandler handler) {
    final FieldNode fNode = pNode.getField();
    fNode.setModifiers((pNode.getModifiers() & (~ACC_PUBLIC)) | ACC_FINAL | ACC_PRIVATE);
    boolean isGetterDefined = cNode.getDeclaredMethods(pNode.getName()).stream().anyMatch(MethodNodeUtils::isGetterCandidate);
    if (!isGetterDefined) {
        pNode.setGetterName(pNode.getName());
        Statement getter = handler.createPropGetter(pNode);
        if (getter != null) {
            pNode.setGetterBlock(getter);
        }
    }
}
Also used : MethodNodeUtils(org.apache.groovy.ast.tools.MethodNodeUtils) FieldNode(org.codehaus.groovy.ast.FieldNode) Statement(org.codehaus.groovy.ast.stmt.Statement) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement)

Aggregations

MethodNodeUtils (org.apache.groovy.ast.tools.MethodNodeUtils)1 FieldNode (org.codehaus.groovy.ast.FieldNode)1 Statement (org.codehaus.groovy.ast.stmt.Statement)1 SwitchStatement (org.codehaus.groovy.ast.stmt.SwitchStatement)1