/** * Gets all fields of the given class and its parents (if any) that are annotated with the given annotation. * @param cls * the {@link Class} to query * @param annotationCls * the {@link Annotation} that must be present on a field to be matched * @return an array of Fields (possibly empty). * @throws IllegalArgumentException * if the class or annotation are {@code null} * @since 3.4 */ public static Field[] getFieldsWithAnnotation(final Class<?> cls, final Class<? extends Annotation> annotationCls) { final List<Field> annotatedFieldsList = getFieldsListWithAnnotation(cls, annotationCls); return annotatedFieldsList.toArray(new Field[annotatedFieldsList.size()]); }
@Test(expected = IllegalArgumentException.class) public void testGetFieldsListWithAnnotationIllegalArgumentException3() { FieldUtils.getFieldsListWithAnnotation(null, null); }
@Test(expected = IllegalArgumentException.class) public void testGetFieldsListWithAnnotationIllegalArgumentException1() { FieldUtils.getFieldsListWithAnnotation(FieldUtilsTest.class, null); }
@Test(expected = IllegalArgumentException.class) public void testGetFieldsListWithAnnotationIllegalArgumentException2() { FieldUtils.getFieldsListWithAnnotation(null, Annotated.class); }
@Test public void testGetFieldsListWithAnnotation() throws NoSuchFieldException { assertEquals(0, FieldUtils.getFieldsListWithAnnotation(Object.class, Annotated.class).size()); final List<Field> annotatedFields = Arrays.asList( FieldUtilsTest.class.getDeclaredField("publicChild"), FieldUtilsTest.class.getDeclaredField("privatelyShadowedChild") ); final List<Field> fieldUtilsTestAnnotatedFields = FieldUtils.getFieldsListWithAnnotation(FieldUtilsTest.class, Annotated.class); assertEquals(annotatedFields.size(),fieldUtilsTestAnnotatedFields.size()); assertTrue(fieldUtilsTestAnnotatedFields.contains(annotatedFields.get(0))); assertTrue(fieldUtilsTestAnnotatedFields.contains(annotatedFields.get(1))); }
classPropertyFields.put(clazz, new HashSet<AnnotatedFieldProperty>()); List<AnnotatedFieldProperty> names = new ArrayList<>(); List<Field> fields = FieldUtils.getFieldsListWithAnnotation(clazz, annotation); List<Field> allFields = FieldUtils.getAllFieldsList(clazz); for (Field field : fields) {
default List<Field> injectableFields(final Class<?> testClass) { return FieldUtils.getFieldsListWithAnnotation(testClass, InjectTestData.class); }
/** * Gets all fields of the given class and its parents (if any) that are annotated with the given annotation. * @param cls * the {@link Class} to query * @param annotationCls * the {@link Annotation} that must be present on a field to be matched * @return an array of Fields (possibly empty). * @throws IllegalArgumentException * if the class or annotation are {@code null} * @since 3.4 */ public static Field[] getFieldsWithAnnotation(final Class<?> cls, final Class<? extends Annotation> annotationCls) { final List<Field> annotatedFieldsList = getFieldsListWithAnnotation(cls, annotationCls); return annotatedFieldsList.toArray(new Field[annotatedFieldsList.size()]); }
/** * Gets all fields of the given class and its parents (if any) that are annotated with the given annotation. * @param cls * the {@link Class} to query * @param annotationCls * the {@link Annotation} that must be present on a field to be matched * @return an array of Fields (possibly empty). * @throws IllegalArgumentException * if the class or annotation are {@code null} * @since 3.4 */ public static Field[] getFieldsWithAnnotation(final Class<?> cls, final Class<? extends Annotation> annotationCls) { final List<Field> annotatedFieldsList = getFieldsListWithAnnotation(cls, annotationCls); return annotatedFieldsList.toArray(new Field[annotatedFieldsList.size()]); }
/** * Gets all fields of the given class and its parents (if any) that are annotated with the given annotation. * @param cls * the {@link Class} to query * @param annotationCls * the {@link Annotation} that must be present on a field to be matched * @return an array of Fields (possibly empty). * @throws IllegalArgumentException * if the class or annotation are {@code null} * @since 3.4 */ public static Field[] getFieldsWithAnnotation(final Class<?> cls, final Class<? extends Annotation> annotationCls) { final List<Field> annotatedFieldsList = getFieldsListWithAnnotation(cls, annotationCls); return annotatedFieldsList.toArray(new Field[annotatedFieldsList.size()]); }
private Field getPartitionKeyField(Class<?> domainClass) { Field partitionKey = null; final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainClass, PartitionKey.class); if (fields.size() == 1) { partitionKey = fields.get(0); } else if (fields.size() > 1) { throw new IllegalArgumentException("Azure Cosmos DB supports only one partition key, " + "only one field with @PartitionKey annotation!"); } if (partitionKey != null && partitionKey.getType() != String.class) { throw new IllegalArgumentException("type of PartitionKey field must be String"); } return partitionKey; }
private Field getPartitionKeyField(Class<?> domainClass) { Field partitionKey = null; final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainClass, PartitionKey.class); if (fields.size() == 1) { partitionKey = fields.get(0); } else if (fields.size() > 1) { throw new IllegalArgumentException("Azure Cosmos DB supports only one partition key, " + "only one field with @PartitionKey annotation!"); } if (partitionKey != null && partitionKey.getType() != String.class) { throw new IllegalArgumentException("type of PartitionKey field must be String"); } return partitionKey; }
public static void deserializeFormFields(Object target, ValueMap input) throws DeserializeException { List<Field> fields = FieldUtils.getFieldsListWithAnnotation(target.getClass(), FormField.class); deserializeFields(target, fields, input); }
/** * Clear all the {@link TestResource}s of the given instance for the given test. * * @param testInstance the instance of the running test. * @param testMethod the method of the running test. */ public void clear(final Object testInstance, final Method testMethod) { Class<?> testClass = testInstance.getClass(); List<Field> testFields = FieldUtils.getFieldsListWithAnnotation(testClass, TestResource.class); for (Field testField : testFields) { clearResource(testInstance, testMethod, testField); } }
private Field getIdField(Class<?> domainClass) { Field idField = null; final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainClass, Id.class); if (fields.isEmpty()) { idField = ReflectionUtils.findField(getJavaType(), Constants.ID_PROPERTY_NAME); } else if (fields.size() == 1) { idField = fields.get(0); } else { throw new IllegalArgumentException("only one field with @Id annotation!"); } if (idField != null && idField.getType() != String.class) { throw new IllegalArgumentException("type of id field must be String"); } return idField; }
private Field getIdField(Class<?> domainClass) { Field idField = null; final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainClass, Id.class); if (fields.isEmpty()) { idField = ReflectionUtils.findField(getJavaType(), "id"); } else if (fields.size() == 1) { idField = fields.get(0); } else { throw new IllegalArgumentException("only one field with @Id annotation!"); } if (idField != null && idField.getType() != String.class) { throw new IllegalArgumentException("type of id field must be String"); } return idField; }
public static Map<String, FieldComponent> getFormFields(Class source, SlingScriptHelper sling) { return FieldUtils.getFieldsListWithAnnotation(source, FormField.class) .stream() .collect(Collectors.toMap(Field::getName, f -> { FormField fieldDefinition = f.getAnnotation(FormField.class); FieldComponent component; try { component = fieldDefinition.component().newInstance(); component.setup(f.getName(), f, fieldDefinition, sling); return component; } catch (InstantiationException | IllegalAccessException ex) { LOG.error("Unable to instantiate field component for " + f.getName(), ex); } return null; }, (a, b) -> a, LinkedHashMap::new)); }
@NonNull private Field getEdgeAnnotatedField(@NonNull Class<?> domainClass, @NonNull Class<? extends Annotation> annotationClass) { final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainClass, annotationClass); if (fields.size() != 1) { throw new GremlinEntityInformationException("should be only one Annotation"); } return fields.get(0); }
@NonNull private Field getEdgeAnnotatedField(@NonNull Class<?> domainClass, @NonNull Class<? extends Annotation> annotationClass) { final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainClass, annotationClass); if (fields.size() != 1) { throw new GremlinEntityInformationException("should be only one Annotation"); } return fields.get(0); }
@Override public void serializeWidgetFields(AbstractFrame widgetFrame, Widget widget) { widget.getWidgetFields().clear(); List<Field> parameterFields = FieldUtils.getFieldsListWithAnnotation(widgetFrame.getClass(), WidgetParam.class); for (Field parameterField : parameterFields) { Parameter parameter = metadata.create(Parameter.class); parameter.setName(parameterField.getName()); parameter.setAlias(parameterField.getName()); ParameterValue parameterValue = parameterTransformer.createParameterValue(parameterField, widgetFrame); parameter.setParameterValue(parameterValue); widget.getWidgetFields().add(parameter); } }