java.lang.Object
io.github.projectunified.craftcommand.processor.LocalNames

public final class LocalNames extends Object
Allocates the local variable names of one generated command slot.

Names are derived from the parameters the user declared, so generated code reads num1 and num2 rather than param_0 and param_1. Names that would shadow a local the generated code itself relies on are given a unique suffix instead.

  • Constructor Details

    • LocalNames

      public LocalNames()
  • Method Details

    • declaredName

      public static String declaredName(ParameterModel parameter)
      The identifier a parameter was declared with in the command class.
      Parameters:
      parameter - the parameter model
      Returns:
      the declared identifier, or null when the parameter has no element
    • allocate

      public String allocate(String preferred, String fallback)
      Allocates a local for a parameter, based on the name the user declared for it.
      Parameters:
      preferred - the declared name, or null to use the fallback
      fallback - the name to use when the declared name is unusable
      Returns:
      a name that is unique within the generated method