final AnnotationFinder scanner = new AnnotationFinder(archive); final List<Class<?>> list = scanner.findAnnotatedClasses(anno); final Set<Class<?>> result = new HashSet<Class<?>>(); for (Class<?> clazz : list) {
public List<Annotated<Class<?>>> findMetaAnnotatedClasses(Class<? extends Annotation> annotation) { classesNotLoaded.clear(); Set<Class<?>> classes = findMetaAnnotatedClasses(annotation, new HashSet<Class<?>>()); List<Annotated<Class<?>>> list = new LinkedList<Annotated<Class<?>>>(); for (Class<?> clazz : classes) { if (Annotation.class.isAssignableFrom(clazz) && isMetaAnnotation((Class<? extends Annotation>) clazz)) continue; list.add(new MetaAnnotatedClass(clazz)); } return list; }
/** * Creates a list of the specified class and all its parent * classes then creates a AnnotationFinder from that list which * can be used for easy annotation scanning. * * @param classes * @return */ private AnnotationFinder createFinder(final Class<?>... classes) { final Set<Class<?>> parents = new HashSet<Class<?>>(); for (final Class<?> clazz : classes) { parents.addAll(Classes.ancestors(clazz)); } return new AnnotationFinder(new ClassesArchive(parents)).enableMetaAnnotations(); // no need to have subclasses/impl here }
/** * The link() method must be called to successfully use the findSubclasses and findImplementations methods * * @return * @throws java.io.IOException */ public AnnotationFinder link() { enableFindSubclasses(); enableFindImplementations(); enableMetaAnnotations(); return this; }
public XbeanScanningLoader(final Archive archive) { final AnnotationFinder finder = new AnnotationFinder(archive); for (final Method method : finder.findAnnotatedMethods(Command.class)) { classes.add(method.getDeclaringClass()); } }
public AnnotationFinder select(Iterable<String> clazz) { return new AnnotationFinder(this, clazz); }
final AnnotationFinder finder = new AnnotationFinder( new FilteredArchive( jar.isDirectory() ? new FileArchive(scanningLoader, jar) : new JarArchive(scanningLoader, jar.toURI().toURL()), Filters.packages("com.tomitribe.tribestream.container"))) .link(); module.setFinder(finder);
public void load() { final AnnotationFinder finder = new AnnotationFinder(new CompositeArchive(thisArchive(), cpArchive())).enableFindSubclasses(); for (final Annotated<Class<?>> clazz : finder.findMetaAnnotatedClasses(Editor.class)) { PropertyEditorManager.registerEditor(clazz.getAnnotation(Editor.class).value(), clazz.get()); } } }
log.debug(e.getMessage(), e); finder = new AnnotationFinder(new FilteredArchive(archive, filter)); } finally { if (AutoCloseable.class.isInstance(archive)) { finder.findAnnotatedClasses(Internationalized.class).forEach(proxy -> { final Object instance = javaProxyEnricherFactory .asSerializable(container.getLoader(), container.getId(), proxy.getName(), }); finder .findAnnotatedMethods(Request.class) .stream() .map(Method::getDeclaringClass) }); final Map<Class<?>, Object> userServices = finder .findAnnotatedClasses(Service.class) .stream() .filter(s -> !services.keySet().contains(s)) Stream .of(PartitionMapper.class, Processor.class, Emitter.class) .flatMap(a -> finder.findAnnotatedClasses(a).stream()) .filter(t -> Modifier.isPublic(t.getModifiers())) .forEach(type -> {
@Override protected void doExecute() { final AnnotationFinder finder = new AnnotationFinder(new CompositeArchive(Stream .of(classes) .map(c -> new FileArchive(Thread.currentThread().getContextClassLoader(), c)) .toArray(Archive[]::new))); final List<Class<?>> icons = finder.findAnnotatedClasses(Icon.class); final List<Package> packages = finder.findAnnotatedPackages(Icon.class); if (!icons.isEmpty()) { final List<IconModel> foundIcons = Stream .concat(icons.stream(), packages.stream()) .map(type -> type.getAnnotation(Icon.class)) .map(icon -> { final boolean isCustom = icon.value() == CUSTOM; final String name = isCustom ? icon.custom() : icon.value().getKey(); return new IconModel(project.getArtifactId(), name, findIcon(name), isCustom); }) .collect(toList()); final GlobalReporter reporter = getReporter(); synchronized (reporter) { reporter.icons.addAll(foundIcons); } } }
private static void generatedJUnitEnvironment(final File generatedDir) throws MalformedURLException { final File file = new File(generatedDir, "generated_junit-environments.adoc"); try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) { stream.println(); stream.println("NOTE: the configuration is read from system properties, environment variables, ...."); stream.println(); final File api = jarLocation(BaseEnvironmentProvider.class); final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final AnnotationFinder finder = new AnnotationFinder( api.isDirectory() ? new FileArchive(loader, api) : new JarArchive(loader, api.toURI().toURL())); finder .link() .findSubclasses(BaseEnvironmentProvider.class) .stream() .filter(c -> !Modifier.isAbstract(c.getModifiers())) .sorted(Comparator.comparing(Class::getName)) .forEach(type -> { final BaseEnvironmentProvider environment; try { environment = BaseEnvironmentProvider.class.cast(type.getConstructor().newInstance()); } catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new IllegalStateException(e); } stream.println(environment.getName() + ":: " + "__class: " + type.getSimpleName() + "_. "); }); stream.println(); } }
private <A extends Annotation> void checkAttributes(final AnnotationHandler<A> handler, final String ejbName, final EjbModule ejbModule, final AnnotationFinder annotationFinder, final String messageKey) { final Map<String, List<MethodAttribute>> existingDeclarations = handler.getExistingDeclarations(); int xml = 0; for (final List<MethodAttribute> methodAttributes : existingDeclarations.values()) { xml += methodAttributes.size(); } if (xml > 0) { ejbModule.getValidation().warn(ejbName, "xml." + messageKey, xml); } int ann = annotationFinder.findAnnotatedClasses(handler.getAnnotationClass()).size(); ann += annotationFinder.findAnnotatedMethods(handler.getAnnotationClass()).size(); if (ann > 0) { ejbModule.getValidation().warn(ejbName, "ann." + messageKey, ann); } }
private void processAsynchronous(final EnterpriseBean bean, final AnnotationFinder annotationFinder) { if (!(bean instanceof SessionBean)) { return; } final SessionBean sessionBean = (SessionBean) bean; for (final Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(Asynchronous.class)) { sessionBean.getAsyncMethod().add(new AsyncMethod(method.get())); } //Spec 4.5.1 @Asynchronous could be used at the class level of a bean-class ( or superclass ). //Seems that it should not be used on the any interface view for (final Annotated<Class<?>> clazz : annotationFinder.findMetaAnnotatedClasses(Asynchronous.class)) { if (!clazz.get().isInterface()) { sessionBean.getAsynchronousClasses().add(clazz.get().getName()); } } }
names[i++] = ancestor.getName(); annotationFinder = af.select(names); } else { // shouldn't occur if (!dynamicBean) { } else { if (finder == null) { finder = annotationFinder.select(clazz.getName()); final List<Annotated<Class<?>>> annotatedClasses = sortClasses(annotationFinder.findMetaAnnotatedClasses(Interceptors.class)); for (final Annotated<Class<?>> interceptorsAnnotatedClass : annotatedClasses) { final Interceptors interceptors = interceptorsAnnotatedClass.getAnnotation(Interceptors.class); final List<Annotated<Method>> annotatedMethods = sortMethods(annotationFinder.findMetaAnnotatedMethods(Interceptors.class)); for (final Annotated<Method> method : annotatedMethods) { final Interceptors interceptors = method.getAnnotation(Interceptors.class); for (final Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(ExcludeDefaultInterceptors.class)) { final InterceptorBinding binding = assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(bean)); binding.setExcludeDefaultInterceptors(true); for (final Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(ExcludeClassInterceptors.class))) { final InterceptorBinding binding = assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(bean)); binding.setExcludeClassInterceptors(true); if (annotationFinder.isAnnotationPresent(Path.class)) { sessionBean.setRestService(true);
.findAnnotatedFields(Option.class) .stream() .map(Field::getType) finder.findAnnotatedFields(Option.class).stream().distinct().filter(field -> { final ResourceBundle bundle = ofNullable(findResourceBundle(field.getDeclaringClass())) .orElseGet(() -> findResourceBundle(field.getType())); for (final Class<?> i : finder.findAnnotatedClasses(Internationalized.class)) { final ResourceBundle resourceBundle = findResourceBundle(i); if (resourceBundle != null) { errors.addAll(getActionsStream().flatMap(action -> finder.findAnnotatedMethods(action).stream()).map(action -> { final Annotation actionAnnotation = Stream .of(action.getAnnotations())
@Override public List<Class<?>> findAnnotatedClasses(final Class<? extends Annotation> annotation) { return classCache.computeIfAbsent(annotation, a -> super.findAnnotatedClasses(annotation)); } };
private Set<Class<?>> findMetaAnnotatedClasses(Class<? extends Annotation> annotation, Set<Class<?>> classes) { List<Info> infos = getAnnotationInfos(annotation.getName()); for (Info info : infos) { if (info instanceof ClassInfo) { ClassInfo classInfo = (ClassInfo) info; try { Class clazz = classInfo.get(); if (classes.contains(clazz)) continue; // double check via proper reflection if (clazz.isAnnotationPresent(annotation)) { classes.add(clazz); } String meta = info.getMetaAnnotationName(); if (meta != null) { classes.addAll(findMetaAnnotatedClasses((Class<? extends Annotation>) clazz, classes)); } } catch (ClassNotFoundException e) { classesNotLoaded.add(classInfo.getName()); } } } return classes; }
public List<Annotated<Method>> findMetaAnnotatedMethods(Class<? extends Annotation> annotation) { classesNotLoaded.clear(); Set<Method> methods = findMetaAnnotatedMethods(annotation, new HashSet<Method>(), new HashSet<String>()); List<Annotated<Method>> targets = new ArrayList<Annotated<Method>>(); for (Method method : methods) { targets.add(new MetaAnnotatedMethod(method)); } return targets; }
private Set<Method> findMetaAnnotatedMethods(Class<? extends Annotation> annotation, Set<Method> methods, Set<String> seen) { List<Info> infos = getAnnotationInfos(annotation.getName()); findMetaAnnotatedMethods((Class<? extends Annotation>) clazz, methods, seen);
public <T> List<Class<? extends T>> findSubclasses(Class<T> clazz) { if (clazz == null) throw new NullPointerException("class cannot be null"); classesNotLoaded.clear(); final ClassInfo classInfo = classInfos.get(clazz.getName()); List<Class<? extends T>> found = new LinkedList<Class<? extends T>>(); if (classInfo == null) return found; findSubclasses(classInfo, found, clazz); return found; }