@Override protected List<ClassStructure> initialValue() { return newInstances(classReader.getInterfaces()); } };
private static List<String> classInterfaces(String name, ClassLoader classLoader) { ImmutableList.Builder<String> list = ImmutableList.builder(); ClassReader reader = readClass(name, classLoader); for (String binaryName : reader.getInterfaces()) { list.add(javaName(binaryName)); } if (reader.getSuperName() != null) { list.addAll(classInterfaces(javaName(reader.getSuperName()), classLoader)); } return list.build(); }
String[] interfaces = classReader.getInterfaces(); if (interfaces != null && interfaces.length > 0) { for (int i = 0; i < interfaces.length; i++) {
/** * Returns true if the given type implements the given interface. * * @param type the internal name of a class or interface. * @param info the ClassReader corresponding to 'type'. * @param itf the internal name of a interface. * @return true if 'type' implements directly or indirectly 'itf' * @throws IOException if the bytecode of 'type' or of some of its ancestor * class cannot be loaded. */ private boolean typeImplements(String type, ClassReader info, String itf) throws IOException { while (!"java/lang/Object".equals(type)) { String[] itfs = info.getInterfaces(); for (int i = 0; i < itfs.length; ++i) { if (itfs[i].equals(itf)) { return true; } } for (int i = 0; i < itfs.length; ++i) { if (typeImplements(itfs[i], typeInfo(itfs[i]), itf)) { return true; } } type = info.getSuperName(); info = typeInfo(type); } return false; } /**
byte[] bytecode = [read bytes from class or jar file]; ClassReader reader = new ClassReader( bytecode ); String[] interfaces = reader.getInterfaces();
in = url.openStream(); ClassReader classReader = new ClassReader(in); String[] superInterfaceNames = classReader.getInterfaces(); for (String superInterfaceName : superInterfaceNames) { if (isInterfaceAssignable(superInterfaceName)) {
public static Class<?> getClass(String classString, Options options) throws ClassNotFoundException, IOException { String className = classString.replace('.', '/') + ".class"; InputStream stream = FabricLauncherBase.getLauncher().getResourceAsStream(className); if (stream == null) { throw new ClassNotFoundException("Could not find or load class " + className); } ClassReader reader = new ClassReader(stream); for (String s : reader.getInterfaces()) { if (!canApplyInterface(s)) { switch (options.getMissingSuperclassBehavior()) { case RETURN_NULL: stream.close(); return null; case CRASH: default: stream.close(); throw new ClassNotFoundException("Could not find or load class " + s); } } } stream.close(); return Class.forName(classString); }
private static List<String> classInterfaces(String name, ClassLoader classLoader) { ImmutableList.Builder<String> list = ImmutableList.builder(); ClassReader reader = readClass(name, classLoader); for (String binaryName : reader.getInterfaces()) { list.add(javaName(binaryName)); } if (reader.getSuperName() != null) { list.addAll(classInterfaces(javaName(reader.getSuperName()), classLoader)); } return list.build(); }
private static List<String> classInterfaces(String name, ClassLoader classLoader) { ImmutableList.Builder<String> list = ImmutableList.builder(); ClassReader reader = readClass(name, classLoader); for (String binaryName : reader.getInterfaces()) { list.add(javaName(binaryName)); } if (reader.getSuperName() != null) { list.addAll(classInterfaces(javaName(reader.getSuperName()), classLoader)); } return list.build(); }
private static List<String> classInterfaces(String name, ClassLoader classLoader) { ImmutableList.Builder<String> list = ImmutableList.builder(); ClassReader reader = readClass(name, classLoader); for (String binaryName : reader.getInterfaces()) { list.add(javaName(binaryName)); } if (reader.getSuperName() != null) { list.addAll(classInterfaces(javaName(reader.getSuperName()), classLoader)); } return list.build(); }
private Set<String> addSuperInterfaces(String superName, Set<String> ifaces) { if (normalize(superName).equals("java.lang.Object")) { return ifaces; } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); String path = superName.replace('.', '/'); InputStream is = null; try { is = classLoader.getResourceAsStream(path + ".class"); if (null != is) { ClassReader classReader = new ClassReader(is); ifaces.addAll(normalize(classReader.getInterfaces())); return addSuperInterfaces(classReader.getSuperName(), ifaces); } } catch (Exception e) { //don't care } finally { IOUtils.closeQuietly(is); } return ifaces; }
is.close(); String[] ifaces = cr.getInterfaces(); for (String iface : ifaces)
private boolean typeImplements(String type, ClassReader info, String itf) throws IOException { while (!"java/lang/Object".equals(type)) { String[] itfs = info.getInterfaces(); for (String itf2 : itfs) { if (itf2.equals(itf)) { return true; } } for (String itf1 : itfs) { if (typeImplements(itf1, typeInfo(itf1), itf)) { return true; } } type = info.getSuperName(); info = typeInfo(type); } return false; }
throws IOException { while (!"java/lang/Object".equals(type)) { String[] itfs = info.getInterfaces(); for (int i = 0; i < itfs.length; ++i) { if (itfs[i].equals(itf)) {
String[] itfs = info.getInterfaces(); for (int i = 0; i < itfs.length; ++i) { if (itfs[i].equals(itf)) {
String[] itfs = info.getInterfaces(); for (int i = 0; i < itfs.length; ++i) { if (itfs[i].equals(itf)) {
throws IOException { while (!"java/lang/Object".equals(type)) { String[] itfs = info.getInterfaces(); for (int i = 0; i < itfs.length; ++i) { if (itfs[i].equals(itf)) {
String[] itfs = info.getInterfaces(); for (int i = 0; i < itfs.length; ++i) { if (itfs[i].equals(itf)) {
String[] interfaceNames = classReader.getInterfaces(); try { for (String interfaceName : interfaceNames) {
private static boolean canApplyInterface(String itfString) throws IOException { String className = itfString + ".class"; // TODO: Be a bit more involved switch (itfString) { case "net/fabricmc/api/ClientModInitializer": if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) { return false; } break; case "net/fabricmc/api/DedicatedServerModInitializer": if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { return false; } } InputStream stream = FabricLauncherBase.getLauncher().getResourceAsStream(className); if (stream == null) { return false; } ClassReader reader = new ClassReader(stream); for (String s : reader.getInterfaces()) { if (!canApplyInterface(s)) { stream.close(); return false; } } stream.close(); return true; }