Search in sources :

Example 1 with SideEffects

use of org.qi4j.api.sideeffect.SideEffects in project qi4j-sdk by Qi4j.

the class CompositeAssemblyImpl method sideEffectDeclarations.

protected Iterable<Class<?>> sideEffectDeclarations(ArrayList<Type> allTypes) {
    // Find all side-effects and flattern them into an iterable
    Function<Type, Iterable<Class<?>>> function = new Function<Type, Iterable<Class<?>>>() {

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

Example 2 with SideEffects

use of org.qi4j.api.sideeffect.SideEffects in project qi4j-sdk by Qi4j.

the class CompositeAssemblyImpl method sideEffectDeclarations.

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

        @Override
        public Iterable<Class<?>> map(Type type) {
            SideEffects sideEffects = Annotations.annotationOn(type, SideEffects.class);
            if (sideEffects == null) {
                return Iterables.empty();
            } else {
                return iterable(sideEffects.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) ArrayList(java.util.ArrayList) SideEffects(org.qi4j.api.sideeffect.SideEffects)

Example 3 with SideEffects

use of org.qi4j.api.sideeffect.SideEffects 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)

Aggregations

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