public boolean apply(@Nullable String input) { final Class<?> type = forName(input, loaders()); return type != null && !type.isInterface(); } }));
/** try to resolve all given string representation of types to a list of java types */ public static <T> List<Class<? extends T>> forNames(final Iterable<String> classes, ClassLoader... classLoaders) { List<Class<? extends T>> result = new ArrayList<Class<? extends T>>(); for (String className : classes) { Class<?> type = forName(className, classLoaders); if (type != null) { result.add((Class<? extends T>) type); } } return result; }
/** try to resolve all given string representation of types to a list of java types */ public static <T> List<Class<? extends T>> forNames(final Iterable<String> classes, ClassLoader... classLoaders) { List<Class<? extends T>> result = new ArrayList<Class<? extends T>>(); for (String className : classes) { Class<?> type = forName(className, classLoaders); if (type != null) { result.add((Class<? extends T>) type); } } return result; }
public boolean apply(@Nullable String input) { final Class<?> type = forName(input, loaders()); return type != null && !type.isInterface(); } }));
public static Field getFieldFromString(String field, ClassLoader... classLoaders) { String className = field.substring(0, field.lastIndexOf('.')); String fieldName = field.substring(field.lastIndexOf('.') + 1); try { return forName(className, classLoaders).getDeclaredField(fieldName); } catch (NoSuchFieldException e) { throw new ReflectionsException("Can't resolve field named " + fieldName, e); } }
public Class getOrCreateClassObject(Vfs.File file, @Nullable ClassLoader... loaders) throws Exception { String name = file.getRelativePath().replace("/", ".").replace(".class", ""); return forName(name, loaders); }
public static Field getFieldFromString(String field, ClassLoader... classLoaders) { String className = field.substring(0, field.lastIndexOf('.')); String fieldName = field.substring(field.lastIndexOf('.') + 1); try { return forName(className, classLoaders).getDeclaredField(fieldName); } catch (NoSuchFieldException e) { throw new ReflectionsException("Can't resolve field named " + fieldName, e); } }
public Class getOfCreateClassObject(Vfs.File file, @Nullable ClassLoader... loaders) throws Exception { String name = file.getRelativePath().replace("/", ".").replace(".class", ""); return forName(name, loaders); }
public static Annotation resolveAnnotation(Class annotation) { try { String name = annotation.getSimpleName().replace(pathSeparator, dotSeparator); Class<?> declaringClass = annotation.getDeclaringClass().getDeclaringClass(); Class<?> aClass = resolveClassOf(declaringClass); Class<? extends Annotation> aClass1 = (Class<? extends Annotation>) ReflectionUtils.forName(name); Annotation annotation1 = aClass.getAnnotation(aClass1); return annotation1; } catch (Exception e) { throw new ReflectionsException("could not resolve to annotation " + annotation.getName(), e); } }
public static Annotation resolveAnnotation(Class annotation) { try { String name = annotation.getSimpleName().replace(pathSeparator, dotSeparator); Class<?> declaringClass = annotation.getDeclaringClass().getDeclaringClass(); Class<?> aClass = resolveClassOf(declaringClass); Class<? extends Annotation> aClass1 = (Class<? extends Annotation>) ReflectionUtils.forName(name); Annotation annotation1 = aClass.getAnnotation(aClass1); return annotation1; } catch (Exception e) { throw new ReflectionsException("could not resolve to annotation " + annotation.getName(), e); } }
public static Method resolveMethod(final Class aMethod) { String methodOgnl = aMethod.getSimpleName(); try { String methodName; Class<?>[] paramTypes; if (methodOgnl.contains(tokenSeparator)) { methodName = methodOgnl.substring(0, methodOgnl.indexOf(tokenSeparator)); String[] params = methodOgnl.substring(methodOgnl.indexOf(tokenSeparator) + 1).split(doubleSeparator); paramTypes = new Class<?>[params.length]; for (int i = 0; i < params.length; i++) { String typeName = params[i].replace(arrayDescriptor, "[]").replace(pathSeparator, dotSeparator); paramTypes[i] = ReflectionUtils.forName(typeName); } } else { methodName = methodOgnl; paramTypes = null; } Class<?> declaringClass = aMethod.getDeclaringClass().getDeclaringClass(); return resolveClassOf(declaringClass).getDeclaredMethod(methodName, paramTypes); } catch (Exception e) { throw new ReflectionsException("could not resolve to method " + aMethod.getName(), e); } } }
public static Method resolveMethod(final Class aMethod) { String methodOgnl = aMethod.getSimpleName(); try { String methodName; Class<?>[] paramTypes; if (methodOgnl.contains(tokenSeparator)) { methodName = methodOgnl.substring(0, methodOgnl.indexOf(tokenSeparator)); String[] params = methodOgnl.substring(methodOgnl.indexOf(tokenSeparator) + 1).split(doubleSeparator); paramTypes = new Class<?>[params.length]; for (int i = 0; i < params.length; i++) { String typeName = params[i].replace(arrayDescriptor, "[]").replace(pathSeparator, dotSeparator); paramTypes[i] = ReflectionUtils.forName(typeName); } } else { methodName = methodOgnl; paramTypes = null; } Class<?> declaringClass = aMethod.getDeclaringClass().getDeclaringClass(); return resolveClassOf(declaringClass).getDeclaredMethod(methodName, paramTypes); } catch (Exception e) { throw new ReflectionsException("could not resolve to method " + aMethod.getName(), e); } } }
/** * expand super types after scanning, for super types that were not scanned. * this is helpful in finding the transitive closure without scanning all 3rd party dependencies. * it uses {@link ReflectionUtils#getSuperTypes(Class)}. * <p> * for example, for classes A,B,C where A supertype of B, B supertype of C: * <ul> * <li>if scanning C resulted in B (B->C in store), but A was not scanned (although A supertype of B) - then getSubTypes(A) will not return C</li> * <li>if expanding supertypes, B will be expanded with A (A->B in store) - then getSubTypes(A) will return C</li> * </ul> */ public void expandSuperTypes() { if (store.keySet().contains(index(SubTypesScanner.class))) { Multimap<String, String> mmap = store.get(index(SubTypesScanner.class)); Sets.SetView<String> keys = Sets.difference(mmap.keySet(), Sets.newHashSet(mmap.values())); Multimap<String, String> expand = HashMultimap.create(); for (String key : keys) { final Class<?> type = forName(key); if (type != null) { expandSupertypes(expand, key, type); } } mmap.putAll(expand); } }
/** * expand super types after scanning, for super types that were not scanned. * this is helpful in finding the transitive closure without scanning all 3rd party dependencies. * it uses {@link ReflectionUtils#getSuperTypes(Class)}. * <p> * for example, for classes A,B,C where A supertype of B, B supertype of C: * <ul> * <li>if scanning C resulted in B (B->C in store), but A was not scanned (although A supertype of B) - then getSubTypes(A) will not return C</li> * <li>if expanding supertypes, B will be expanded with A (A->B in store) - then getSubTypes(A) will return C</li> * </ul> */ public void expandSuperTypes() { if (store.keySet().contains(index(SubTypesScanner.class))) { Multimap<String, String> mmap = store.get(index(SubTypesScanner.class)); Sets.SetView<String> keys = Sets.difference(mmap.keySet(), Sets.newHashSet(mmap.values())); Multimap<String, String> expand = HashMultimap.create(); for (String key : keys) { final Class<?> type = forName(key, loaders()); if (type != null) { expandSupertypes(expand, key, type); } } mmap.putAll(expand); } }
/** try to resolve all given string representation of types to a list of java types */ public static <T> List<Class<? extends T>> forNames(final Iterable<String> classes, ClassLoader... classLoaders) { List<Class<? extends T>> result = new ArrayList<Class<? extends T>>(); for (String className : classes) { Class<?> type = forName(className, classLoaders); if (type != null) { result.add((Class<? extends T>) type); } } return result; }
/** try to resolve all given string representation of types to a list of java types */ public static <T> List<Class<? extends T>> forNames(final Iterable<String> classes, ClassLoader... classLoaders) { List<Class<? extends T>> result = new ArrayList<Class<? extends T>>(); for (String className : classes) { Class<?> type = forName(className, classLoaders); if (type != null) { result.add((Class<? extends T>) type); } } return result; }
public static Field getFieldFromString(String field, ClassLoader... classLoaders) { String className = field.substring(0, field.lastIndexOf('.')); String fieldName = field.substring(field.lastIndexOf('.') + 1); try { return forName(className, classLoaders).getDeclaredField(fieldName); } catch (NoSuchFieldException e) { throw new ReflectionsException("Can't resolve field named " + fieldName, e); } }
@Override public void scan(Object cls) { String className = getMetadataAdapter().getClassName(cls); Class<?> aClass = ReflectionUtils.forName(className, getConfiguration().getClassLoaders()); if (acceptResult(klass.getName()) && klass.isAssignableFrom(aClass) && aClass != klass) { getStore().put(klass.getName(), className); } } }