@Override public <T> Provider<T> provider(Injector manager, Key<T> key) { Class<?> rawClass = key.rawClass(); return null; }
private boolean isAssignableFrom(ParameterizedType typeA, ParameterizedType typeB) { Type []paramA = typeA.getActualTypeArguments(); Type []paramB = typeB.getActualTypeArguments(); if (paramA.length != paramB.length) { return false; } for (int i = 0; i < paramA.length; i++) { Class<?> classA = rawClass(paramA[i]); Class<?> classB = rawClass(paramB[i]); if (! classA.equals(classB) && ! classA.equals(Object.class) && ! classB.equals(Object.class)) { return false; } } return true; }
@Override public <T> Provider<T> provider(Injector manager, Key<T> key) { if (! Config.class.equals(key.rawClass())) { return null; } return () -> (T) _config.get(); } }
@Override public void build(InjectorImpl injector) { // XXX: BindingAmp<U> parentBinding = newBinding(injector, _keyParent.rawClass()); introspectMethod(injector, _method, parentBinding); } }
@SuppressWarnings("unchecked") @Override public <T> Provider<T> provider(Injector inject, Key<T> key) { if (! ConvertManager.class.equals(key.rawClass())) { return null; } final T converter = (T) new ConvertManagerInject(inject); return ()->converter; } }
/** * Find a binding by the key. */ private <T> BindingInject<T> findBean(Key<T> key) { for (InjectProvider provider : _providerList) { BindingInject<T> bean = (BindingInject) provider.lookup(key.rawClass()); if (bean != null) { return bean; } } return null; }
/** * Returns all bindings matching a key. */ @Override public <T> List<Binding<T>> bindings(Key<T> key) { BindingSet<T> set = (BindingSet) _bindingSetMap.get(key.rawClass()); if (set != null) { return set.bindings(key); } else { return Collections.EMPTY_LIST; } }
/** * Finds a producer for the given target type. */ private <T> BindingAmp<T> findBinding(Key<T> key) { BindingSet<T> set = (BindingSet) _bindingSetMap.get(key.rawClass()); if (set != null) { BindingAmp<T> binding = set.find(key); if (binding != null) { return binding; } } return null; }
@Override public <T> Provider<T> provider(Injector injector, Key<T> key) { Class<?> type = key.rawClass(); if (ApplicationContext.class.equals(type)) { return null; } ApplicationContext context = context(injector); if (context == null) { return null; } String[] names = context.getBeanNamesForType(type); if (names == null || names.length == 0) { return null; } return ()->(T) context.getBean(type); }
/** * Adds a new injection producer to the discovered producer list. */ <T> void addProvider(BindingAmp<T> binding) { // TypeRef typeRef = TypeRef.of(producer.key().type()); Class<T> type = (Class) binding.key().rawClass(); addBinding(type, binding); }
/** * Adds a new injection producer to the discovered producer list. */ <T> void addFunction(BindingAmp<T> binding) { // TypeRef typeRef = TypeRef.of(producer.key().type()); Class<T> type = (Class) binding.key().rawClass(); addBinding(type, binding); }
@Override public <T> Provider<T> provider(Injector manager, Key<T> key) { Class<T> rawClass = key.rawClass(); Service service = rawClass.getAnnotation(Service.class); if (service == null) { return null; } if (key.isAnnotationPresent(ServiceImpl.class)) { return null; } String address = getManager().address(rawClass); if (address != null && ! address.isEmpty()) { T proxy = getManager().service(address).as(rawClass); return ()->proxy; } else { return null; } }
/** * Creates a new instance for a given key. */ @Override public <T> T instance(Key<T> key) { Objects.requireNonNull(key); Class<T> type = (Class) key.rawClass(); if (type.equals(Provider.class)) { TypeRef typeRef = TypeRef.of(key.type()); TypeRef param = typeRef.param(0); return (T) provider(Key.of(param.type())); } Provider<T> provider = provider(key); if (provider != null) { return provider.get(); } else { return null; } }
@Service public Object service(InjectionPoint ip) Class<?> type = ip.key().rawClass();
@Override public <T> Provider<T> provider(Injector manager, InjectionPoint<T> ip) { Service service = ip.annotation(Service.class); Class<T> rawClass = ip.key().rawClass(); if (service == null) { service = metaService(ip.key()); } if (service == null) { service = rawClass.getAnnotation(Service.class); } if (service == null) { return null; } String address = getManager().address(rawClass, service.value()); if (address != null && ! address.isEmpty()) { T proxy = getManager().service(address).as(rawClass); return ()->proxy; } else { return null; } }
/** * default provider */ private <T> Provider<T> createProvider(Key<T> key) { Class<T> type = (Class<T>) key.rawClass(); if (Provider.class.equals(type)) { TypeRef subType = TypeRef.of(key.type()).to(Provider.class).param(0); Key<Object> subkey = Key.of(subType.type(), key.annotationTypes()); return (Provider) new ProviderProvider(key, -10, provider(subkey)); } else if (Optional.class.equals(type)) { TypeRef subType = TypeRef.of(key.type()).to(Optional.class).param(0); Key<Object> subkey = Key.of(subType.type(), key.annotationTypes()); return (Provider) new ProviderOptional(key, -10, provider(subkey)); } else if (type.isInterface() || Modifier.isAbstract(type.getModifiers())) { return new ProviderNull(key, -10000, new InjectScopeSingleton()); } int priority = -10; // auto-provider is factory InjectScope<T> scope = findScope(type); BindingAmp<T> binding = new ProviderConstructor<>(this, key, priority, scope, type); binding.bind(); return binding.provider(); }