org.iqual.chaplin.trait
Class TraitTransformer
java.lang.Object
org.objectweb.asm.ClassAdapter
org.iqual.chaplin.trait.TraitTransformer
- All Implemented Interfaces:
- org.objectweb.asm.ClassVisitor
public class TraitTransformer
- extends org.objectweb.asm.ClassAdapter
This class performs a pre-transformation of classes before they are transformed by FieldRedirector.
It uses its own semantics to produce classes adorned by the semantics of the FieldRedirector.
The transformation consists of replacement of all CHECKCAST instructions with trait instantiation and initialization.
Only those CHECKCAST instructions are replaces as long as the CHECKCAST's type is a trait, ie. it is annotated by
Trait annotation.
The other task of the transformation is transformin trait classes into the semantics of the FieldRedirector.
It consists of recognition whether the class is annotated by Trait annotation. If it is so
the transformer generates the self field whose type is the type of the trait's target class as is given
by the value property of the annotation. The self field
is annotated by FromContext annotation where the context id is the trait's class itself.
Then the transformation annotates all methods in the trait class by DynaContext as follows:
before:
private void someMethod() {
}
private static void someStaticMethod() {
}
after:
@DynaContext(id=TheTrait.class, attr=ContextAttribute.This)
private void someMethod() {
}
@DynaContext(id=TheTrait.class, attr=ContextAttribute.Mandatory)
private static void someStaticMethod() {
}
- Since:
- Mar 21, 2009 2:37:32 PM
- Author:
- Zbynek Slajchrt
| Fields inherited from class org.objectweb.asm.ClassAdapter |
cv |
|
Constructor Summary |
TraitTransformer(org.objectweb.asm.ClassVisitor cv,
org.objectweb.asm.tree.ClassNode classNode)
|
|
Method Summary |
void |
visit(int version,
int access,
String name,
String signature,
String superName,
String[] interfaces)
|
org.objectweb.asm.AnnotationVisitor |
visitAnnotation(String desc,
boolean visible)
|
void |
visitEnd()
|
org.objectweb.asm.FieldVisitor |
visitField(int access,
String name,
String desc,
String signature,
Object value)
|
org.objectweb.asm.MethodVisitor |
visitMethod(int access,
String name,
String desc,
String signature,
String[] exceptions)
|
| Methods inherited from class org.objectweb.asm.ClassAdapter |
visitAttribute, visitInnerClass, visitOuterClass, visitSource |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TRAIT_ANNOT_DESC
public static String TRAIT_ANNOT_DESC
TraitTransformer
public TraitTransformer(org.objectweb.asm.ClassVisitor cv,
org.objectweb.asm.tree.ClassNode classNode)
visit
public void visit(int version,
int access,
String name,
String signature,
String superName,
String[] interfaces)
- Specified by:
visit in interface org.objectweb.asm.ClassVisitor- Overrides:
visit in class org.objectweb.asm.ClassAdapter
visitAnnotation
public org.objectweb.asm.AnnotationVisitor visitAnnotation(String desc,
boolean visible)
- Specified by:
visitAnnotation in interface org.objectweb.asm.ClassVisitor- Overrides:
visitAnnotation in class org.objectweb.asm.ClassAdapter
visitField
public org.objectweb.asm.FieldVisitor visitField(int access,
String name,
String desc,
String signature,
Object value)
- Specified by:
visitField in interface org.objectweb.asm.ClassVisitor- Overrides:
visitField in class org.objectweb.asm.ClassAdapter
visitEnd
public void visitEnd()
- Specified by:
visitEnd in interface org.objectweb.asm.ClassVisitor- Overrides:
visitEnd in class org.objectweb.asm.ClassAdapter
visitMethod
public org.objectweb.asm.MethodVisitor visitMethod(int access,
String name,
String desc,
String signature,
String[] exceptions)
- Specified by:
visitMethod in interface org.objectweb.asm.ClassVisitor- Overrides:
visitMethod in class org.objectweb.asm.ClassAdapter
Copyright © 2009 iquality.org. All Rights Reserved.