private static boolean lookForInterface( java.lang.Class<?> klass, String className, Set<java.lang.Class<?>> alreadyVisited) { if (klass.getName().equals(className)) return true; // did we already visit this type? if (!alreadyVisited.add(klass)) return false; // first see if it satisfies it directly SatisfiedTypes satisfiesAnnotation = klass.getAnnotation(SatisfiedTypes.class); if (satisfiesAnnotation != null) { for (String satisfiedType : satisfiesAnnotation.value()) { satisfiedType = declClassName(satisfiedType); int i = satisfiedType.indexOf('<'); if (i > 0) { satisfiedType = satisfiedType.substring(0, i); } try { if (lookForInterface( java.lang.Class.forName(satisfiedType, true, klass.getClassLoader()), className, alreadyVisited)) { return true; } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } } // now look at this class's interfaces for (java.lang.Class<?> intrface : klass.getInterfaces()) { if (lookForInterface(intrface, className, alreadyVisited)) return true; } // no luck return false; }
private List<Field> buildFieldsList(List<Field> result, Set<String> seen, boolean publicOnly) { for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { for (Field f : c.getClassCache().getDeclaredFields(false, publicOnly)) { String s = f.toString(); if (!seen.contains(s)) { result.add(f); seen.add(s); } } for (Class<?> intf : c.getInterfaces()) { intf.getClassCache().buildFieldsList(result, seen, publicOnly); } } return result; }
private List<Method> buildMethodsList( List<Method> result, Set<MethodHashKey> seen, boolean publicOnly) { for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { for (Method m : c.getClassCache().getDeclaredMethods(false, publicOnly)) { MethodHashKey key = new MethodHashKey(m); if (!seen.contains(key)) { result.add(m); seen.add(key); } } } for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { for (Class<?> intf : c.getInterfaces()) { intf.getClassCache().buildMethodsList(result, seen, publicOnly); } } return result; }