use of groovy.transform.NamedParam in project groovy by apache.
the class NamedVariantASTTransformation method processDelegateParam.
private boolean processDelegateParam(final MethodNode mNode, final Parameter mapParam, final ArgumentListExpression args, final List<String> propNames, final Parameter fromParam, final boolean coerce) {
if (isInnerClass(fromParam.getType()) && mNode.isStatic()) {
addError("Error during " + NAMED_VARIANT + " processing. Delegate type '" + fromParam.getType().getNameWithoutPackage() + "' is an inner class which is not supported.", mNode);
return false;
}
Set<String> names = new HashSet<>();
List<PropertyNode> props = getAllProperties(names, fromParam.getType(), true, false, false, true, false, true);
for (String name : names) {
if (hasDuplicates(this, mNode, propNames, name))
return false;
}
for (PropertyNode prop : props) {
// create annotation @NamedParam(value='name', type=PropertyType)
AnnotationNode namedParam = new AnnotationNode(NAMED_PARAM_TYPE);
namedParam.addMember("value", constX(prop.getName()));
namedParam.addMember("type", classX(prop.getType()));
mapParam.addAnnotation(namedParam);
}
Expression[] subMapArgs = names.stream().map(name -> constX(name)).toArray(Expression[]::new);
Expression delegateMap = callX(varX(mapParam), "subMap", args(subMapArgs));
args.addExpression(castX(fromParam.getType(), delegateMap));
return true;
}
Aggregations