Counting Java @author annotations per developer
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);
}
精彩评论