package net.md_5.specialsource;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;

/**
 * Lookup inheritance from a class in a given URLClassLoader.
 */
public class URLClassLoaderInheritanceProvider implements IInheritanceProvider {
    private final URLClassLoader classLoader;

    public URLClassLoaderInheritanceProvider(URLClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<String> getParents(String owner) {
        try {
            String ownerInternalName = owner.replace('.', '/').concat(".class");
            URL url = classLoader.findResource(ownerInternalName);
            if (url == null) {
                return null;
            }

            InputStream inputStream = url.openStream();
            if (inputStream == null) {
                return null;
            }

            // TODO: refactor

            ClassReader cr = new ClassReader(inputStream);
            ClassNode node = new ClassNode();
            cr.accept(node, 0);

            List<String> parents = new ArrayList<String>();

            for (String iface : (List<String>) node.interfaces) {
                parents.add(iface);
            }
            parents.add(node.superName);

            return parents;
        } catch (IOException ex) {
            return null;
        }
    }
}

@@ -463,16 +463,51 @@
 sLoader;
+%0A    private final boolean verbose;
 %0A%0A    pu
@@ -571,16 +571,33 @@
 ssLoader
+, boolean verbose
 ) %7B%0A    
@@ -628,24 +628,56 @@
 lassLoader;%0A
+        this.verbose = verbose;%0A
     %7D%0A%0A    @
@@ -866,16 +866,160 @@
 lass%22);%0A
+            if (verbose) %7B%0A                System.out.println(%22URLClassLoaderInheritanceProvider looking up %22+ownerInternalName);%0A            %7D%0A
         
@@ -1295,39 +1295,8 @@
  %7D%0A%0A
-            // TODO: refactor%0A%0A
     
@@ -1608,114 +1608,492 @@
     
-%7D%0A            parents.add(node.superName);%0A%0A            return parents;%0A        %7D catch (IOException ex) %7B
+    if (verbose) %7B%0A                    System.out.println(%22 - %22+iface);%0A                %7D%0A            %7D%0A            parents.add(node.superName);%0A            if (verbose) %7B%0A                System.out.println(%22 + %22+node.superName);%0A            %7D%0A%0A            return parents;%0A        %7D catch (IOException ex) %7B%0A            if (verbose) %7B%0A                System.out.println(%22URLClassLoaderInheritanceProvider %22+owner+%22 exception: %22+ex);%0A                ex.printStackTrace();%0A            %7D
 %0A   

Add verbose mode to URLClassLoaderInheritanceProvider