package fi.evident.apina.java.reader;

import fi.evident.apina.java.model.JavaClass;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public final class ClassReaderUtils {

    private ClassReaderUtils() { }

    public static JavaClass loadClass(Class<?> cl) {
        try (InputStream in = openInputStreamForClassBytes(cl)) {
            return ClassMetadataReader.loadMetadata(in);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static InputStream openInputStreamForClassBytes(Class<?> cl) throws IOException {
        String resourceName = cl.getName().replace('.', '/') + ".class";
        InputStream inputStream = cl.getClassLoader().getResourceAsStream(resourceName);
        if (inputStream != null)
            return inputStream;
        else
            throw new FileNotFoundException(resourceName);
    }
}

@@ -686,16 +686,167 @@
 class%22;%0A
+        ClassLoader classLoader = cl.getClassLoader();%0A        if (classLoader == null)%0A            classLoader = ClassLoader.getSystemClassLoader();%0A%0A
         
@@ -869,30 +869,24 @@
 tStream = cl
-.getCl
 assLoader().
@@ -882,18 +882,16 @@
 ssLoader
-()
 .getReso

Support loading classes that use system classloader