|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.objectweb.fractal.julia.asm.MixinClassGenerator
public class MixinClassGenerator
A class generator to mix several mixin classes into a single class. A mixin class is a class of the following form:
public abstract class XMixin implements I { // private constructor private XMixin () {} // fields and methods added or overriden by the mixin class public int i; public void m (String s) { _this_n(); _super_m(_this_header + s + i); } // ... // fields and methods required by the mixin class in other mixins String _this_header; abstract void _this_n (); // original methods, overriden in this mixin class abstract void _super_m (String s); // ... }The mix of several mixin classes M1 ... Mn, in this order, is a class that is equivalent to a class Mn subclassing Mn-1 ... sub classing M1. For example, if YMixin is a mixin of the following form:
public abstract class YMixin { // private constructor private YMixin () {} // fields and methods added or overriden by the mixin class public String header; public void n () { ... } public void m (String s) { return header + s; } }then the mix of YMixin and XMixin, in this order, is the following class:
public class XYZ implements I, Generated { // from XMixin: public int i; public void m (String s) { n(); return m$$0(header + s + i); } // from YMixin: public String header; public void n () { ... } private void m$$0 (String s) { return header + s; } // other methods public String getFcGeneratorParameters () { return "(...MixinClassGenerator source YMixin XMixin)"; } }As can be seen, the code of the mixin classes is copied into the mixed class, with some small transformations: fields and methods that are static or whose name begins with _this_ or _super_ are not copied, and overriden methods are renamed with a "$$n" suffix to avoid name clashes.
Several mixin classes can be mixed, in a specific order, only if the fields and methods required by each mixin class are provided by previous mixins classes in the mixin class list. For example, the XMixin can only be used if one or more previous mixin classes, in the mixed class list, provide a header field, a void n () method, and a void m (String s) method.
Notes:
Field Summary |
---|
Constructor Summary | |
---|---|
MixinClassGenerator()
|
Method Summary | |
---|---|
byte[] |
generateClass(String name,
Tree args,
Loader loader,
ClassLoader classLoader)
Generates a class by adding mixin classes to the given class. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MixinClassGenerator()
Method Detail |
---|
public byte[] generateClass(String name, Tree args, Loader loader, ClassLoader classLoader) throws ClassGenerationException
generateClass
in interface ClassGenerator
name
- the name of the class to be generated.args
- the descriptor of the class to be generated. This
descriptor must be of the form (object descriptor source
mixinClass1 ... mixinClassN), where source is a symbolic name to
designate the mixed class - this name appears in stack traces, and
where mixinClass1 ... mixinClassN are the class descriptors of the
classes to be mixed.loader
- the loader to be used to load or generate auxiliary classes,
if needed.classLoader
- the class loader to be used to load auxiliary classes,
if needed.
ClassGenerationException
- if any other problem occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |