Search in sources :

Example 1 with QueryFunction

use of org.reflections.util.QueryFunction in project reflections by ronmamo.

the class ReflectionUtilsQueryTest method mergedAnnotations.

@Test
public void mergedAnnotations() {
    Class<CombinedTestModel.Request> metaAnnotation = CombinedTestModel.Request.class;
    Reflections reflections = new Reflections(metaAnnotation, Scanners.values());
    Set<Class<?>> metaAnnotations = reflections.get(TypesAnnotated.getAllIncluding(metaAnnotation.getName()).asClass());
    QueryFunction<Store, CombinedTestModel.Request> mergedAnnotations = MethodsAnnotated.with(metaAnnotations).as(Method.class).map(method -> get(Annotations.of(method.getDeclaringClass()).add(Annotations.of(method)).filter(a -> metaAnnotations.contains(a.annotationType()))).stream().collect(new AnnotationMergeCollector(method))).map(map -> ReflectionUtils.toAnnotation(map, metaAnnotation));
    assertThat(reflections.get(mergedAnnotations.map(CombinedTestModel.Request::value)), equalTo("/base/post", "/base/get"));
    assertThat(reflections.get(mergedAnnotations.map(CombinedTestModel.Request::method)), equalTo("Post", "Get"));
}
Also used : AnnotationMergeCollector(org.reflections.util.AnnotationMergeCollector) TestModel(org.reflections.TestModel) Inherited(java.lang.annotation.Inherited) Set(java.util.Set) Scanners(org.reflections.scanners.Scanners) Target(java.lang.annotation.Target) Collectors(java.util.stream.Collectors) MethodsAnnotated(org.reflections.scanners.Scanners.MethodsAnnotated) Retention(java.lang.annotation.Retention) Test(org.junit.jupiter.api.Test) QueryFunction(org.reflections.util.QueryFunction) ReflectionsQueryTest.equalTo(org.reflections.ReflectionsQueryTest.equalTo) TypesAnnotated(org.reflections.scanners.Scanners.TypesAnnotated) Map(java.util.Map) Annotation(java.lang.annotation.Annotation) Documented(java.lang.annotation.Documented) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ReflectionUtils(org.reflections.ReflectionUtils) Method(java.lang.reflect.Method) LinkedHashSet(java.util.LinkedHashSet) AnnotationMergeCollector(org.reflections.util.AnnotationMergeCollector) Test(org.junit.jupiter.api.Test)

Aggregations

Annotation (java.lang.annotation.Annotation)1 Documented (java.lang.annotation.Documented)1 Inherited (java.lang.annotation.Inherited)1 Retention (java.lang.annotation.Retention)1 Target (java.lang.annotation.Target)1 Method (java.lang.reflect.Method)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Test (org.junit.jupiter.api.Test)1 ReflectionUtils (org.reflections.ReflectionUtils)1 ReflectionsQueryTest.equalTo (org.reflections.ReflectionsQueryTest.equalTo)1 TestModel (org.reflections.TestModel)1 Scanners (org.reflections.scanners.Scanners)1 MethodsAnnotated (org.reflections.scanners.Scanners.MethodsAnnotated)1 TypesAnnotated (org.reflections.scanners.Scanners.TypesAnnotated)1 AnnotationMergeCollector (org.reflections.util.AnnotationMergeCollector)1