добавлены методы поиска полей по аннотации
This commit is contained in:
@@ -2,11 +2,14 @@ package ru.dmitriymx.reflection;
|
||||
|
||||
import lombok.ToString;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ToString
|
||||
public class ReflectionObject {
|
||||
@@ -45,6 +48,15 @@ public class ReflectionObject {
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReflectionField> fieldsWithAnnotation(final Class<? extends Annotation> annotationType) {
|
||||
final Class clazz = object.getClass();
|
||||
|
||||
return Stream.of(clazz.getDeclaredFields())
|
||||
.filter(field -> field.isAnnotationPresent(annotationType))
|
||||
.map(field -> new ReflectionField(object, field))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ReflectionField field(String name) {
|
||||
final Class clazz = object.getClass();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user