package org.k13n.asmstubber;

import java.io.IOException;

import org.k13n.asmstubber.indexing.ClassIndex;
import org.k13n.asmstubber.indexing.ClassIndexer;
import org.k13n.asmstubber.util.FileUtil;
import org.k13n.asmstubber.visitors.ClassTransformer;

public class App {

  public static void main(String[] args) {
    ClassIndex index = new ClassIndex();
    ClassIndexer indexer = new ClassIndexer(index);

    indexer.index("/path/to/swt/jar/file");
    System.out.printf("Indexed classes: %d%n", index.keys().size());

    final String targetDirectory = "/path/to/store/the/transformed/class/files";

    ClassTransformer.Callback cb = new ClassTransformer.Callback() {
      @Override public void accept(String className, byte[] bytecode) {
        try {
          FileUtil.writeBytecode(targetDirectory, className, bytecode);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    };
    new ClassTransformer(index, cb).transform();
  }

}

@@ -270,48 +270,244 @@
 p %7B%0A
-%0A  public static void main(String%5B%5D args
+  private final String inputPath;%0A  private final String targetDirectory;%0A%0A  private App(String inputPath, String targetDirectory) %7B%0A    this.inputPath = inputPath;%0A    this.targetDirectory = targetDirectory;%0A  %7D%0A%0A  public void execute(
 ) %7B%0A
@@ -599,17 +599,16 @@
 index);%0A
-%0A
     inde
@@ -621,183 +621,18 @@
 dex(
-%22/path/to/swt/jar/file%22);%0A    System.out.printf(%22Indexed classes: %25d%25n%22, index.keys().size());%0A%0A    final String targetDirectory = %22/path/to/store/the/transformed/class/files%22
+inputPath)
 ;%0A%0A 
@@ -1001,10 +1001,468 @@
 );%0A  %7D%0A%0A
+  public static void main(String%5B%5D args) %7B%0A    if (args.length %3C 2) %7B%0A      printUsage();%0A      System.exit(1);%0A    %7D%0A    new App(args%5B0%5D, args%5B1%5D).execute();%0A  %7D%0A%0A  private static void printUsage() %7B%0A    System.out.println(%22Two arguments are required, the parameters are:%22);%0A    System.out.println(%22  %3Cinput path%3E %3Ctarget directory%3E%22);%0A    System.out.println(%22The input path can be either a single class file, %22 +%0A        %22a directory or a jar file%22);%0A  %7D%0A%0A
 %7D%0A

Refactor the App class