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