package org.qi4j.runtime.resolution;

import org.qi4j.api.model.DependencyKey;
import org.qi4j.api.model.InjectionKey;

/**
 * TODO
 */
public class KeyMatcher
{
    public boolean matches( DependencyKey dependency, InjectionKey injectedObject )
    {
        // Match raw types (e.g. Iterable<Foo> matches List<Foo> and Iterable<Foo>)
        if( !dependency.getRawType().isAssignableFrom( injectedObject.getRawType() ) )
        {
            return false;
        }

        // Match dependent types, if set
        if( injectedObject.getDependentType() != null && !dependency.getDependentType().equals( injectedObject.getDependentType() ) )
        {
            return false;
        }

        // Match names, if set
        if( injectedObject.getName() != null )
        {
            // if injection key has a name, the name must match dependency key
            if( dependency.getName() == null || !dependency.getName().equals( injectedObject.getName() ) )
            {
                return false;
            }
        }

        // Match type - injecting subtypes is ok
        if( !dependency.getDependencyType().isAssignableFrom( injectedObject.getDependencyType() ) )
        {
            return false;
        }

        // The keys match!
        return true;
    }
}

@@ -656,37 +656,172 @@
             
-return false;
+if( !dependency.getDependentType().isAssignableFrom( injectedObject.getDependentType() ) )%0A            %7B%0A                return false;%0A            %7D
 %0A        %7D%0A%0A

o Fixed bug. Qi4j was fail to inject value to PropertyField in mixin's super class at runtime.