<T> InternalProviderImpl<T> toProvider(Binding<T> binding) {
if (binding == null) {
throw new IllegalStateException("null binding are not allowed. Should not happen unless getBindingSet is overridden.");
}
Configuration.instance.checkIllegalBinding(binding);
switch (binding.getMode()) {
case SIMPLE:
return createInternalProvider(this, binding.getKey(), false, binding.isScoped());
case CLASS:
return createInternalProvider(this, binding.getImplementationClass(), false, binding.isScoped());
case INSTANCE:
return new InternalProviderImpl<>(binding.getInstance());
case PROVIDER_INSTANCE:
return new InternalProviderImpl<>(binding.getProviderInstance());
case PROVIDER_CLASS:
return createInternalProvider(this, binding.getProviderClass(), true, binding.isScoped());
default:
throw new IllegalStateException(format("mode is not handled: %s. This should not happen.", binding.getMode()));
}
}