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);
}
}
}
Aggregations