Search in sources :

Example 1 with Mixins

use of org.qi4j.api.mixin.Mixins in project qi4j-sdk by Qi4j.

the class AnnotationsTest method getAnnotationOrNull.

@Test
public void getAnnotationOrNull() throws NoSuchMethodException {
    assertNotNull("Mixins annotation found", Annotations.annotationOn(AnnotatedClass.class, Mixins.class));
    assertNull("No SideEffects annotation found", Annotations.annotationOn(AnnotatedClass.class, SideEffects.class));
    final Type returnType = AnnotatedClass.class.getDeclaredMethod("list").getGenericReturnType();
    assertNull("Null on no class type", Annotations.annotationOn(returnType, Mixins.class));
}
Also used : Type(java.lang.reflect.Type) Mixins(org.qi4j.api.mixin.Mixins) SideEffects(org.qi4j.api.sideeffect.SideEffects) Test(org.junit.Test)

Example 2 with Mixins

use of org.qi4j.api.mixin.Mixins in project qi4j-sdk by Qi4j.

the class CompositeAssemblyImpl method mixinDeclarations.

protected Iterable<Class<?>> mixinDeclarations(Iterable<? extends Class<?>> typess) {
    // Find mixin declarations
    ArrayList<Type> allTypes = new ArrayList<Type>();
    for (Class<?> type : typess) {
        Iterable<Type> types = typesOf(type);
        Iterables.addAll(allTypes, types);
    }
    // Find all mixins and flattern them into an iterable
    Function<Type, Iterable<Class<?>>> function = new Function<Type, Iterable<Class<?>>>() {

        @Override
        public Iterable<Class<?>> map(Type type) {
            Mixins mixins = Annotations.annotationOn(type, Mixins.class);
            if (mixins == null) {
                return Iterables.empty();
            } else {
                return iterable(mixins.value());
            }
        }
    };
    Iterable<Class<?>> flatten = Iterables.flattenIterables(Iterables.map(function, allTypes));
    return Iterables.toList(flatten);
}
Also used : Function(org.qi4j.functional.Function) Type(java.lang.reflect.Type) Mixins(org.qi4j.api.mixin.Mixins) ArrayList(java.util.ArrayList)

Aggregations

Type (java.lang.reflect.Type)2 Mixins (org.qi4j.api.mixin.Mixins)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 SideEffects (org.qi4j.api.sideeffect.SideEffects)1 Function (org.qi4j.functional.Function)1