Search in sources :

Example 1 with Provider

use of org.opensearch.common.inject.Provider in project OpenSearch by opensearch-project.

the class ProviderMethodsModule method createProviderMethod.

<T> ProviderMethod<T> createProviderMethod(Binder binder, final Method method) {
    binder = binder.withSource(method);
    Errors errors = new Errors(method);
    // prepare the parameter providers
    Set<Dependency<?>> dependencies = new HashSet<>();
    List<Provider<?>> parameterProviders = new ArrayList<>();
    List<TypeLiteral<?>> parameterTypes = typeLiteral.getParameterTypes(method);
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for (int i = 0; i < parameterTypes.size(); i++) {
        Key<?> key = getKey(errors, parameterTypes.get(i), method, parameterAnnotations[i]);
        dependencies.add(Dependency.get(key));
        parameterProviders.add(binder.getProvider(key));
    }
    // Define T as the method's return type.
    @SuppressWarnings("unchecked") TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
    Key<T> key = getKey(errors, returnType, method, method.getAnnotations());
    Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations());
    for (Message message : errors.getMessages()) {
        binder.addError(message);
    }
    return new ProviderMethod<>(key, method, delegate, unmodifiableSet(dependencies), parameterProviders, scopeAnnotation);
}
Also used : Message(org.opensearch.common.inject.spi.Message) ArrayList(java.util.ArrayList) Dependency(org.opensearch.common.inject.spi.Dependency) Provider(org.opensearch.common.inject.Provider) TypeLiteral(org.opensearch.common.inject.TypeLiteral) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Provider (org.opensearch.common.inject.Provider)1 TypeLiteral (org.opensearch.common.inject.TypeLiteral)1 Dependency (org.opensearch.common.inject.spi.Dependency)1 Message (org.opensearch.common.inject.spi.Message)1