I have a code base where developers use @author annotations on their class definitions. 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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.