public static String classToResource(Class<?> clazz) { if (clazz == null) return null; return classToResource(clazz.getName()); }
public static InputStream getClassInputStream(String className, ClassLoader cl) { final String resource = classToResource(className); return cl != null ? cl.getResourceAsStream(resource) : ClassLoader.getSystemResourceAsStream(resource); }
public static ClassNode getClassNode(String className, ClassLoader cl, boolean skipCode) throws IOException { final ClassNode cn = getClassNode(getClassInputStream(className, cl), skipCode); if (cn == null) throw new IOException("Resource " + classToResource(className) + " not found."); return cn; }
/** * Visits classes whose methods are found in the suspendables file, as if they were part of the project */ private void scanSuspendablesFile(Function<InputStream, Void> classFileVisitor) { // scan classes in suspendables file if (suspendablesFile != null) { SimpleSuspendableClassifier tssc = new SimpleSuspendableClassifier(suspendablesFile); final Set<String> cs = new HashSet<>(); cs.addAll(tssc.getSuspendableClasses()); for (String susMethod : tssc.getSuspendables()) cs.add(susMethod.substring(0, susMethod.indexOf('.'))); for (String className : cs) { try { log("Scanning suspendable class:" + className, Project.MSG_VERBOSE); classFileVisitor.apply(cl.getResourceAsStream(classToResource(className))); } catch (Exception e) { throw new RuntimeException("Exception while processing " + className, e); } } } }
&& !name.contains("$")) { // if class is possibly an inner class, don't use parent's, which will be in a different runtime package try { String resourceName = classToResource(name); URL parentUrl = parent.getResource(resourceName); LOG.debug("findClass {} in module {} - parent URL: {}", name, this, parentUrl);
private ClassNode fill(ClassNode node) { if (node.supers == null) { try (InputStream is = ClassLoaderUtil.getResourceAsStream(cl, classToResource(node.name))) { final ClassReader cr = new ClassReader(is); cr.accept(new ClassNodeVisitor(false, ASMAPI, null), ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE); assert node.supers != null; } catch (IOException e) { throw new RuntimeException("during processing of " + node.name, e); } } return node; }