public static <T extends ClassVisitor> T accept(String className, ClassLoader cl, int flags, T visitor) throws IOException { return accept(getClassInputStream(className, cl), flags, visitor); }
public static MethodNode getMethod(MethodNode method, List<MethodNode> ms) { if (ms == null) return null; for (MethodNode m : ms) { if (equals(method, m)) return m; } return null; }
public static ClassNode getClassNode(Class<?> clazz, boolean skipCode) throws IOException { return getClassNode(getClassInputStream(clazz), skipCode); }
private boolean findSuperDeclarations(ClassNode cls, ClassNode declaringClass, MethodNode method) throws IOException { if (cls == null) return false; boolean foundMethod = false; MethodNode m; if ((m = getMethod(method, cls)) != null) { foundMethod = true; if (!ASMUtil.equals(cls, declaringClass) && !isSuspendable(cls, m)) { log("Found parent of annotated method: " + declaringClass.name + "." + method.name + method.signature + " in " + cls.name, Project.MSG_VERBOSE); results.add(cls.name.replace('/', '.') + '.' + method.name); } } // recursively look in superclass and interfaces boolean methodInParent = false; methodInParent |= findSuperDeclarations(getClassNode(cls.superName, cl, true), declaringClass, method); for (String iface : (List<String>) cls.interfaces) methodInParent |= findSuperDeclarations(getClassNode(iface, cl, true), declaringClass, method); if (!foundMethod && methodInParent) { log("Found parent of annotated method in a parent of: " + declaringClass.name + "." + method.name + method.signature + " in " + cls.name, Project.MSG_VERBOSE); results.add(cls.name.replace('/', '.') + '.' + method.name); } return foundMethod | methodInParent; }
public static boolean hasAnnotation(Class ann, FieldNode f) { return hasAnnotation(ann, f.visibleAnnotations); }
private static boolean isAssignableFrom0(String supertypeName, String className, ClassLoader cl) { try { if (className == null) return false; if (supertypeName.equals(className)) return true; ClassNode cn = getClassNode(className, cl, true); if (supertypeName.equals(cn.superName)) return true; if (isAssignableFrom0(supertypeName, cn.superName, cl)) return true; if (cn.interfaces != null) { for (String iface : (List<String>) cn.interfaces) { if (supertypeName.equals(iface)) return true; if (isAssignableFrom0(supertypeName, iface, cl)) return true; } } return false; } catch (IOException e) { // e.printStackTrace(); throw new RuntimeException(e); } }
public static byte[] getClass(String className, ClassLoader cl) throws IOException { try (InputStream is = getClassInputStream(className, cl)) { return ByteStreams.toByteArray(is); } }
private void scanClass(File file) throws Exception { log("Scanning " + file, Project.MSG_VERBOSE); if (file != null) { if (USE_REFLECTION) scanClass(Class.forName(extractClassName(file))); else scanClass(getClassNode(new FileInputStream(file), true)); } }
public static ClassNode getClassNode(InputStream is, boolean skipCode) throws IOException { return accept(is, ClassReader.SKIP_DEBUG | (skipCode ? 0 : ClassReader.SKIP_CODE), new ClassNode()); }
public static MethodNode getMethod(MethodNode method, ClassNode c) { return getMethod(method, c.methods); }
private static boolean hasMethodWithDescriptor(String nameAndDescSuffix, Class<?> c) { if (nameAndDescSuffix == null || c == null) return false; for (final Method m : c.getDeclaredMethods()) { final String n = "." + m.getName() + ASMUtil.getDescriptor(m); if (nameAndDescSuffix.equals(n)) return true; } if (hasMethodWithDescriptor(nameAndDescSuffix, c.getSuperclass())) return true; for (final Class<?> i : c.getInterfaces()) { if (hasMethodWithDescriptor(nameAndDescSuffix, i)) return true; } return false; }
public static boolean hasMethod(MethodNode method, ClassNode c) { return hasMethod(method, c.methods); }
private boolean isAutomaticUpgrade(String className) { for (Class<?> c : AUTOMATIC_UPGRADE_CLASSES) { if (ASMUtil.isAssignableFrom(c, className, ActorModule.this)) { LOG.debug("Automatic upgrade of class {} (implements/extends {})", className, c); return true; } } return false; }
private static String[] getReadableCallsites(String[] callsites) { String[] readable = new String[callsites.length]; for (int i = 0; i < callsites.length; i++) readable[i] = SuspendableHelper.getCallsiteOwner(callsites[i]) + "." + SuspendableHelper.getCallsiteName(callsites[i]) + ASMUtil.getReadableDescriptor(SuspendableHelper.getCallsiteDesc(callsites[i])); return readable; }
public static boolean hasAnnotation(Class ann, MethodNode m) { return hasAnnotation(ann, m.visibleAnnotations); }
public static byte[] getClass(Class<?> klass) throws IOException { try (InputStream is = getClassInputStream(klass)) { return ByteStreams.toByteArray(is); } }
private void scanSuspendablesFile() throws Exception { // scan classes in suspendables file if (ssc != null) { Set<String> classes = new HashSet<>(); for (String susCls : ssc.getSuspendableClasses()) classes.add(susCls); for (String susMethod : ssc.getSuspendables()) classes.add(susMethod.substring(0, susMethod.indexOf('.'))); for (String className : classes) { log("scanning suspendable class:" + className, Project.MSG_VERBOSE); scanClass(getClassNode(className, cl, true)); } } }
try { final AtomicReference<String> descriptor = new AtomicReference<>(); ASMUtil.accept(este.getDeclaringClass(), ClassReader.SKIP_FRAMES, new ClassVisitor(Opcodes.ASM5) { @Override public MethodVisitor visitMethod(int access, String name, final String desc, String signature, String[] exceptions) {
public static boolean hasMethod(MethodNode method, List<MethodNode> ms) { return getMethod(method, ms) != null; }
final String nameAndDescSuffix = "." + callee.getName() + ASMUtil.getDescriptor(callee); final String[] callsites = i.suspendableCallSiteNames(); for (String callsite : callsites) {