public void visitEnd() {
if (generationAllowed) {
if (!clinitfound) {
logger.log(BasicLevel.DEBUG, "Adding static area in " + classToWrite);
CodeVisitor c = cv.visitMethod(Constants.ACC_STATIC,
"<clinit>", "()V", null, null);
addClassRegistrationCode(c);
c.visitInsn(RETURN);
c.visitMaxs(0, 0);
clinitfound = true;
}
if (!classMethodfound) {
classMethodfound = true;
logger.log(BasicLevel.DEBUG, "Adding static method class$(String)Class in " + classToWrite);
CodeVisitor c = cv.visitMethod(ACC_STATIC + ACC_SYNTHETIC, CLASS_METH,
"(Ljava/lang/String;)Ljava/lang/Class;", null, null);
//try {
final Label l0 = new Label();
c.visitLabel(l0);
//return Class.forName(str)
c.visitVarInsn(ALOAD, 0);
c.visitMethodInsn(INVOKESTATIC, "java/lang/Class", "forName",
"(Ljava/lang/String;)Ljava/lang/Class;");
final Label l1 = new Label();
c.visitLabel(l1);
c.visitInsn(ARETURN);
final Label l2 = new Label();
c.visitLabel(l2);
c.visitVarInsn(ASTORE, 1);
c.visitTypeInsn(NEW, "java/lang/NoClassDefFoundError");
c.visitInsn(DUP);
c.visitVarInsn(ALOAD, 1);
c.visitMethodInsn(INVOKEVIRTUAL, "java/lang/ClassNotFoundException",
"getMessage", "()Ljava/lang/String;");
c.visitMethodInsn(INVOKESPECIAL, "java/lang/NoClassDefFoundError",
"<init>", "(Ljava/lang/String;)V");
c.visitInsn(ATHROW);
c.visitTryCatchBlock(l0, l1, l2, "java/lang/ClassNotFoundException");
c.visitMaxs(0, 0);
}
if (!classFieldfound) {
classFieldfound = true;
logger.log(BasicLevel.DEBUG, "Adding static field '"
+ fieldName + " in " + classToWrite);