0

добавлены методы поиска полей по аннотации

This commit is contained in:
2020-04-17 18:29:46 +03:00
parent a16fed9785
commit 62b93916f9
5 changed files with 45 additions and 0 deletions

View File

@@ -86,6 +86,20 @@ public class ReflectionObjectTest {
ReflectionMethod refSetter = refField.setter();
assertNotNull(refSetter);
}
@Test
public void fieldsWithAnnotation() {
ReflectionObject refObj = new ReflectionObject(new SomeObject());
List<ReflectionField> list = refObj.fieldsWithAnnotation(SomeAnnotation.class);
assertEquals(1, list.size());
ReflectionField refField = list.get(0);
assertEquals("someIntField", refField.name());
SomeAnnotation annotation = refField.annotation(SomeAnnotation.class);
assertNotNull(annotation);
}
//endregion
//region Method tests

View File

@@ -0,0 +1,12 @@
package ru.dmitriymx.reflection;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SomeAnnotation {
}

View File

@@ -5,6 +5,8 @@ class SomeObject {
private static final int MAGIC_NUMBER = 33;
private final String finalizedField = "value123";
private String simpleField = "defaultValue";
@SomeAnnotation
private int someIntField;
public String getSimpleField() {