开发者

Counting Java @author annotations per developer

开发者 https://www.devze.com 2022-12-28 02:47 出处:网络
I have a code base where developers use @author annotations on their class definitions. Is there a way for me to be able to progr开发者_如何学编程ammatically count how many classes are authored by eac

I have a code base where developers use @author annotations on their class definitions. Is there a way for me to be able to progr开发者_如何学编程ammatically count how many classes are authored by each developer using those annotations?


Assuming this is how you use the annotation

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

Then here is a method that will do it

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号