Example #1
0
 /**
  * Converts {@link OperatorPortDeclaration} into a member of {@link OperatorInfo}.
  *
  * @param var target port declaration
  * @param position the factory parameter position
  * @return related meta-data
  * @throws IllegalArgumentException if some parameters were {@code null}
  */
 public Expression toMetaData(OperatorPortDeclaration var, int position) {
   Precondition.checkMustNotBeNull(var, "var"); // $NON-NLS-1$
   NamedType type;
   TypeMirror representation = var.getType().getRepresentation();
   List<AnnotationElement> members = new ArrayList<>();
   members.add(
       factory.newAnnotationElement(
           factory.newSimpleName("name"), // $NON-NLS-1$
           Models.toLiteral(factory, var.getName())));
   members.add(
       factory.newAnnotationElement(
           factory.newSimpleName("type"), // $NON-NLS-1$
           factory.newClassLiteral(t(environment.getErasure(representation)))));
   if (var.getKind() == OperatorPortDeclaration.Kind.INPUT) {
     type = (NamedType) t(OperatorInfo.Input.class);
     members.add(
         factory.newAnnotationElement(
             factory.newSimpleName("position"), // $NON-NLS-1$
             Models.toLiteral(factory, position)));
     String typeVariable = getTypeVariableName(representation);
     if (typeVariable != null) {
       members.add(
           factory.newAnnotationElement(
               factory.newSimpleName("typeVariable"), // $NON-NLS-1$
               Models.toLiteral(factory, typeVariable)));
     }
   } else if (var.getKind() == OperatorPortDeclaration.Kind.OUTPUT) {
     type = (NamedType) t(OperatorInfo.Output.class);
     String typeVariable = getTypeVariableName(representation);
     if (typeVariable != null) {
       members.add(
           factory.newAnnotationElement(
               factory.newSimpleName("typeVariable"), // $NON-NLS-1$
               Models.toLiteral(factory, typeVariable)));
     }
   } else if (var.getKind() == OperatorPortDeclaration.Kind.CONSTANT) {
     type = (NamedType) t(OperatorInfo.Parameter.class);
     members.add(
         factory.newAnnotationElement(
             factory.newSimpleName("position"), // $NON-NLS-1$
             Models.toLiteral(factory, position)));
     String typeVariable = getTypeVariableNameInClass(representation);
     if (typeVariable != null) {
       members.add(
           factory.newAnnotationElement(
               factory.newSimpleName("typeVariable"), // $NON-NLS-1$
               Models.toLiteral(factory, typeVariable)));
     }
   } else {
     throw new AssertionError(var);
   }
   return factory.newNormalAnnotation(type, members);
 }
Example #2
0
  /**
   * Converts {@link OperatorPortDeclaration} into an operator factory method parameter.
   *
   * @param var target port declaration
   * @param name the actual parameter name
   * @return related parameter declaration
   * @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<>();
      for (String entry : key.getGroupProperties()) {
        group.addAll(
            new AttributeBuilder(factory)
                .annotation(
                    t(KeyInfo.Group.class),
                    "expression", //$NON-NLS-1$
                    Models.toLiteral(factory, entry))
                .toAnnotations());
      }
      List<Expression> order = new ArrayList<>();
      for (ShuffleKey.Order entry : key.getOrderings()) {
        order.addAll(
            new AttributeBuilder(factory)
                .annotation(
                    t(KeyInfo.Order.class),
                    "direction",
                    new TypeBuilder(factory, t(KeyInfo.Direction.class)) // $NON-NLS-1$
                        .field(entry.getDirection().name())
                        .toExpression(),
                    "expression",
                    Models.toLiteral(factory, entry.getProperty())) // $NON-NLS-1$
                .toAnnotations());
      }

      attributes.annotation(
          t(KeyInfo.class),
          "group",
          factory.newArrayInitializer(group), // $NON-NLS-1$
          "order",
          factory.newArrayInitializer(order)); // $NON-NLS-1$
    }
    return factory.newFormalParameterDeclaration(
        attributes.toAttributes(), toSourceType(var.getType().getRepresentation()), false, name, 0);
  }