Scanner { @SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE") public static List<Invocation> findUsages(final Supplier<InputStream> classSupplier, final Set<Method> invokedMethods) throws IOException { try (InputStream is = classSupplier.get()) { ClassReader reader = new ClassReader(is); List<Invocation> result = new ArrayList<>(); reader.accept(new MethodInvocationClassVisitor(result, invokedMethods), 0); return result; } } private  Scanner(); @SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE") // Findbugs does not like try with resources. static List<Invocation> findUsages(final Supplier<InputStream> classSupplier,
          final Set<Method> invokedMethods); static List<Invocation> findUsages(final Class<?> clasz, final Set<Method> invokedMethods); static List<Invocation> findUsages(final ClassLoader cl,
          final String claszResourcePath, final Set<Method> invokedMethods); static List<Invocation> findUsages(final String packageName, final Set<Method> invokedMethods);  }
@Test public void testScan() throws NoSuchMethodException, IOException { List<Invocation> findUsages = Scanner.findUsages(ScannerTest.class, ImmutableSet.of(A.class.getDeclaredMethod("getValue"))); LOG.debug("Usages: {}", findUsages); final ImmutableSet<Method> lookFor = ImmutableSet.of(System.class.getDeclaredMethod("getProperty", String.class), System.class.getDeclaredMethod("getProperty", String.class, String.class), Integer.class.getDeclaredMethod("getInteger", String.class), Integer.class.getDeclaredMethod("getInteger", String.class, int.class), Integer.class.getDeclaredMethod("getInteger", String.class, Integer.class), Long.class.getDeclaredMethod("getLong", String.class), Long.class.getDeclaredMethod("getLong", String.class, Long.class), Long.class.getDeclaredMethod("getLong", String.class, long.class), Boolean.class.getDeclaredMethod("getBoolean", String.class)); List<Invocation> findUsages2 = Scanner.findUsages(ScannerTest.class, lookFor); LOG.debug("Scan 1 = {}", findUsages2); List<Invocation> findUsages3 = Scanner.findUsages(ScannerTest.class.getPackage().getName(), lookFor); LOG.debug("Scan 2 = {}", findUsages3); Assert.assertThat(findUsages2, CoreMatchers.hasItem( Matchers.allOf( Matchers.hasProperty("caleeMethodName", Matchers.equalTo("method")), Matchers.hasProperty("invokedMethod", Matchers.hasProperty("name", Matchers.equalTo("getInteger"))), Matchers.hasProperty("parameters", Matchers.arrayContaining("spf4j.custom.prop2", 1))))); Assert.assertThat(findUsages2, CoreMatchers.hasItem( Matchers.allOf( Matchers.hasProperty("caleeMethodName", Matchers.equalTo("testSomeMethod")), Matchers.hasProperty("invokedMethod", Matchers.hasProperty("name", Matchers.equalTo("getProperty"))), Matchers.hasProperty("parameters", Matchers.arrayContaining("some.property", "default value"))))); Assert.assertThat(findUsages2, CoreMatchers.hasItem( Matchers.allOf( Matchers.hasProperty("caleeMethodName", Matchers.equalTo("testSomeMethod")), Matchers.hasProperty("invokedMethod", Matchers.hasProperty("name", Matchers.equalTo("getLong"))), Matchers.hasProperty("parameters", Matchers.arrayContaining("someLong.value", 5L))))); }