Last active
August 29, 2015 14:22
-
-
Save varren/77834294142ddcbb70cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void testMethods() { | |
// need to have 'org.reflections:reflections:0.9.10' | |
// can dowload from here gist.github.com/hepin1989/5026900 | |
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>(); | |
classLoadersList.add(ClasspathHelper.contextClassLoader()); | |
classLoadersList.add(ClasspathHelper.staticClassLoader()); | |
Reflections reflections = new Reflections(new ConfigurationBuilder() | |
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner()) | |
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))) | |
.filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("ru.varren")))); | |
Set<Class<?>> allClasses = | |
reflections.getSubTypesOf(Object.class); | |
HashMap<String, MethodInfo> map = new HashMap<>(); | |
System.out.println("allClasses " + allClasses.size()); | |
for (Class c : allClasses) { | |
for (Method method : c.getDeclaredMethods()) { | |
String key = c.getName() + "." + method.getName(); | |
if (!map.containsKey(key)) { | |
map.put(key, new MethodInfo(c)); | |
} | |
MethodInfo methodInfo = map.get(key); | |
methodInfo.methods.add(method); | |
} | |
} | |
for (String key : map.keySet()) { | |
MethodInfo info = map.get(key); | |
if (info.methods.size() > 1) { | |
System.out.println(key + " : " + info.methods.size()); | |
} | |
} | |
} | |
public static class MethodInfo { | |
public MethodInfo(Class fromClass) { | |
this.fromClass = fromClass; | |
} | |
Class fromClass; | |
ArrayList<Method> methods = new ArrayList<>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment