The reflections project is able to find and return all classes in the classpath. Here is a working example:
ReflectionUtils.forNames(new Reflections(new ConfigurationBuilder().setScanners(new SubTypesScanner(false)) .addUrls(ClasspathHelper.forClassLoader())) .getAllTypes()).stream() .filter(Class::isInterface) .collect(toMap(c -> c, c -> Arrays.stream(c.getMethods()) .filter(m -> !m.isDefault()) .filter(m -> !Modifier.isStatic(m.getModifiers())) .filter(m -> !isObjectMethod(m)) .collect(toSet()))) .entrySet().stream() .filter(e -> e.getValue().size() == 1) .sorted(comparing(e -> e.getKey().toString())) .map(e -> e.getKey().toString() + " has single method " + e.getValue())
The isObjectMethod is defined as follows:
private static final Set<Method> OBJECT_METHODS = ImmutableSet.copyOf(Object.class.getMethods()); private static boolean isObjectMethod(Method m){ return OBJECT_METHODS.stream() .anyMatch(om -> m.getName().equals(om.getName()) && m.getReturnType().equals(om.getReturnType()) && Arrays.equals(m.getParameterTypes(), om.getParameterTypes())); }
This will not help you return to the source code and add annotations, but it will give you a list for work.
source share