Given a class, return its {@link Provider}.

@param <T> the class of T
14107
@SuppressWarnings("unchecked")
    @Nullable
    public <T> Provider<T> get(Class<T> type) {
        return (Provider<T>) providers.get(type.getName());
    }
207354
public static <E> E get(Class<E> type) {
    ServiceLoader<E> loader = ServiceLoader.load(type);
    Iterator<E> iterator = loader.iterator();
    if (iterator.hasNext()) {
      return iterator.next(); // only one is expected
    }
    try {
      //loads the default implementation
      return (E) Class.forName(getDefaultImplementationName(type)).newInstance();
    } catch (Exception e) {
      throw new TruggerException(e);
    }
  }
577925
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();
  }
1215474
@Nullable
    public <T> Provider<T> getScopedFactory(Class scope, Class<T> classDefinition) {
        //noinspection unchecked
        return factories.getScope(scope).get(classDefinition);
    }
182635
public static <T> List<T> findServiceProviders( Class<T> klass )
    {
        ServiceLoader<T> loader = ServiceLoader.load( klass );
        List<T> providers = new ArrayList<T>();
        Iterator<T> it = loader.iterator();
        while ( it.hasNext() )
        {
            providers.add( it.next() );
        }
        return providers;
    }
410008
public static <T> Class<T> loadClass(String className, ClassLoader classloader) {
        if(className == null) {
            throw new IllegalArgumentException("className cannot be null");
        }

        if(classloader == null) {
            throw new IllegalArgumentException("classloader cannot be null");
        }

        try {
            return (Class<T>) Class.forName(className, false, classloader);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
955135
@SuppressWarnings("unchecked")
    public static <T> T getService(Class<T> type) {
        Bundle serviceBundle = FrameworkUtil.getBundle(type);
        BundleContext serviceBundleContext = serviceBundle.getBundleContext();
        ServiceReference serviceReference = serviceBundleContext.getServiceReference(type.getName());
        return (T) serviceBundleContext.getService(serviceReference);
    }
1187873
public static Class<?> typeToClass(Type t) {
		if (t instanceof Class) {
			return (Class<?>)t;
		}
		else if (t instanceof ParameterizedType) {
			return ((Class<?>) ((ParameterizedType) t).getRawType());
		}
		throw new IllegalArgumentException("Cannot convert type to class");
	}
1311195
public <T extends InvocationMarshaller<?>> T registerProvider (
        InvocationProvider provider, Class<T> mclass)
    {
        return registerProvider(provider, mclass, null);
    }
452392
@Override
  public <T> T get(String name, Class<T> type) {
    return this.properties.get(name, type);
  }
231493
public static <U> LifecycleProvider<U> of(@Nonnull final Class<? extends Provider<U>> providerClass)
    {
        return new DelegatingLifecycleProvider<U>(providerClass, null);
    }
1270343
private <T> Set<Class<? extends T>> load(Class<T> serviceClass) {
        String serviceFile = SERVICES + "/" + serviceClass.getName();

        LinkedHashSet<Class<? extends T>> providers = new LinkedHashSet<Class<? extends T>>();

        try {
            Enumeration<URL> enumeration = classLoader.getResources(serviceFile);
            while (enumeration.hasMoreElements()) {
                final URL url = enumeration.nextElement();
                final InputStream is = url.openStream();
                BufferedReader reader = null;

                try {
                    reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                    String line = reader.readLine();
                    while (null != line) {
                        line = skipCommentAndTrim(line);

                        if (line.length() > 0) {
                            try {
                                Class<? extends T> provider = classLoader.loadClass(line).asSubclass(serviceClass);
                                providers.add(provider);
                            } catch (ClassCastException e) {
                                ClassLoader other = serviceClass.getClassLoader();
                                if (!classLoader.getClass().equals(serviceClass.getClassLoader())) {
                                    throw new IllegalStateException("Service " + line
                                        + " was loaded by different classloader (" + (other == null ? "bootstrap"
                                            : other.getClass().getName()) + ") then service interface "
                                        + serviceClass.getName() + " (" + classLoader.getClass().getName()
                                        + "), unable to cast classes");
                                }
                                throw new IllegalStateException("Service " + line + " does not implement expected type "
                                    + serviceClass.getName());
                            }
                        }
                        line = reader.readLine();
                    }
                } finally {
                    if (reader != null) {
                        reader.close();
                    }
                }
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not load services for " + serviceClass.getName(), e);
        }
        return providers;
    }
1008055
static Type forTypeProvider(final TypeProvider provider) {
        LettuceAssert.notNull(provider, "Provider must not be null");
        if (provider.getType() instanceof Serializable || provider.getType() == null) {
            return provider.getType();
        }

        for (Class<?> type : SUPPORTED_SERIALIZABLE_TYPES) {
            if (type.isAssignableFrom(provider.getType().getClass())) {
                ClassLoader classLoader = provider.getClass().getClassLoader();
                Class<?>[] interfaces = new Class<?>[] { type, SerializableTypeProxy.class, Serializable.class };
                InvocationHandler handler = new TypeProxyInvocationHandler(provider);
                return (Type) Proxy.newProxyInstance(classLoader, interfaces, handler);
            }
        }
        throw new IllegalArgumentException("Unsupported Type class: " + provider.getType().getClass().getName());
    }
824081
protected @Nonnull <T> Provider<T> getBeanProvider(@Nullable BeanResolutionContext resolutionContext, @Nonnull Class<T> beanType) {
        return getBeanProvider(resolutionContext, beanType, null);
    }
733271
@Override
  public <T> T instance(InjectionPoint<T> ip)
  {
    Objects.requireNonNull(ip);

    Provider<T> provider = provider(ip);

    if (provider != null) {
      return provider.get();
    }
    else {
      return null;
    }
  }
624768
public static Class<?> getRawClass(Type t) {
		if (isClassType(t)) {
			return typeToClass(t);
		} else if (t instanceof GenericArrayType) {
			Type component = ((GenericArrayType) t).getGenericComponentType();
			return Array.newInstance(getRawClass(component), 0).getClass();
		}
		return Object.class;
	}
441786
public <T> T getService (Class<T> sclass)
    {
        if (_bstrap == null) {
            return null;
        }
        int scount = _bstrap.services.size();
        for (int ii = 0; ii < scount; ii++) {
            InvocationService<?> service = _bstrap.services.get(ii);
            if (sclass.isInstance(service)) {
                return sclass.cast(service);
            }
        }
        return null;
    }