Class ClassGenerator
- Direct Known Subclasses:
FakePlayerClassGenerator
ClassLoader.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final net.bytebuddy.dynamic.DynamicType.Builder<?> createBuilder(Class<?> superClass) Creates a newByteBuddybuilder.protected final voidfinishBuilder(net.bytebuddy.dynamic.DynamicType.Builder<?> builder) Finishes the builder.protected final voidfinishBuilder(net.bytebuddy.dynamic.DynamicType.Builder<?> builder, @Nullable Path savePath) Finishes the builder.protected final voidgenerate()Generates the class.protected abstract voidThe implementation of the class generation code.protected abstract StringRetrieves the base name of the class to be generated.protected abstract Class<?>[]Retrieves the array of parameter types as the generated constructor takes them.protected StringRetrieves the name the generated class should have in the correct format.final Class<?> Gets the class generated by this ClassGenerator.final Constructor<?> Gets the constructor generated by this ClassGenerator.toString()
-
Field Details
-
generatedClass
-
generatedConstructor
-
-
Constructor Details
-
ClassGenerator
- Parameters:
classLoader- TheClassLoaderto insert generated classes into.
-
-
Method Details
-
generate
Generates the class.- Throws:
Exception- When any kind of exception occurs during the generation process.
-
generateImpl
The implementation of the class generation code. This method is called bygenerate()when needed.- Throws:
Exception- When any kind of exception occurs during the generation process.
-
createBuilder
Creates a newByteBuddybuilder.The returned builder will be a subclass of the provided superclass, have a properly formatted name, and implement
IGeneratedClass.- Parameters:
superClass- TheClassthe builder should be a subclass of. This can also be an interface.- Returns:
- The new, properly configured,
ByteBuddybuilder.
-
getFormattedName
Retrieves the name the generated class should have in the correct format.getBaseName()is used as the basis of the formatted name.- Returns:
- The correctly formatted name.
-
getBaseName
Retrieves the base name of the class to be generated.This should be the simple name describing the class that is to be generated.
For example, the base name of the generated EntityFallingBlock class would be just that: "EntityFallingBlock". Any additional information (such as the fact that it is a generated class) will be added later on by
getFormattedName().- Returns:
- The base name of the class to be generated.
-
getConstructorArgumentTypes
Retrieves the array of parameter types as the generated constructor takes them.- Returns:
- The array of parameter types of the generated constructor.
-
finishBuilder
protected final void finishBuilder(net.bytebuddy.dynamic.DynamicType.Builder<?> builder) Finishes the builder.This method takes care of loading the generated class, and retrieving the class object and the constructor of the generated class.
The generated class will not be saved to a file.
- Parameters:
builder- The builder to finish.
-
finishBuilder
protected final void finishBuilder(net.bytebuddy.dynamic.DynamicType.Builder<?> builder, @Nullable @Nullable Path savePath) Finishes the builder.This method takes care of loading the generated class, and retrieving the class object and the constructor of the generated class.
- Parameters:
builder- The builder to finish.savePath- The path to save the generated class to. If this isnull, the class will not be saved.
-
getGeneratedClass
Gets the class generated by this ClassGenerator.- Returns:
- The generated class.
-
getGeneratedConstructor
Gets the constructor generated by this ClassGenerator.- Returns:
- The constructor generated by this ClassGenerator.
-
toString
-