Java @author Annotation Count for Developers

I have a code base where developers use @author annotations in their class definitions. Is there a way that I can programmatically calculate how many classes each developer created using these annotations?

+3
source share
1 answer

Assuming you are using annotation

@Author("fred")
public class MyClass {...

Then here is the method that will do this

public List<Class> getClassesWrittenBy(String name, List<Class> classList) {
   List<Class> list = new LinkedList<Class>();
   for (Class clazz: classList)
      if (clazz.isAnnotationPresent(Author.class)) {
          Author author = clazz.getAnnotation(Author.class);
          if (author.value().equals(name))
             list.add(clazz);
      }
   return (list);
}
+4
source

Source: https://habr.com/ru/post/1742059/