简体   繁体   English

为每个开发人员计算Java @author注释

[英]Counting Java @author annotations per developer

I have a code base where developers use @author annotations on their class definitions. 我有一个代码库,开发人员在其类定义中使用@author注释。 Is there a way for me to be able to programmatically 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM