public class GenerateMethodDelegate extends AbstractClassGenerator<GenerateMethodDelegate.GMDMetaData>
MethodDelegate and the
additional interfaces supplied in AbstractClassGenerator.MetaData.interfaces(). Calls to
those interfaces are forwarded to a delegate instance set via
MethodDelegate.delegate(Object).
The generated class allows the delegate to be swapped or wrapped at run time,
providing a lightweight means of adapting behaviour. This generator extends
AbstractClassGenerator and produces a typed wrapper that forwards
every method invocation to the current delegate.
| Modifier and Type | Class and Description |
|---|---|
static class |
GenerateMethodDelegate.GMDMetaData
Metadata for
GenerateMethodDelegate. |
AbstractClassGenerator.MetaData<M extends AbstractClassGenerator.MetaData<M>>CACHED_COMPILER, importSet, sourceCode| Constructor and Description |
|---|
GenerateMethodDelegate()
Creates a generator with the default metadata.
|
| Modifier and Type | Method and Description |
|---|---|
<T> Class<T> |
acquireClass(ClassLoader classLoader)
Ensures
MethodDelegate is always included before delegating to the
superclass to create or load the proxy class. |
protected void |
generateConstructors(SourceCodeFormatter mainCode)
Uses the implicit no-arg constructor; no constructors are generated.
|
protected void |
generateFields(SourceCodeFormatter mainCode)
Emits the field that stores the current delegate instance.
|
protected String |
generateGenericType()
Creates the generic type signature in the form
<OUT extends Object & Interface1 & Interface2 & MethodDelegate<OUT>>. |
protected void |
generateMethod(Method method,
SourceCodeFormatter mainCode)
Generates a concrete implementation of each method.
|
protected void |
generateMethod(Method method,
StringBuilder params,
List<String> paramList,
SourceCodeFormatter mainCode)
Writes the body of a delegated method.
|
protected SourceCodeFormatter |
getDelegate(SourceCodeFormatter mainCode,
Method method)
Appends the delegate to the main code.
|
protected String |
getDelegateType()
Returns the name used for the delegate type in generated code.
|
className, extendsClass, fieldCase, generateEnd, generateMainCode, maxCode, maxCode, metaData, methodsToOverride, nameForClass, withLineNumberpublic GenerateMethodDelegate()
public <T> Class<T> acquireClass(ClassLoader classLoader)
MethodDelegate is always included before delegating to the
superclass to create or load the proxy class.acquireClass in class AbstractClassGenerator<GenerateMethodDelegate.GMDMetaData>T - The type of the generated class.classLoader - The class loader to be used for loading the generated class.protected String generateGenericType()
<OUT extends Object & Interface1 & Interface2 & MethodDelegate<OUT>>.generateGenericType in class AbstractClassGenerator<GenerateMethodDelegate.GMDMetaData>protected void generateFields(SourceCodeFormatter mainCode)
generateFields in class AbstractClassGenerator<GenerateMethodDelegate.GMDMetaData>mainCode - The code formatter where the generated code is appended.protected String getDelegateType()
protected void generateConstructors(SourceCodeFormatter mainCode)
generateConstructors in class AbstractClassGenerator<GenerateMethodDelegate.GMDMetaData>mainCode - The code formatter where the generated code is appended.protected void generateMethod(Method method, SourceCodeFormatter mainCode)
delegate(Object) method stores the delegate, while all other
methods are handled by the superclass.generateMethod in class AbstractClassGenerator<GenerateMethodDelegate.GMDMetaData>method - The method whose code is being generated.mainCode - The code formatter where the generated code is appended.protected void generateMethod(Method method, StringBuilder params, List<String> paramList, SourceCodeFormatter mainCode)
generateMethod in class AbstractClassGenerator<GenerateMethodDelegate.GMDMetaData>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.protected SourceCodeFormatter getDelegate(SourceCodeFormatter mainCode, Method method)
mainCode - The SourceCodeFormatter to append the delegate.method - The associated method.Copyright © 2026 Chronicle Software Ltd. All rights reserved.