ClassSourcerpublic class ClassSourcer extends Object implements org.objectweb.asm.ClassVisitorA 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 void | visit(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.AnnotationVisitor | visitAnnotation(java.lang.String desc, boolean visible)
mOutput.write("@%s", desc);
return new AnnotationSourcer(mOutput);
| public void | visitAttribute(org.objectweb.asm.Attribute attr)
mOutput.write("%s /* non-standard class attribute */ ", attr.type);
| public void | visitEnd()
mOutput.write("}\n");
| public org.objectweb.asm.FieldVisitor | visitField(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 void | visitInnerClass(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.MethodVisitor | visitMethod(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 void | visitOuterClass(java.lang.String owner, java.lang.String name, java.lang.String desc)
// Skip outer classes.
| public void | visitSource(java.lang.String source, java.lang.String debug)
// Skip source information.
|
|