Dynamic method implementation annotation.
This annotation marks methods that implement a dynamic method
for a specific argument type, which must be a subclass of the
argument type for the matching
@DynamicMethod
annotation. The class that this member is a part of must
be annotated with a @DMethodContext
or
@DMethodContexts
annotation to associate a
local-helper class (the source code for this class will be
automatically generated) with the top-level helper class.
the local-helper class and the helper class must not be
the same class.
Unless a class loader that is aware of dynamic methods, such as
org.bzdev.lang.DMClassLoader
, is
used,
a class containing a DMethodImpl
annotation must include the
following initialization code:
static {
LOCALHELPER.register();
}
where LOCALHELPER is the name of the local-helper class (the
DMethodImpl
annotation's localHelper
field's
value).
For example,
class Foo {
@DynamicMethod("Helper")
void method(Bar arg) {
Helper.getHelper().dispatch(this, arg);
}
}
class Bar1 extends Bar {...}
class Bar2 extends Bar {...}
@DMethodContext(helper="Helper", localHelper="LocalHelper")
class Foo1 extends Foo {
static {
LocalHelper.register();
}
...
@DMethodImpl("Helper")
void doMethod(Bar1 arg) {
...
}
@DMethodImpl("Helper")
void doMethod(Bar2 arg) {
...
}
}
Note that if (in the example) class Foo
contained a
DMethodImpl
annotation, then Foo
would
itself require a DMethodContext
annotation with a
local-helper class different from the helper class.
If the method returns a value, the above example becomes
class Foo {
@DynamicMethod("Helper")
void FooBar method(Bar arg) {
Helper.getHelper().dispatch(this, arg);
}
}
class Bar1 extends Bar {...}
class Bar2 extends Bar {...}
@DMethodContext(helper="Helper", localHelper="LocalHelper")
class Foo1 extends Foo {
static {
LocalHelper.register();
}
...
@DMethodImpl("Helper")
FooBar doMethod(Bar1 arg) {
...
}
@DMethodImpl("Helper")
FooBar doMethod(Bar2 arg) {
...
}
}
- See Also:
-
Required Element Summary
Required Elements
-
Element Details
-
value
String valueClass name of the top-level helper class. This class name is used as a key to distinguish various dynamic methods. It must be a fully qualified name if the helper is not in the current package.- Returns:
- the value of this element
-