ClassLoader { public static DeclaredClass load(InputStream in) throws IOException { ClassNode classNode = readClassNode(in); Set<ClassTypeDescriptor> parents = readParents(classNode); Set<DeclaredField> declaredFields = readDeclaredFields(classNode); Map<MethodDescriptor, DeclaredMethod> declaredMethods = new HashMap<>(); Set<ClassTypeDescriptor> loadedClasses = new HashSet<>(); for (MethodNode method : classNode.methods) { analyseMethod(classNode.name, method, declaredMethods, loadedClasses); } return new DeclaredClassBuilder() .className(TypeDescriptors.fromClassName(classNode.name)) .methods(declaredMethods) .parents(parents) .loadedClasses(loadedClasses) .fields(declaredFields) .build(); } private  ClassLoader(); static DeclaredClass load(InputStream in);  }
@Test public void testLoad() throws Exception { final DeclaredClass declaredClass = ClassLoader.load(inputStream); assertThat(declaredClass).isNotNull(); assertThat(declaredClass.methods()).isNotEmpty(); }
@Test public void shouldHandleLoadingOfType() throws Exception { try (FileInputStream inputStream = findClass(LdcLoadType.class)) { DeclaredClass loaded = ClassLoader.load(inputStream); assertThat(loaded.className().getClassName()).contains("LdcLoadType"); } }
@Test public void shouldHandleLoadingOfArrayOfType() throws Exception { try (FileInputStream inputStream = findClass(LdcLoadArrayOfType.class)) { DeclaredClass loaded = ClassLoader.load(inputStream); assertThat(loaded.className().getClassName()).contains("LdcLoadArrayOfType"); assertThat(loaded.loadedClasses()) .containsExactly(TypeDescriptors.fromClassName(Object.class.getName())); } }
@Test public void shouldHandleLoadingOfArrayOfPrimitive() throws Exception { try (FileInputStream inputStream = findClass(LdcLoadArrayOfPrimitive.class)) { DeclaredClass loaded = ClassLoader.load(inputStream); assertThat(loaded.className().getClassName()).contains("LdcLoadArrayOfPrimitive"); assertThat(loaded.loadedClasses()).isEmpty(); } }