FileDocCategorySizeDatePackage
ClassSourcer.javaAPI DocAndroid 1.5 API4625Wed May 06 22:41:10 BST 2009com.android.mkstubs.sourcer

ClassSourcer

public class ClassSourcer extends Object implements org.objectweb.asm.ClassVisitor
A class visitor that writes a java source.

Fields Summary
private final Output
mOutput
private final AccessSourcer
mAccessSourcer
private String
mClassName
Constructors Summary
public ClassSourcer(Output output)

        mOutput = output;
        mAccessSourcer = new AccessSourcer(mOutput);
    
Methods Summary
public voidvisit(int version, int access, java.lang.String name, java.lang.String signature, java.lang.String superName, java.lang.String[] interfaces)


        String pkg = name.substring(0, name.lastIndexOf('/")).replace('/", '.");
        mClassName = name.substring(name.lastIndexOf('/") + 1);

        mOutput.write("package %s;\n", pkg);

        // dump access keywords. Note: do not dump "super" here
        mAccessSourcer.write(access & ~Opcodes.ACC_SUPER, AccessSourcer.IS_CLASS);

        // write class name
        mOutput.write(" class %s", mClassName);

        if (signature != null) {
            // write template formal definition and super type
            SignatureReader sigReader = new SignatureReader(signature);
            SignatureSourcer sigSourcer = new SignatureSourcer();
            sigReader.accept(sigSourcer);
            
            if (sigSourcer.hasFormalsContent()) {
                mOutput.write(sigSourcer.formalsToString());
            }

            mOutput.write(" extends %s", sigSourcer.getSuperClass().toString());
            
        } else {
            // write non-generic super type
            mOutput.write(" extends %s", superName.replace('/", '."));
        }

        // write interfaces defined, if any
        if (interfaces != null && interfaces.length > 0) {
            mOutput.write(" implements ");
            boolean need_sep = false;
            for (String i : interfaces) {
                if (need_sep) {
                    mOutput.write(", ");
                }
                mOutput.write(i.replace('/", '."));
                need_sep = true;
            }
        }
        
        // open class body
        mOutput.write(" {\n");
    
public org.objectweb.asm.AnnotationVisitorvisitAnnotation(java.lang.String desc, boolean visible)

        mOutput.write("@%s", desc);
        return new AnnotationSourcer(mOutput);
    
public voidvisitAttribute(org.objectweb.asm.Attribute attr)

        mOutput.write("%s /* non-standard class attribute */ ", attr.type);
    
public voidvisitEnd()

        mOutput.write("}\n");
    
public org.objectweb.asm.FieldVisitorvisitField(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.Object value)

        // skip synthetic fields
        if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
            return null;
        }
        
        return new FieldSourcer(mOutput, access, name, desc, signature);
    
public voidvisitInnerClass(java.lang.String name, java.lang.String outerName, java.lang.String innerName, int access)

        // Skip inner classes. This just indicates there's an inner class definition but
        // they are visited at the top level as separate classes.
    
public org.objectweb.asm.MethodVisitorvisitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions)


        // Visit the method and dump its stub.
        return new MethodSourcer(mOutput, mClassName, access, name, desc, signature, exceptions);
    
public voidvisitOuterClass(java.lang.String owner, java.lang.String name, java.lang.String desc)

        // Skip outer classes.
    
public voidvisitSource(java.lang.String source, java.lang.String debug)

        // Skip source information.