Class CodeGenerationUtil
java.lang.Object
eu.cloudnetservice.utils.base.CodeGenerationUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final recordHolds all information required to generate code to box or unbox a primitive type. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final CodeGenerationUtil.PrimitiveWrapperConverterprivate static final CodeGenerationUtil.PrimitiveWrapperConverterprivate static final CodeGenerationUtil.PrimitiveWrapperConverterprivate static final CodeGenerationUtil.PrimitiveWrapperConverterprivate static final CodeGenerationUtil.PrimitiveWrapperConverterprivate static final CodeGenerationUtil.PrimitiveWrapperConverterprivate static final CodeGenerationUtil.PrimitiveWrapperConverterprivate static final CodeGenerationUtil.PrimitiveWrapperConverterprivate static final MethodHandles.Lookup.ClassOption[]private static final MethodHandles.Lookup -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidboxPrimitive(@NonNull CodeBuilder codeBuilder, @NonNull CodeGenerationUtil.PrimitiveWrapperConverter converter) Applies the conversion from a primitive type to the corresponding wrapper type on the given code builder.static voidboxPrimitive(@NonNull CodeBuilder codeBuilder, @NonNull String sourceDescriptor) Boxes the given primitive type on the stack of the given code builder (excluding void).defineClass(@NonNull Class<?> parentClass, byte[] classData) Defines a class based on the given class bytes using the class loader of the given parent class.static MethodHandles.LookupdefineNestedClass(@NonNull Class<?> hostClass, byte[] classData) Defines a hidden nest mate class in the given host class, which grants the defined class full access to everything that is present in the class (for example private members).private static voidunboxPrimitive(@NonNull CodeBuilder codeBuilder, @NonNull CodeGenerationUtil.PrimitiveWrapperConverter converter) Applies the primitive to wrapper conversion by first casting to the wrapper type and then invoking the method to convert the wrapper to the primitive representation.static voidunboxPrimitive(@NonNull CodeBuilder codeBuilder, @NonNull String targetDescriptor) Unboxes the current object on the stack of the given code builder into the given primitive type (excluding void).
-
Field Details
-
C_BYTE
-
C_SHORT
-
C_INT
-
C_LONG
-
C_FLOAT
-
C_DOUBLE
-
C_CHAR
-
C_BOOL
-
TRUSTED_LOOKUP
-
NEST_MATE_DEFINE_OPTIONS
-
-
Constructor Details
-
CodeGenerationUtil
private CodeGenerationUtil()
-
-
Method Details
-
unboxPrimitive
public static void unboxPrimitive(@NonNull @NonNull CodeBuilder codeBuilder, @NonNull @NonNull String targetDescriptor) Unboxes the current object on the stack of the given code builder into the given primitive type (excluding void).- Parameters:
codeBuilder- the code builder to append the unbox operation to.targetDescriptor- the descriptor of the target primitive type to convert to.- Throws:
NullPointerException- if the given code builder or target type is null.IllegalArgumentException- if the given target type is not primitive or void.
-
unboxPrimitive
private static void unboxPrimitive(@NonNull @NonNull CodeBuilder codeBuilder, @NonNull @NonNull CodeGenerationUtil.PrimitiveWrapperConverter converter) Applies the primitive to wrapper conversion by first casting to the wrapper type and then invoking the method to convert the wrapper to the primitive representation.- Parameters:
codeBuilder- the code builder to apply the operation to.converter- the converter information for the wrapper type.- Throws:
NullPointerException- if the given code builder or converter is null.
-
boxPrimitive
public static void boxPrimitive(@NonNull @NonNull CodeBuilder codeBuilder, @NonNull @NonNull String sourceDescriptor) Boxes the given primitive type on the stack of the given code builder (excluding void).- Parameters:
codeBuilder- the code builder to append the box operation to.sourceDescriptor- the descriptor of the primitive type that should get boxed.- Throws:
NullPointerException- if the given code builder or target type is null.IllegalArgumentException- if the given source type is not primitive or void.
-
boxPrimitive
private static void boxPrimitive(@NonNull @NonNull CodeBuilder codeBuilder, @NonNull @NonNull CodeGenerationUtil.PrimitiveWrapperConverter converter) Applies the conversion from a primitive type to the corresponding wrapper type on the given code builder.- Parameters:
codeBuilder- the code builder to apply the operation to.converter- the converter information for the wrapper type.- Throws:
NullPointerException- if the given code builder or converter is null.
-
defineClass
@NonNull public static @NonNull Class<?> defineClass(@NonNull @NonNull Class<?> parentClass, byte[] classData) Defines a class based on the given class bytes using the class loader of the given parent class. The returned class has not been initialized.- Parameters:
parentClass- the parent class to use the classloader for class defining of.classData- the raw bytecode of the class to define.- Returns:
- the class object of the defined class.
- Throws:
NullPointerException- if the given parent class or class data is null.
-
defineNestedClass
@NonNull public static MethodHandles.Lookup defineNestedClass(@NonNull @NonNull Class<?> hostClass, byte[] classData) Defines a hidden nest mate class in the given host class, which grants the defined class full access to everything that is present in the class (for example private members). The returned class has not been initialized.- Parameters:
hostClass- the host class which should be used for the nested class.classData- the raw bytecode of the nest class to define.- Returns:
- a method handle with full access to the defined nest class.
- Throws:
NullPointerException- if the given host class or class data is null.
-