package org.k13n.swtstubber.visitors;

import org.k13n.swtstubber.codegen.EmptyMethodFactory;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class SwtClassVisitor extends ClassVisitor {
  private final ClassVisitor visitor;

  public SwtClassVisitor(ClassVisitor visitor) {
    super(Opcodes.ASM4, visitor);
    this.visitor = visitor;
  }

  @Override
  public MethodVisitor visitMethod(int access, String name, String desc,
      String signature, String[] exceptions) {
    if (isAbstractMethod(access)) {
      super.visitMethod(access, name, desc, signature, exceptions);
      return null;
    }
    MethodVisitor methodVisitor = visitor.visitMethod(access, name, desc,
        signature, exceptions);
    if (isConstructor(name)) {
      return new ConstructorVisitor(methodVisitor);
    } else {
      EmptyMethodFactory.createMethod(desc).generate(methodVisitor);
      return null;
    }
  }

  private boolean isAbstractMethod(int access) {
    return (access & Opcodes.ACC_ABSTRACT) != 0;
  }

  private boolean isConstructor(String name) {
    return name.equals("<init>");
  }

}

@@ -87,16 +87,73 @@
 actory;%0A
+import org.k13n.swtstubber.codegen.EmptyMethodGenerator;%0A
 import o
@@ -605,50 +605,44 @@
     
-if (isAbstractMethod(access)) %7B%0A      supe
+MethodVisitor methodVisitor = visito
 r.vi
@@ -670,16 +670,24 @@
 e, desc,
+%0A       
  signatu
@@ -711,138 +711,65 @@
     
-  return null;%0A    %7D%0A    MethodVisitor methodVisitor = visitor.visitMethod(access, name, desc,%0A        signature, exceptions);%0A   
+if (isAbstractMethod(access))%0A      return null;%0A    else
  if 
@@ -789,18 +789,16 @@
 r(name))
- %7B
 %0A      r
@@ -849,111 +849,67 @@
 %0A   
- %7D
  else
- %7B
 %0A      
-EmptyMethodFactory.createMethod(desc).generate(methodVisitor);%0A      return null;%0A    %7D
+return handleNormalMethod(desc, methodVisitor);
 %0A  %7D
@@ -1099,10 +1099,241 @@
 );%0A  %7D%0A%0A
+  private MethodVisitor handleNormalMethod(String desc,%0A      MethodVisitor methodVisitor) %7B%0A    EmptyMethodGenerator generator = EmptyMethodFactory.createMethod(desc);%0A    generator.generate(methodVisitor);%0A    return null;%0A  %7D%0A%0A%0A
 %7D%0A

Refactor the SwtClassVisitor class