M - Represents the meta-data associated with the class being generated.public abstract class AbstractClassGenerator<M extends AbstractClassGenerator.MetaData<M>> extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractClassGenerator.MetaData<M extends AbstractClassGenerator.MetaData<M>>
Represents the metadata configuration required for the class generator.
|
| Modifier and Type | Field and Description |
|---|---|
static net.openhft.compiler.CachedCompiler |
CACHED_COMPILER |
protected SortedSet<String> |
importSet |
protected SourceCodeFormatter |
sourceCode |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractClassGenerator(M metaData)
Constructor for initializing the generator with its associated meta-data.
|
| Modifier and Type | Method and Description |
|---|---|
<T> Class<T> |
acquireClass(ClassLoader classLoader)
Attempts to acquire the generated class.
|
protected @NotNull String |
className()
Generates a class name based on the metadata and possibly a hash value.
|
protected Class<?> |
extendsClass()
Specifies which class the generated class should extend.
|
protected String |
fieldCase(Class<?> clazz)
Generates a field name based on the given class.
|
protected void |
generateConstructors(SourceCodeFormatter mainCode)
Generates constructors for the class.
|
protected void |
generateEnd(SourceCodeFormatter mainCode)
Stub method for subclasses to implement end code generation, if necessary.
|
protected void |
generateFields(SourceCodeFormatter mainCode)
Generates fields for the class.
|
protected String |
generateGenericType()
Generates a generic type for the class, if required.
|
protected void |
generateMainCode(SourceCodeFormatter mainCode)
Generates the main code for the class, including fields, constructors, methods, and more.
|
protected void |
generateMethod(Method method,
SourceCodeFormatter mainCode)
Generates the implementation for a specific method.
|
protected abstract void |
generateMethod(Method method,
StringBuilder params,
List<String> paramList,
SourceCodeFormatter mainCode)
Abstract method for subclasses to implement the body of the generated method.
|
int |
maxCode()
Retrieves the maxCode value which seems to determine the maximum
number of characters or an internal limit for generated code.
|
AbstractClassGenerator<M> |
maxCode(int maxCode)
Sets the maxCode value.
|
M |
metaData()
Retrieves the meta-data associated with this generator.
|
protected @NotNull Set<Method> |
methodsToOverride()
Determines the set of methods that should be overridden based on the provided metadata.
|
String |
nameForClass(Class<?> clazz)
Generates a name for the given class.
|
protected SourceCodeFormatter |
withLineNumber(SourceCodeFormatter mainCode)
Appends the line number and stack trace for better traceability in the generated code.
|
public static final net.openhft.compiler.CachedCompiler CACHED_COMPILER
protected final SourceCodeFormatter sourceCode
protected AbstractClassGenerator(M metaData)
metaData - Meta-data related to the class to be generated.public M metaData()
public <T> Class<T> acquireClass(ClassLoader classLoader)
T - The type of the generated class.classLoader - The class loader to be used for loading the generated class.protected String generateGenericType()
protected Class<?> extendsClass()
public String nameForClass(Class<?> clazz)
clazz - The class whose name should be generated.public int maxCode()
public AbstractClassGenerator<M> maxCode(int maxCode)
maxCode - The desired maxCode value.@NotNull protected @NotNull String className()
protected void generateMainCode(SourceCodeFormatter mainCode)
mainCode - The code formatter where the generated code is appended.protected String fieldCase(Class<?> clazz)
clazz - The class for which the field name is being generated.protected void generateFields(SourceCodeFormatter mainCode)
mainCode - The code formatter where the generated code is appended.protected void generateConstructors(SourceCodeFormatter mainCode)
mainCode - The code formatter where the generated code is appended.protected SourceCodeFormatter withLineNumber(SourceCodeFormatter mainCode)
mainCode - The code formatter where the line information is appended.protected void generateMethod(Method method, SourceCodeFormatter mainCode)
method - The method whose code is being generated.mainCode - The code formatter where the generated code is appended.protected void generateEnd(SourceCodeFormatter mainCode)
mainCode - The code formatter where the generated code is appended.protected abstract void generateMethod(Method method, StringBuilder params, List<String> paramList, SourceCodeFormatter mainCode)
method - The method whose body is being generated.params - The parameters of the method in a StringBuilder.paramList - The list of parameter names.mainCode - The code formatter where the generated code is appended.@NotNull protected @NotNull Set<Method> methodsToOverride()
The method retrieves abstract methods from the interfaces specified in the metadata and the superclass. Any concrete method present in the superclass or interfaces is considered to have already been overridden, so these methods are excluded from the result.
Copyright © 2024. All rights reserved.