org.objectweb.asm.util
Class CheckClassAdapter

java.lang.Object
  extended byorg.objectweb.asm.ClassAdapter
      extended byorg.objectweb.asm.util.CheckClassAdapter
All Implemented Interfaces:
ClassVisitor

public class CheckClassAdapter
extends ClassAdapter

A ClassAdapter that checks that its methods are properly used. More precisely this class adapter checks each method call individually, based only on its arguments, but does not check the sequence of method calls. For example, the invalid sequence visitField(ACC_PUBLIC, "i", "I", null) visitField(ACC_PUBLIC, "i", "D", null) will not be detected by this class adapter.

Author:
Eric Bruneton

Field Summary
 
Fields inherited from class org.objectweb.asm.ClassAdapter
cv
 
Constructor Summary
CheckClassAdapter(ClassVisitor cv)
          Constructs a new CheckClassAdapter.
 
Method Summary
static void main(String[] args)
          Checks a given class.
static void verify(ClassReader cr, boolean dump, PrintWriter pw)
          Checks a given class
 void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
          Visits the header of the class.
 AnnotationVisitor visitAnnotation(String desc, boolean visible)
          Visits an annotation of the class.
 void visitAttribute(Attribute attr)
          Visits a non standard attribute of the class.
 void visitEnd()
          Visits the end of the class.
 FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
          Visits a field of the class.
 void visitInnerClass(String name, String outerName, String innerName, int access)
          Visits information about an inner class.
 MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
          Visits a method of the class.
 void visitOuterClass(String owner, String name, String desc)
          Visits the enclosing class of the class.
 void visitSource(String file, String debug)
          Visits the source of the class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CheckClassAdapter

public CheckClassAdapter(ClassVisitor cv)
Constructs a new CheckClassAdapter.

Parameters:
cv - the class visitor to which this adapter must delegate calls.
Method Detail

main

public static void main(String[] args)
                 throws Exception
Checks a given class.

Usage: CheckClassAdapter <fully qualified class name or class file name>

Parameters:
args - the command line arguments.
Throws:
Exception - if the class cannot be found, or if an IO exception occurs.

verify

public static void verify(ClassReader cr,
                          boolean dump,
                          PrintWriter pw)
Checks a given class

Parameters:
cr - a ClassReader that contains bytecode for the analysis.
dump - true if bytecode should be printed out not only when errors are found.
pw - write where results going to be printed

visit

public void visit(int version,
                  int access,
                  String name,
                  String signature,
                  String superName,
                  String[] interfaces)
Description copied from interface: ClassVisitor
Visits the header of the class.

Specified by:
visit in interface ClassVisitor
Overrides:
visit in class ClassAdapter

visitSource

public void visitSource(String file,
                        String debug)
Description copied from interface: ClassVisitor
Visits the source of the class.

Specified by:
visitSource in interface ClassVisitor
Overrides:
visitSource in class ClassAdapter

visitOuterClass

public void visitOuterClass(String owner,
                            String name,
                            String desc)
Description copied from interface: ClassVisitor
Visits the enclosing class of the class. This method must be called only if the class has an enclosing class.

Specified by:
visitOuterClass in interface ClassVisitor
Overrides:
visitOuterClass in class ClassAdapter

visitInnerClass

public void visitInnerClass(String name,
                            String outerName,
                            String innerName,
                            int access)
Description copied from interface: ClassVisitor
Visits information about an inner class. This inner class is not necessarily a member of the class being visited.

Specified by:
visitInnerClass in interface ClassVisitor
Overrides:
visitInnerClass in class ClassAdapter

visitField

public FieldVisitor visitField(int access,
                               String name,
                               String desc,
                               String signature,
                               Object value)
Description copied from interface: ClassVisitor
Visits a field of the class.

Specified by:
visitField in interface ClassVisitor
Overrides:
visitField in class ClassAdapter

visitMethod

public MethodVisitor visitMethod(int access,
                                 String name,
                                 String desc,
                                 String signature,
                                 String[] exceptions)
Description copied from interface: ClassVisitor
Visits a method of the class. This method must return a new MethodVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

Specified by:
visitMethod in interface ClassVisitor
Overrides:
visitMethod in class ClassAdapter

visitAnnotation

public AnnotationVisitor visitAnnotation(String desc,
                                         boolean visible)
Description copied from interface: ClassVisitor
Visits an annotation of the class.

Specified by:
visitAnnotation in interface ClassVisitor
Overrides:
visitAnnotation in class ClassAdapter

visitAttribute

public void visitAttribute(Attribute attr)
Description copied from interface: ClassVisitor
Visits a non standard attribute of the class.

Specified by:
visitAttribute in interface ClassVisitor
Overrides:
visitAttribute in class ClassAdapter

visitEnd

public void visitEnd()
Description copied from interface: ClassVisitor
Visits the end of the class. This method, which is the last one to be called, is used to inform the visitor that all the fields and methods of the class have been visited.

Specified by:
visitEnd in interface ClassVisitor
Overrides:
visitEnd in class ClassAdapter