/** * @param annotationType * the annotation type to look for on this field * @param name the fieldName * @return the annotation if found OR null if none found * @throws FieldnameNotFoundException if this fieldName is invalid */ @SuppressWarnings("hiding") public <T extends Annotation> T getFieldAnnotation(Class<T> annotationType, String name) { if (annotationType == null) { throw new IllegalArgumentException("annotationType must not be null"); } ClassProperty cp = getAnyPropertyOrFail(name); T a = cp.getAnnotation(annotationType); return a; }
/** * @param annotationType * the annotation type to look for on this field * @param name the fieldName * @return the annotation if found OR null if none found * @throws FieldnameNotFoundException if this fieldName is invalid */ @SuppressWarnings("hiding") public <T extends Annotation> T getFieldAnnotation(Class<T> annotationType, String name) { if (annotationType == null) { throw new IllegalArgumentException("annotationType must not be null"); } ClassProperty cp = getAnyPropertyOrFail(name); T a = cp.getAnnotation(annotationType); return a; }
/** * Finds the names of all the fields with the given annotation type * @param annotationType * the annotation type to look for on this field * @return the list of all field names sorted OR empty if none found */ public List<String> getFieldNamesWithAnnotation(Class<? extends Annotation> annotationType) { if (annotationType == null) { throw new IllegalArgumentException("annotationType must not be null"); } HashSet<String> fieldNames = new HashSet<String>(); Collection<ClassProperty> cps = namesToProperties.values(); for (ClassProperty classProperty : cps) { if (classProperty.getAnnotation(annotationType) != null) { fieldNames.add( classProperty.getFieldName() ); } } ArrayList<String> l = new ArrayList<String>(fieldNames); Collections.sort(l); return l; }
/** * Finds the names of all the fields with the given annotation type * @param annotationType * the annotation type to look for on this field * @return the list of all field names sorted OR empty if none found */ public List<String> getFieldNamesWithAnnotation(Class<? extends Annotation> annotationType) { if (annotationType == null) { throw new IllegalArgumentException("annotationType must not be null"); } HashSet<String> fieldNames = new HashSet<String>(); Collection<ClassProperty> cps = namesToProperties.values(); for (ClassProperty classProperty : cps) { if (classProperty.getAnnotation(annotationType) != null) { fieldNames.add( classProperty.getFieldName() ); } } ArrayList<String> l = new ArrayList<String>(fieldNames); Collections.sort(l); return l; }
/** * Will find the first field which has this annotation type * * @param annotationType * the annotation type to look for on this field * @return the name of the field which has this annotation OR null if none found */ public String getFieldNameByAnnotation(Class<? extends Annotation> annotationType) { if (annotationType == null) { throw new IllegalArgumentException("annotationType must not be null"); } String fieldName = null; Collection<ClassProperty> cps = namesToProperties.values(); for (ClassProperty classProperty : cps) { if (classProperty.getAnnotation(annotationType) != null) { fieldName = classProperty.getFieldName(); break; } } return fieldName; }
/** * Will find the first field which has this annotation type * * @param annotationType * the annotation type to look for on this field * @return the name of the field which has this annotation OR null if none found */ public String getFieldNameByAnnotation(Class<? extends Annotation> annotationType) { if (annotationType == null) { throw new IllegalArgumentException("annotationType must not be null"); } String fieldName = null; Collection<ClassProperty> cps = namesToProperties.values(); for (ClassProperty classProperty : cps) { if (classProperty.getAnnotation(annotationType) != null) { fieldName = classProperty.getFieldName(); break; } } return fieldName; }