Class DataClassInvokerGenerator
java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.object.data.DataClassInvokerGenerator
A generator for data class invoker based on runtime code generation.
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents a writer for an instance of a data class generated by this generator.static interfaceRepresents a creator for an instance of a data class generated by this generator. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final String[]private static final Stringprivate static final String[]private static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncommonFilter(@NonNull Field field) A common filter to find a getter method based on the field input using the fields return type.createInstanceCreator(@NonNull Class<?> clazz, @NonNull Type[] types) Generates an instance creator for the given class using the constructor with the given types.createWriter(@NonNull Class<?> clazz, @NonNull Collection<Field> fields) Creates an instance writer for the given data class writing all values of all fields provided to this methods to the buffer.findGetterForField(@NonNull Collection<Method> methods, @NonNull Field field, @NonNull Predicate<Method> extraFilter) Finds the best matching getter method for the given field.
-
Field Details
-
SUPER
- See Also:
-
TYPES_DESC
-
INSTANCE_CREATOR
-
MAKE_INSTANCE_DESCRIPTOR
-
INFO_WRITER
-
WRITE_INFORMATION_DESCRIPTOR
-
DATA_BUF_NAME
-
READ_OBJECT_DESC
-
WRITE_OBJECT_DESC
-
INSTANCE_CREATOR_NAME_FORMAT
- See Also:
-
INFORMATION_WRITE_NAME_FORMAT
- See Also:
-
-
Constructor Details
-
DataClassInvokerGenerator
private DataClassInvokerGenerator()
-
-
Method Details
-
createInstanceCreator
@NonNull public static @NonNull DataClassInvokerGenerator.DataClassInstanceCreator createInstanceCreator(@NonNull @NonNull Class<?> clazz, @NonNull @NonNull Type[] types) 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
@NonNull public static @NonNull DataClassInvokerGenerator.DataClassInformationWriter createWriter(@NonNull @NonNull Class<?> clazz, @NonNull @NonNull Collection<Field> fields) 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
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.
-