//Copyright 2006-2007 Acelet Corporation. All rights reserved.
package limpidlog.asm1;
import java.io.*;
import java.net.*;
import java.util.*;
import limpidlog.org.objectweb.asm.ClassWriter;
import limpidlog.org.objectweb.asm.FieldVisitor;
import limpidlog.org.objectweb.asm.MethodVisitor;
import limpidlog.org.objectweb.asm.Opcodes;
import limpidlog.lib.Options;
/**
* @author Wei Jiang
*/
public class MyClassWriter extends ClassWriter implements Opcodes {
Hashtable labelVectorHashtable;
Hashtable localVariableVectorHashtable;
Vector memberFieldVector = new Vector();
String classNameWithSlash;
String classNameWithDot;
String sourceFileName;
boolean containsDebugInfo = false;
Vector myMethodAdapterVector = new Vector();
public MyClassWriter(Hashtable labelVectorHashtable,
Hashtable localVariableVectorHashtable) {
super(0);
this.labelVectorHashtable = labelVectorHashtable;
this.localVariableVectorHashtable = localVariableVectorHashtable;
}
public void visit(int version, int access, String name, String signature,
String superName, String[] interfaces) {
classNameWithSlash = name;
classNameWithDot = classNameWithSlash.replace('/', '.');
super.visit(version, access, name, signature, superName, interfaces);
if (Options.debug)
System.out.println("MyClassWriter.visit: classNameWithSlash="+classNameWithSlash+
" classNameWithDot="+classNameWithDot);
}
public void visitEnd() {
for (int i = 0; i < myMethodAdapterVector.size(); i++) {
MyMethodAdapter myMethodAdapter = (MyMethodAdapter) myMethodAdapterVector.elementAt(i);
if (myMethodAdapter.containsDebugInfo) {
containsDebugInfo = true;
break;
}
}
}
public FieldVisitor visitField(int access, String name, String desc, String signature,
Object value) {
FieldVisitor fieldVisitor = super.visitField(access, name, desc, signature, value);
MemberVariable memberVariable = null;
int kind = -1;
if ((access & ACC_STATIC) > 0)
kind = MemberVariable.KIND_STATIC;
else
kind = MemberVariable.KIND_INSTANCE;
memberVariable = new MemberVariable(name, desc, kind);
memberFieldVector.add(memberVariable);
return fieldVisitor;
}
public MethodVisitor visitMethod(int access, String methodName, String desc, String signature,
String[] exceptions) {
MethodVisitor aMethodVisitor =
super.visitMethod(access, methodName, desc, signature, exceptions);
if (sourceFileName == null)
return aMethodVisitor;
if (methodName.equals("toString") && desc.equals("()Ljava/lang/String;"))
return aMethodVisitor;
String key = methodName + desc;
Hashtable lineVariableHashtable = (Hashtable) localVariableVectorHashtable.get(key);
Vector labelVector = (Vector) labelVectorHashtable.get(key);
MyMethodAdapter myMethodAdapter = new MyMethodAdapter(aMethodVisitor, access, methodName,
desc, classNameWithSlash, sourceFileName, memberFieldVector, labelVector,
lineVariableHashtable);
myMethodAdapterVector.add(myMethodAdapter);
return myMethodAdapter;
}
public void visitSource(String file, String debug) {
super.visitSource(file, debug);
sourceFileName = file;
if (Options.debug)
System.out.println("MyClassWriter.visitSource: sourceFileName="+sourceFileName);
}
}