@Beta public final class JavassistUtils extends Object
Modifier and Type | Method and Description |
---|---|
void |
appendClassLoaderIfMissing(ClassLoader loader)
Append class to class pool if doesn't exist.
|
javassist.CtClass |
asCtClass(Class<?> class1)
Get class from class pool.
|
javassist.CtClass |
createClass(String className,
ClassGenerator classGenerator)
Generate and add class to global class pool.
|
javassist.CtClass |
createClass(String className,
javassist.CtClass superInterface,
ClassGenerator classGenerator)
Generate and add class to global class pool with implemented interface.
|
void |
ensureClassLoader(Class<?> child)
Ensure if is class in class loader.
|
javassist.CtField |
field(javassist.CtClass baseClass,
String fieldName,
Class<?> fieldType)
Create and add field to class.
|
static JavassistUtils |
forClassPool(javassist.ClassPool pool)
Get a utility instance for a particular class pool.
|
javassist.CtClass |
get(javassist.ClassPool pool,
Class<? extends Object> clazz)
Get class from pool.
|
void |
implementMethodsFrom(javassist.CtClass target,
javassist.CtClass source,
MethodGenerator methodGenerator)
Implement methods to class from other class.
|
void |
implementsType(javassist.CtClass baseClass,
javassist.CtClass superInterface)
Implements type to class.
|
javassist.CtClass |
instantiatePrototype(String prototype,
String target,
ClassCustomizer customizer)
Instantiate a new class based on a prototype.
|
void |
method(javassist.CtClass baseClass,
Class<?> methodReturnType,
String methodName,
Class<?> methodParameter,
MethodGenerator methodGenerator)
Generate and add method to class.
|
void |
method(javassist.CtClass baseClass,
Class<?> methodReturnType,
String methodName,
Collection<? extends Class<?>> methodParameters,
MethodGenerator methodGenerator)
Generate and add method to class.
|
javassist.CtField |
staticField(javassist.CtClass baseClass,
String fieldName,
Class<?> fieldType)
Create and add static field to class.
|
javassist.CtField |
staticField(javassist.CtClass baseClass,
String fieldName,
Class<?> fieldType,
SourceCodeGenerator sourceGenerator)
Create and add static field to class.
|
void |
staticMethod(javassist.CtClass baseClass,
Class<?> methodReturnType,
String methodName,
Class<?> methodParameter,
MethodGenerator methodGenerator)
Generate and add static method to class.
|
public static JavassistUtils forClassPool(javassist.ClassPool pool)
pool
- - backing class poolpublic void method(javassist.CtClass baseClass, Class<?> methodReturnType, String methodName, Class<?> methodParameter, MethodGenerator methodGenerator) throws javassist.CannotCompileException
baseClass
- - class for adding methodmethodReturnType
- - return type of methodmethodName
- - name of methodmethodParameter
- - parameter of methodmethodGenerator
- - method generatorjavassist.CannotCompileException
public void method(javassist.CtClass baseClass, Class<?> methodReturnType, String methodName, Collection<? extends Class<?>> methodParameters, MethodGenerator methodGenerator) throws javassist.CannotCompileException
baseClass
- - class for adding methodmethodReturnType
- - return type of methodmethodName
- - name of methodmethodParameters
- - parameters of methodmethodGenerator
- - method generatorjavassist.CannotCompileException
public void staticMethod(javassist.CtClass baseClass, Class<?> methodReturnType, String methodName, Class<?> methodParameter, MethodGenerator methodGenerator) throws javassist.CannotCompileException
baseClass
- - class for adding methodmethodReturnType
- - return type of methodmethodName
- - name of methodmethodParameter
- - parameter of methodmethodGenerator
- - method generatorjavassist.CannotCompileException
public void implementMethodsFrom(javassist.CtClass target, javassist.CtClass source, MethodGenerator methodGenerator) throws javassist.CannotCompileException
target
- - class for implementing methodssource
- - source class of methods to be implemented in targetmethodGenerator
- - method generatorjavassist.CannotCompileException
public javassist.CtClass createClass(String className, ClassGenerator classGenerator) throws javassist.CannotCompileException
className
- - name of classclassGenerator
- - class generatorjavassist.CannotCompileException
public javassist.CtClass createClass(String className, javassist.CtClass superInterface, ClassGenerator classGenerator) throws javassist.CannotCompileException
className
- - name of classsuperInterface
- - interface to be implemented to the classclassGenerator
- - class generatorjavassist.CannotCompileException
public javassist.CtClass instantiatePrototype(String prototype, String target, ClassCustomizer customizer) throws javassist.NotFoundException
prototype
- - prototype class fully qualified nametarget
- - target class fully qualified namecustomizer
- - customization callback to be invoked on the new classjavassist.NotFoundException
- - when the prototype class is not foundpublic void implementsType(javassist.CtClass baseClass, javassist.CtClass superInterface)
baseClass
- - class for implements interfacesuperInterface
- - interface to be implementedpublic javassist.CtClass asCtClass(Class<?> class1)
class1
- - class for getting from class poolpublic javassist.CtField field(javassist.CtClass baseClass, String fieldName, Class<?> fieldType) throws javassist.CannotCompileException
baseClass
- - class for adding fieldfieldName
- - name of fieldfieldType
- - type of fieldjavassist.CannotCompileException
public javassist.CtField staticField(javassist.CtClass baseClass, String fieldName, Class<?> fieldType) throws javassist.CannotCompileException
baseClass
- - class for adding fieldfieldName
- - name of fieldfieldType
- - type of fieldjavassist.CannotCompileException
public javassist.CtField staticField(javassist.CtClass baseClass, String fieldName, Class<?> fieldType, SourceCodeGenerator sourceGenerator) throws javassist.CannotCompileException
baseClass
- - class for adding fieldfieldName
- - name of fieldfieldType
- - type of fieldsourceGenerator
- - source generatorjavassist.CannotCompileException
public javassist.CtClass get(javassist.ClassPool pool, Class<? extends Object> clazz)
pool
- - class poolclazz
- - search class in class poolpublic void appendClassLoaderIfMissing(ClassLoader loader)
loader
- - class loader of search classpublic void ensureClassLoader(Class<?> child)
child
- - search classCopyright © 2019 OpenDaylight. All rights reserved.