1 package jfun.yan.nuts.annotations; 2 3 import java.lang.annotation.Annotation ; 4 import java.lang.reflect.Constructor ; 5 import java.lang.reflect.Field ; 6 import java.lang.reflect.Member ; 7 import java.lang.reflect.Method ; 8 9 import jfun.yan.util.MemberPredicate; 10 11 18 public class AnnotationMemberPredicate implements MemberPredicate { 19 private final Class <? extends Annotation > annotation; 20 public boolean isMember(String name, Member m) { 21 if(m instanceof Method ){ 22 return ((Method )m).isAnnotationPresent(annotation); 23 } 24 else if(m instanceof Field ){ 25 return ((Field )m).isAnnotationPresent(annotation); 26 } 27 else if(m instanceof Constructor ){ 28 return ((Constructor )m).isAnnotationPresent(annotation); 29 } 30 return false; 31 } 32 public AnnotationMemberPredicate(Class <? extends Annotation > annotation) { 33 this.annotation = annotation; 34 } 35 public boolean equals(Object obj) { 36 if(obj instanceof AnnotationMemberPredicate){ 37 final AnnotationMemberPredicate other = (AnnotationMemberPredicate)obj; 38 return annotation.equals(other.annotation); 39 } 40 else return false; 41 } 42 public int hashCode() { 43 return annotation.hashCode(); 44 } 45 public String toString() { 46 return annotation.toString(); 47 } 48 49 } 50 | Popular Tags |