Class DataClassCodecGenerator
java.lang.Object
eu.cloudnetservice.driver.impl.network.object.data.DataClassCodecGenerator
Internal generator for data class codec implementations in runtime.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ClassDescprivate static final ClassDescprivate static final ClassDescprivate static final ClassDescprivate static final ClassDescprivate static final ClassDescprivate static final ClassDescprivate static final Stringprivate static final Field[]private static final Stringprivate static final Stringprivate static final MethodTypeDescprivate static final MethodTypeDescprivate static final MethodTypeDescprivate static final MethodTypeDescprivate static final MethodTypeDescprivate static final MethodTypeDescprivate static final MethodTypeprivate static final Stringprivate static final Stringprivate static final Stringprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull DataClassCodecGenerates the codec implementation for the given class hierarchy, including all given fields.private static MethodHandles.LookupGenerates and defines the codec for the given target class.private static voidgenerateDeserializeMethod(@NonNull CodeBuilder code, @NonNull List<Field> allFields, @NonNull ClassDesc targetClassDesc, @NonNull ClassDesc generatingClassDesc) Generates the deserialize method for the root type of the hierarchy.private static voidgenerateSerializeMethod(@NonNull CodeBuilder code, @NonNull Class<?> target, @NonNull List<Field> allFields, @NonNull ClassDesc targetClassDesc, @NonNull ClassDesc generatingClassDesc) Generates the serialize method of the data class codec for the given target type.Finds and validates the getter method provided via an annotation for the given field.
-
Field Details
-
FIELDS_FIELD_NAME
- See Also:
-
SUPER_CODEC_NAME
- See Also:
-
SERIALIZE_METHOD_NAME
- See Also:
-
DESERIALIZE_METHOD_NAME
- See Also:
-
CD_TYPE
-
CD_FIELD
-
CD_FIELD_ARRAY
-
FIELD_GET_TYPE_NAME
- See Also:
-
MT_FIELD_GET_TYPE
-
CD_DATA_BUF
-
CD_DATA_BUF_MUT
-
CD_OBJECT_MAPPER
-
CD_DATA_CLASS_CODEC
-
OBJECT_MAPPER_READ_NAME
- See Also:
-
OBJECT_MAPPER_WRITE_NAME
- See Also:
-
MT_OBJECT_MAPPER_READ
-
MT_OBJECT_MAPPER_WRITE
-
MT_CONSTRUCTOR
-
MT_DESERIALIZE
-
MT_SERIALIZE
-
EMPTY_FIELD_ARRAY
-
MTR_CONSTRUCTOR
-
-
Constructor Details
-
DataClassCodecGenerator
private DataClassCodecGenerator()
-
-
Method Details
-
generateClassCodec
@NonNull public static @NonNull DataClassCodec generateClassCodec(@NonNull @NonNull List<Field> allFields, @NonNull @NonNull List<Class<?>> classHierarchy) Generates the codec implementation for the given class hierarchy, including all given fields. The root class is assumed to be the first element in the given class hierarchy list.- Parameters:
allFields- all fields in the class hierarchy that are subject to serialization.classHierarchy- the full class hierarchy that was inspected for fields to include.- Returns:
- an instance of the generated codec for the root target class.
- Throws:
NullPointerException- if the given fields or class hierarchy is null.NoSuchElementException- if the given hierarchy list has no elements.
-
generateClassCodecClass
@NonNull private static MethodHandles.Lookup generateClassCodecClass(@NonNull @NonNull Class<?> target, @NonNull @NonNull List<Field> allFields, boolean root) Generates and defines the codec for the given target class. The deserialized method is only properly implemented if this is the root type, in all other cases the deserialize method will just return null.- Parameters:
target- the target class to create the codec for.allFields- all fields that are subject to serialization, include those not defined in the given target.root- if the given target class is the root class for which the codec is generated.- Returns:
- a lookup with full privileged access to the defined codec class.
- Throws:
NullPointerException- if the given target class or fields list is null.
-
generateSerializeMethod
private static void generateSerializeMethod(@NonNull @NonNull CodeBuilder code, @NonNull @NonNull Class<?> target, @NonNull @NonNull List<Field> allFields, @NonNull @NonNull ClassDesc targetClassDesc, @NonNull @NonNull ClassDesc generatingClassDesc) Generates the serialize method of the data class codec for the given target type.- Parameters:
code- the code builder of the current codec class.target- the target class for which the codec is getting implemented.allFields- all fields, include those that are not defined in the given target class.targetClassDesc- the class descriptor of the target class.generatingClassDesc- the class descriptor of the class that is being generated.- Throws:
NullPointerException- if one of the parameters is null.
-
generateDeserializeMethod
private static void generateDeserializeMethod(@NonNull @NonNull CodeBuilder code, @NonNull @NonNull List<Field> allFields, @NonNull @NonNull ClassDesc targetClassDesc, @NonNull @NonNull ClassDesc generatingClassDesc) Generates the deserialize method for the root type of the hierarchy.- Parameters:
code- the code builder of the current codec class.allFields- all fields in the class hierarchy.targetClassDesc- the class descriptor of the target class.generatingClassDesc- the class descriptor of the class that is being generated.- Throws:
NullPointerException- if one of the parameters is null.
-
getAndValidateGetterMethod
Finds and validates the getter method provided via an annotation for the given field. This method returns null in case no specific getter is provided for the given field.- Parameters:
field- the field to find the getter method for.- Returns:
- the getter method for the given field, null if none is specifically provided.
- Throws:
NullPointerException- if the given field is null.
-