function keywordsForAttributes()

in src/plugins/algebraic-type-case-matching.ts [15:59]


function keywordsForAttributes(
  algebraicType: AlgebraicType.Type,
  attributes: AlgebraicType.SubtypeAttribute[],
): ObjC.Keyword[] {
  const assumeNonnull = algebraicType.includes.indexOf('RMAssumeNonnull') > 0;
  const usesNullability =
    assumeNonnull ||
    attributes.some((attribute) =>
      attribute.nullability.match(
        /* inherited */ () => false,
        /* nonnull   */ () => true,
        /* nullable  */ () => true,
      ),
    );

  return attributes.map((attribute, index) => {
    let name = attribute.name;
    let reference = attribute.type.reference;

    if (usesNullability) {
      // Use the underscored nullability type annotations as the lowercased type
      // annotations are not compatible with a pointer to a pointer.
      reference = attribute.nullability.match(
        () => reference,
        () => (assumeNonnull ? reference : `${reference} _Nonnull`),
        () => `${reference} _Nullable`,
      );
      reference = reference.concat(' * _Nullable');
    } else {
      reference = reference.concat(' *');
    }

    return {
      argument: {
        name: name,
        modifiers: [],
        type: {
          name: attribute.type.name,
          reference: reference,
        },
      },
      name: index !== 0 ? name : `is${StringUtils.capitalize(name)}`,
    };
  });
}