FileDocCategorySizeDatePackage
TreeClassAdapter.javaAPI DocGlassfish v2 API4508Thu Mar 02 11:51:16 GMT 2006oracle.toplink.libraries.asm.tree

TreeClassAdapter

public class TreeClassAdapter extends ClassAdapter
A {@link ClassAdapter ClassAdapter} that constructs a tree representation of the classes it vists. Each visitXXX method of this class constructs an XXXNode and adds it to the {@link #classNode classNode} node (except the {@link #visitEnd visitEnd} method, which just makes the {@link #cv cv} class visitor visit the tree that has just been constructed).

In order to implement a usefull class adapter based on a tree representation of classes, one just need to override the {@link #visitEnd visitEnd} method with a method of the following form:

public void visitEnd () {
// ...
// code to modify the classNode tree, can be arbitrary complex
// ...
// makes the cv visitor visit this modified class:
classNode.accept(cv);
}
author
Eric Bruneton

Fields Summary
public ClassNode
classNode
A tree representation of the class that is being visited by this visitor.
Constructors Summary
public TreeClassAdapter(ClassVisitor cv)
Constructs a new {@link TreeClassAdapter TreeClassAdapter} object.

param
cv the class visitor to which this adapter must delegate calls.

    super(cv);
  
Methods Summary
public voidvisit(int version, int access, java.lang.String name, java.lang.String superName, java.lang.String[] interfaces, java.lang.String sourceFile)

    classNode = new ClassNode(version, access, name, superName, interfaces, sourceFile);
  
public voidvisitAttribute(oracle.toplink.libraries.asm.Attribute attr)

    attr.next = classNode.attrs;
    classNode.attrs = attr;
  
public voidvisitEnd()

    if( cv!=null) {
      classNode.accept(cv);
    }
  
public voidvisitField(int access, java.lang.String name, java.lang.String desc, java.lang.Object value, oracle.toplink.libraries.asm.Attribute attrs)

    FieldNode fn = new FieldNode(access, name, desc, value, attrs);
    classNode.fields.add(fn);
  
public voidvisitInnerClass(java.lang.String name, java.lang.String outerName, java.lang.String innerName, int access)

    InnerClassNode icn = new InnerClassNode(name, outerName, innerName, access);
    classNode.innerClasses.add(icn);
  
public oracle.toplink.libraries.asm.CodeVisitorvisitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String[] exceptions, oracle.toplink.libraries.asm.Attribute attrs)

    MethodNode mn = new MethodNode(access, name, desc, exceptions, attrs);
    classNode.methods.add(mn);
    return new TreeCodeAdapter(mn);