Class DescriptorBuilder

java.lang.Object
ftbsc.lll.utils.DescriptorBuilder

public class DescriptorBuilder extends Object
Builds a method descriptor for you. See the documentation to better understand what this is. Parameters must be given in a specific order. Return type should always be specified for clarity, but defaults to void.
  • Constructor Details

    • DescriptorBuilder

      public DescriptorBuilder()
      Public constructor. Initialises default values.
  • Method Details

    • setReturnType

      public DescriptorBuilder setReturnType(Class<?> returnType)
      Sets the return type to the given type. Passing a Class may cause problems if used with objects outside the Java SDK. Pass the fully qualified name as a String rather than the Class object for non-standard types.
      Parameters:
      returnType - the Class object corresponding to the return type
      Returns:
      the builder's state after the change
    • setReturnType

      public DescriptorBuilder setReturnType(String returnType)
      Sets the return type to the Object specified here as a fully qualified name. Example: java.lang.String. No validity checks are performed: it's up to the user to ensure the name is correct.
      Parameters:
      returnType - the fully qualified name of the desired Object.
      Returns:
      the builder's state after the change
    • setReturnType

      public DescriptorBuilder setReturnType(String returnType, int arrayLevel)
      Sets the return type to the Object specified here as a fully qualified name (example: java.lang.String), with the specified array level. No validity checks are performed: it's up to the user to ensure the name is correct.
      Parameters:
      returnType - the fully qualified name of the desired Object.
      arrayLevel - how many levels of array are there (example: String is 0, String[] is 1, String[][] is 2, etc.)
      Returns:
      the builder's state after the change
    • addParameter

      public DescriptorBuilder addParameter(Class<?> param)
      Adds a parameter of the given class type to the method. Parameter order matters. Passing a Class may cause problems if used with objects outside the Java SDK. Pass the fully qualified name as a String rather than the Class object for non-standard types.
      Parameters:
      param - the Class object corresponding to the parameter
      Returns:
      the builder's state after the change
    • addParameter

      public DescriptorBuilder addParameter(String param)
      Adds a parameter with the type specified by the given fully qualified name to the method. Example: java.lang.String. Parameter order matters. No validity checks are performed: it's up to the user to ensure the name is correct.
      Parameters:
      param - the fully qualified name of the parameter type
      Returns:
      the builder's state after the change
    • addParameter

      public DescriptorBuilder addParameter(String param, int arrayLevel)
      Adds a parameter with the type specified by the given fully qualified name (example: java.lang.String) to the method, with the specified array level. Parameter order matters. No validity checks are performed: it's up to the user to ensure the name is correct.
      Parameters:
      param - the fully qualified name of the parameter type
      arrayLevel - how many levels of array are there (example: String is 0, String[] is 1, String[][] is 2, etc.)
      Returns:
      the builder's state after the change
    • build

      public String build()
      Builds the descriptor into a string. Example result: int m(Object[] o) becomes ([Ljava/lang/Object;)I
      Returns:
      the resulting descriptor
    • nameToDescriptor

      public static String nameToDescriptor(String name, int arrayLevel)
      Converts a fully qualified name and array level to a descriptor.
      Parameters:
      name - the fully qualified name of the object type
      arrayLevel - how many levels of array are there (example: String is 0, String[] is 1, String[][] is 2, etc.)
      Returns:
      object descriptor