use of groovy.transform.options.PropertyHandler in project groovy by apache.
the class ImmutableASTTransformation method visit.
@Override
public void visit(final ASTNode[] nodes, final 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) {
final GroovyClassLoader classLoader = compilationUnit != null ? compilationUnit.getTransformLoader() : source.getClassLoader();
final PropertyHandler handler = PropertyHandler.createPropertyHandler(this, classLoader, (ClassNode) parent);
if (handler == null || !handler.validateAttributes(this, anno))
return;
doMakeImmutable((ClassNode) parent, anno, handler);
}
}
use of groovy.transform.options.PropertyHandler in project groovy by apache.
the class RecordTypeASTTransformation method visit.
@Override
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) {
final GroovyClassLoader classLoader = compilationUnit != null ? compilationUnit.getTransformLoader() : source.getClassLoader();
final PropertyHandler handler = PropertyHandler.createPropertyHandler(this, classLoader, (ClassNode) parent);
if (handler == null)
return;
if (!handler.validateAttributes(this, anno))
return;
doProcessRecordType((ClassNode) parent, handler);
}
}
use of groovy.transform.options.PropertyHandler in project groovy by apache.
the class MapConstructorASTTransformation method visit.
@Override
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;
boolean includeFields = memberHasValue(anno, "includeFields", true);
boolean includeProperties = !memberHasValue(anno, "includeProperties", false);
boolean includeSuperProperties = memberHasValue(anno, "includeSuperProperties", true);
boolean includeSuperFields = memberHasValue(anno, "includeSuperFields", true);
boolean includeStatic = memberHasValue(anno, "includeStatic", true);
boolean allProperties = memberHasValue(anno, "allProperties", true);
boolean noArg = memberHasValue(anno, "noArg", true);
boolean specialNamedArgHandling = !memberHasValue(anno, "specialNamedArgHandling", false);
List<String> excludes = getMemberStringList(anno, "excludes");
List<String> includes = getMemberStringList(anno, "includes");
boolean allNames = memberHasValue(anno, "allNames", true);
if (!checkIncludeExcludeUndefinedAware(anno, excludes, includes, MY_TYPE_NAME))
return;
if (!checkPropertyList(cNode, includes, "includes", anno, MY_TYPE_NAME, includeFields, includeSuperProperties, allProperties))
return;
if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields, includeSuperProperties, allProperties))
return;
final GroovyClassLoader classLoader = compilationUnit != null ? compilationUnit.getTransformLoader() : source.getClassLoader();
final PropertyHandler handler = PropertyHandler.createPropertyHandler(this, classLoader, cNode);
if (handler == null)
return;
if (!handler.validateAttributes(this, anno))
return;
Expression pre = anno.getMember("pre");
if (pre != null && !(pre instanceof ClosureExpression)) {
addError("Expected closure value for annotation parameter 'pre'. Found " + pre, cNode);
return;
}
Expression post = anno.getMember("post");
if (post != null && !(post instanceof ClosureExpression)) {
addError("Expected closure value for annotation parameter 'post'. Found " + post, cNode);
return;
}
createConstructors(this, anno, handler, cNode, includeFields, includeProperties, includeSuperProperties, includeSuperFields, noArg, allNames, allProperties, specialNamedArgHandling, includeStatic, excludes, includes, (ClosureExpression) pre, (ClosureExpression) post, source);
if (pre != null) {
anno.setMember("pre", new ClosureExpression(Parameter.EMPTY_ARRAY, EmptyStatement.INSTANCE));
}
if (post != null) {
anno.setMember("post", new ClosureExpression(Parameter.EMPTY_ARRAY, EmptyStatement.INSTANCE));
}
}
}
use of groovy.transform.options.PropertyHandler in project groovy by apache.
the class TupleConstructorASTTransformation method visit.
@Override
public void visit(final ASTNode[] nodes, final 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;
boolean includeFields = memberHasValue(anno, "includeFields", true);
boolean includeProperties = !memberHasValue(anno, "includeProperties", false);
boolean includeSuperFields = memberHasValue(anno, "includeSuperFields", true);
boolean includeSuperProperties = memberHasValue(anno, "includeSuperProperties", true);
boolean allProperties = memberHasValue(anno, "allProperties", true);
List<String> excludes = getMemberStringList(anno, "excludes");
List<String> includes = getMemberStringList(anno, "includes");
boolean allNames = memberHasValue(anno, "allNames", true);
if (!checkIncludeExcludeUndefinedAware(anno, excludes, includes, MY_TYPE_NAME))
return;
if (!checkPropertyList(cNode, includes, "includes", anno, MY_TYPE_NAME, includeFields, includeSuperProperties, allProperties, includeSuperFields, false))
return;
if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields, includeSuperProperties, allProperties, includeSuperFields, false))
return;
GroovyClassLoader classLoader = compilationUnit != null ? compilationUnit.getTransformLoader() : source.getClassLoader();
PropertyHandler handler = PropertyHandler.createPropertyHandler(this, classLoader, cNode);
if (handler == null)
return;
if (!handler.validateAttributes(this, anno))
return;
Expression pre = anno.getMember("pre");
if (pre != null && !(pre instanceof ClosureExpression)) {
addError("Expected closure value for annotation parameter 'pre'. Found " + pre, cNode);
return;
}
Expression post = anno.getMember("post");
if (post != null && !(post instanceof ClosureExpression)) {
addError("Expected closure value for annotation parameter 'post'. Found " + post, cNode);
return;
}
createConstructor(this, anno, cNode, includeFields, includeProperties, includeSuperFields, includeSuperProperties, excludes, includes, allNames, allProperties, sourceUnit, handler, (ClosureExpression) pre, (ClosureExpression) post);
if (pre != null) {
anno.setMember("pre", new ClosureExpression(Parameter.EMPTY_ARRAY, EmptyStatement.INSTANCE));
}
if (post != null) {
anno.setMember("post", new ClosureExpression(Parameter.EMPTY_ARRAY, EmptyStatement.INSTANCE));
}
}
}
Aggregations