001package com.teamscale.commons.annotation; 002 003import java.lang.annotation.Annotation; 004import java.util.stream.Collectors; 005 006import org.atteo.classindex.ClassIndex; 007 008import com.google.common.collect.Streams; 009 010/** Wrapper to retrieve annotated classes. */ 011public class ClassIndexUtils { 012 013 /** 014 * Returns all classes annotated with the given annotation. This is workaround 015 * for https://github.com/atteo/classindex/issues/54. 016 */ 017 public static Iterable<Class<?>> getAnnotated(Class<? extends Annotation> annotation) { 018 Iterable<Class<?>> annotated = ClassIndex.getAnnotated(annotation); 019 return Streams.stream(annotated).filter(clazz -> clazz.getAnnotation(annotation) != null) 020 .collect(Collectors.toList()); 021 } 022}