Search in sources :

Example 1 with InjectedFieldModel

use of org.qi4j.runtime.injection.InjectedFieldModel in project qi4j-sdk by Qi4j.

the class MixinsModel method bind.

// Binding
@Override
public void bind(final Resolution resolution) throws BindingException {
    // Order mixins based on @This usages
    UsageGraph<MixinModel> deps = new UsageGraph<MixinModel>(mixinModels, new Uses(), true);
    mixinModels = deps.resolveOrder();
    // Populate mappings
    for (int i = 0; i < mixinModels.size(); i++) {
        MixinModel mixinModel = mixinModels.get(i);
        mixinIndex.put(mixinModel.mixinClass(), i);
    }
    for (Map.Entry<Method, MixinModel> methodClassEntry : methodImplementation.entrySet()) {
        methodIndex.put(methodClassEntry.getKey(), mixinIndex.get(methodClassEntry.getValue().mixinClass()));
    }
    for (MixinModel mixinModel : mixinModels) {
        mixinModel.accept(new HierarchicalVisitorAdapter<Object, Object, BindingException>() {

            @Override
            public boolean visitEnter(Object visited) throws BindingException {
                if (visited instanceof InjectedFieldModel) {
                    InjectedFieldModel fieldModel = (InjectedFieldModel) visited;
                    fieldModel.bind(resolution.forField(fieldModel.field()));
                    return false;
                } else if (visited instanceof Binder) {
                    Binder constructorsModel = (Binder) visited;
                    constructorsModel.bind(resolution);
                    return false;
                }
                return true;
            }

            @Override
            public boolean visit(Object visited) throws BindingException {
                if (visited instanceof Binder) {
                    ((Binder) visited).bind(resolution);
                }
                return true;
            }
        });
    }
}
Also used : Method(java.lang.reflect.Method) InjectedFieldModel(org.qi4j.runtime.injection.InjectedFieldModel) BindingException(org.qi4j.bootstrap.BindingException) Binder(org.qi4j.runtime.model.Binder) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BindingException (org.qi4j.bootstrap.BindingException)1 InjectedFieldModel (org.qi4j.runtime.injection.InjectedFieldModel)1 Binder (org.qi4j.runtime.model.Binder)1