* @throws IllegalArgumentException if some parameters were {@code null}
*/
public FormalParameterDeclaration toFactoryMethodInput(OperatorPortDeclaration var, SimpleName name) {
Precondition.checkMustNotBeNull(var, "var"); //$NON-NLS-1$
Precondition.checkMustNotBeNull(name, "name"); //$NON-NLS-1$
AttributeBuilder attributes = new AttributeBuilder(factory);
ShuffleKey key = var.getShuffleKey();
if (key != null) {
List<Expression> group = new ArrayList<Expression>();
for (String entry : key.getGroupProperties()) {
group.addAll(new AttributeBuilder(factory)
.annotation(t(KeyInfo.Group.class), "expression", Models.toLiteral(factory, entry))
.toAnnotations());
}
List<Expression> order = new ArrayList<Expression>();
for (ShuffleKey.Order entry : key.getOrderings()) {
order.addAll(new AttributeBuilder(factory)
.annotation(
t(KeyInfo.Order.class),
"direction", new TypeBuilder(factory, t(KeyInfo.Direction.class))
.field(entry.getDirection().name())
.toExpression(),
"expression", Models.toLiteral(factory, entry.getProperty()))
.toAnnotations());
}
attributes.annotation(
t(KeyInfo.class),
"group", factory.newArrayInitializer(group),
"order", factory.newArrayInitializer(order));
}
return factory.newFormalParameterDeclaration(
attributes.toAttributes(),
toSourceType(var.getType().getRepresentation()),
false,
name,
0);
}