Class StructGenerator

java.lang.Object
edu.wpi.first.util.struct.StructGenerator

public final class StructGenerator extends Object
A utility class for procedurally generating Structs from records and enums.
  • Method Details

    • addCustomStruct

      public static <T> void addCustomStruct(Class<T> clazz, Struct<T> struct, boolean override)
      Add a custom struct to the structifier.
      Type Parameters:
      T - The type the struct is for.
      Parameters:
      clazz - The class of the type.
      struct - The struct to add.
      override - Whether to override an existing struct. An existing struct could mean the type already has a struct field and implemnts StructSerializable or that the type is already in the custom struct map.
    • genRecord

      public static <R extends Record> Struct<R> genRecord(Class<R> recordClass)
      Generates a Struct for the given Record class. If a Struct cannot be generated from the Record, the errors encountered will be printed and a no-op Struct will be returned.
      Type Parameters:
      R - The type of the record.
      Parameters:
      recordClass - The class of the record.
      Returns:
      The generated struct.
    • genEnum

      public static <E extends Enum<E>> Struct<E> genEnum(Class<E> enumClass)
      Generates a Struct for the given Enum class. If a Struct cannot be generated from the Enum, the errors encountered will be printed and a no-op Struct will be returned.
      Type Parameters:
      E - The type of the enum.
      Parameters:
      enumClass - The class of the enum.
      Returns:
      The generated struct.