Search in sources :

Example 1 with Message

use of org.elasticsearch.common.inject.spi.Message in project elasticsearch by elastic.

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.elasticsearch.common.inject.spi.Message) ArrayList(java.util.ArrayList) Dependency(org.elasticsearch.common.inject.spi.Dependency) Provider(org.elasticsearch.common.inject.Provider) TypeLiteral(org.elasticsearch.common.inject.TypeLiteral) HashSet(java.util.HashSet)

Example 2 with Message

use of org.elasticsearch.common.inject.spi.Message in project crate by crate.

the class Errors method addMessage.

private Errors addMessage(Throwable cause, String messageFormat, Object... arguments) {
    String message = format(messageFormat, arguments);
    addMessage(new Message(getSources(), message, cause));
    return this;
}
Also used : Message(org.elasticsearch.common.inject.spi.Message)

Example 3 with Message

use of org.elasticsearch.common.inject.spi.Message in project crate by crate.

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.elasticsearch.common.inject.spi.Message) ArrayList(java.util.ArrayList) Dependency(org.elasticsearch.common.inject.spi.Dependency) Provider(org.elasticsearch.common.inject.Provider) TypeLiteral(org.elasticsearch.common.inject.TypeLiteral) HashSet(java.util.HashSet)

Example 4 with Message

use of org.elasticsearch.common.inject.spi.Message in project crate by crate.

the class RepositoryServiceTest method testConvertException.

@Test
public void testConvertException() throws Throwable {
    expectedException.expect(RepositoryException.class);
    expectedException.expectMessage("[foo] failed: [foo] missing location");
    throw RepositoryService.convertRepositoryException(new RepositoryException("foo", "failed", new CreationException(List.of(new Message(Collections.singletonList(10), "creation error", new RepositoryException("foo", "missing location"))))));
}
Also used : Message(org.elasticsearch.common.inject.spi.Message) RepositoryException(org.elasticsearch.repositories.RepositoryException) CreationException(org.elasticsearch.common.inject.CreationException) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 5 with Message

use of org.elasticsearch.common.inject.spi.Message in project crate by crate.

the class RepositoryServiceTest method testConvertException.

@Test
public void testConvertException() throws Throwable {
    expectedException.expect(RepositoryException.class);
    expectedException.expectMessage("[foo] failed: [foo] missing location");
    throw RepositoryService.convertRepositoryException(new RepositoryException("foo", "failed", new CreationException(ImmutableList.of(new Message(Collections.<Object>singletonList(10), "creation error", new RepositoryException("foo", "missing location"))))));
}
Also used : Message(org.elasticsearch.common.inject.spi.Message) RepositoryException(org.elasticsearch.repositories.RepositoryException) CreationException(org.elasticsearch.common.inject.CreationException) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Message (org.elasticsearch.common.inject.spi.Message)10 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2 HashSet (java.util.HashSet)2 CreationException (org.elasticsearch.common.inject.CreationException)2 Provider (org.elasticsearch.common.inject.Provider)2 TypeLiteral (org.elasticsearch.common.inject.TypeLiteral)2 Dependency (org.elasticsearch.common.inject.spi.Dependency)2 InjectionPoint (org.elasticsearch.common.inject.spi.InjectionPoint)2 RepositoryException (org.elasticsearch.repositories.RepositoryException)2 Test (org.junit.Test)2 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 CrateUnitTest (io.crate.test.integration.CrateUnitTest)1