|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ClassFab
Used when fabricating a new class. Represents a wrapper around the Javassist library.
The core concept of Javassist is how method bodies (as well as constructor bodies, etc.)
are specified ... as a very Java-like scripting language. The
BodyBuilder
class is very useful for assembling
this method bodies. Details are available at the
Javassist home page.
Method bodies look largely like Java. References to java classes must be fully qualified. Several special variables are used:
$0
first parameter, equivalent to this
in Java code (and can't
be used when creating a static method)
$1, $2, ...
actual parameters to the method
$args
all the parameters as an Object[]
$r
the return type of the method, typically used as return ($r) ...
.
$r
is valid with method that return void
. This also handles conversions
between wrapper types and primitive types.
$w
conversion from primitive type to wrapper type, used as ($w) foo()
where
foo()
returns a primitive type and a wrapper type is needed
Method Summary | |
---|---|
void |
addConstructor(java.lang.Class[] parameterTypes,
java.lang.Class[] exceptions,
java.lang.String body)
Adds a constructor to the class. |
void |
addField(java.lang.String name,
java.lang.Class type)
Adds a new field with the given name and type. |
void |
addInterface(java.lang.Class interfaceClass)
Adds the specified interface as an interface implemented by this class. |
MethodFab |
addMethod(int modifiers,
MethodSignature signature,
java.lang.String body)
Adds a method. |
boolean |
canConvert(java.lang.Class inputClass)
|
boolean |
containsMethod(MethodSignature signature)
Convenience method for checking whether the fabricated class already contains a method. |
java.lang.Class |
createClass()
Invoked last to create the class. |
MethodFab |
getMethodFab(MethodSignature signature)
Returns a previous defined method so that it can be further enhanced (perhaps by adding additional catches, etc.). |
Method Detail |
---|
void addInterface(java.lang.Class interfaceClass)
void addField(java.lang.String name, java.lang.Class type)
boolean canConvert(java.lang.Class inputClass)
boolean containsMethod(MethodSignature signature)
signature
- the signature
MethodFab addMethod(int modifiers, MethodSignature signature, java.lang.String body)
modifiers
- Modifiers for the method (see Modifier
).signature
- defines the name, return type, parameters and exceptions thrownbody
- The body of the method.
ApplicationRuntimeException
- if a method with that signature has already
been added, or if there is a Javassist compilation errorMethodFab getMethodFab(MethodSignature signature)
signature
- the signature of the method previously added
void addConstructor(java.lang.Class[] parameterTypes, java.lang.Class[] exceptions, java.lang.String body)
parameterTypes
- the type of each parameter, or null if the constructor takes no parameters.exceptions
- the type of each exception, or null if the constructor throws no exceptions.body
- The body of the constructor.java.lang.Class createClass()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |