Class DataClassInvokerGenerator

java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.object.data.DataClassInvokerGenerator

public final class DataClassInvokerGenerator extends Object
A generator for data class invoker based on runtime code generation.
Since:
4.0
  • Field Details

    • SUPER

      private static final String SUPER
      See Also:
    • TYPES_DESC

      private static final String TYPES_DESC
    • INSTANCE_CREATOR

      private static final String[] INSTANCE_CREATOR
    • MAKE_INSTANCE_DESCRIPTOR

      private static final String MAKE_INSTANCE_DESCRIPTOR
    • INFO_WRITER

      private static final String[] INFO_WRITER
    • WRITE_INFORMATION_DESCRIPTOR

      private static final String WRITE_INFORMATION_DESCRIPTOR
    • DATA_BUF_NAME

      private static final String DATA_BUF_NAME
    • READ_OBJECT_DESC

      private static final String READ_OBJECT_DESC
    • WRITE_OBJECT_DESC

      private static final String WRITE_OBJECT_DESC
    • INSTANCE_CREATOR_NAME_FORMAT

      private static final String INSTANCE_CREATOR_NAME_FORMAT
      See Also:
    • INFORMATION_WRITE_NAME_FORMAT

      private static final String INFORMATION_WRITE_NAME_FORMAT
      See Also:
  • Constructor Details

    • DataClassInvokerGenerator

      private DataClassInvokerGenerator()
  • Method Details

    • createInstanceCreator

      Generates an instance creator for the given class using the constructor with the given types. The constrcutor must exist, no further checks will be made.
      Parameters:
      clazz - the class to generate for.
      types - the arguments of the constructor to generate the invoker for.
      Returns:
      the generated instance creator for the given class.
      Throws:
      NullPointerException - if either the given class or type array is null.
    • createWriter

      Creates an instance writer for the given data class writing all values of all fields provided to this methods to the buffer.
      Parameters:
      clazz - the data class to generate the writer for.
      fields - the fields to include during writing.
      Returns:
      the generated class writer based on the given fields.
      Throws:
      NullPointerException - if either the given class or field collection is null.
    • findGetterForField

      @Nullable private static @Nullable Method findGetterForField(@NonNull @NonNull Collection<Method> methods, @NonNull @NonNull Field field, @NonNull @NonNull Predicate<Method> extraFilter)
      Finds the best matching getter method for the given field. Null is returned when no method is matching the filter based on the field information and the provided extra filter. Always the method with the shortest name matching the filter is used.
      Parameters:
      methods - the methods to select the getter method from.
      field - the field for which the getter is being searched.
      extraFilter - the extra filter to apply to the base filter which is using the field information.
      Returns:
      the best matching method to the filter or null if no method is matching.
      Throws:
      NullPointerException - if one of the given arguments is null.
      See Also:
    • commonFilter

      @NonNull private static @NonNull Predicate<Method> commonFilter(@NonNull @NonNull Field field)
      A common filter to find a getter method based on the field input using the fields return type.
      Parameters:
      field - the field to find the getter for.
      Returns:
      a filter checking if the provided method has the same return type as the field.
      Throws:
      NullPointerException - if the given field is null.