java - getFieldsAnnotatedWith annotation containing -
annotation
@target(elementtype.field) @retention(retentionpolicy.runtime) public @interface searchable { searchtype[] types() default { searchtype.all }; }
reflections in method
reflections reflections = new reflections(packagename); reflections.getfieldsannotatedwith(); // here's problem
i return fields annotated searchable
containing @ least searchtype.all
. have tried defining new searchable() { ... }
pass method. though result in fields exact match. e.g. containing searchtype.all
. way:
new searchable() { @override public searchtype[] types() { return { searchtype.all }; } @override public class<? extends annotation> annotationtype() { return searchable.class; } }
i fields @searchable(types = { searchtype.all, searchtype.text })
hit too, since contains searchtype.all
. how can accomplish this?
i don't know reflections api, can fields annotated searchable annotation, , check if searchable annotation's types contains searchtype.all:
set<field> fields = reflections.getfieldsannotatedwith(searchable.class); set<field> wanted = new hashset<field>(); (field field : fields) { searchable annotation = field.getannotation(searchable.class); if (arrays.aslist(annotation.types).contains(searchtype.all)) { wanted.add(field); } }
Comments
Post a Comment