org.elasticsearch.common.inject.internal
Class Errors

java.lang.Object
  extended by org.elasticsearch.common.inject.internal.Errors
All Implemented Interfaces:
Serializable

public final class Errors
extends Object
implements Serializable

A collection of error messages. If this type is passed as a method parameter, the method is considered to have executed succesfully only if new errors were not added to this collection.

Errors can be chained to provide additional context. To add context, call withSource(java.lang.Object) to create a new Errors instance that contains additional context. All messages added to the returned instance will contain full context.

To avoid messages with redundant context, withSource(java.lang.Object) should be added sparingly. A good rule of thumb is to assume a ethod's caller has already specified enough context to identify that method. When calling a method that's defined in a different context, call that method with an errors object that includes its context.

Author:
jessewilson@google.com (Jesse Wilson)
See Also:
Serialized Form

Constructor Summary
Errors()
           
Errors(Object source)
           
 
Method Summary
 Errors addMessage(Message message)
           
 Errors addMessage(String messageFormat, Object... arguments)
           
 Errors ambiguousTypeConversion(String stringValue, Object source, TypeLiteral<?> type, MatcherAndConverter a, MatcherAndConverter b)
           
 Errors bindingAlreadySet(Key<?> key, Object source)
           
 Errors bindingToProvider()
           
 Errors cannotBindToGuiceType(String simpleName)
           
 Errors cannotInjectInnerClass(Class<?> type)
           
 Errors cannotInjectRawMembersInjector()
           
 Errors cannotInjectRawProvider()
           
 Errors cannotInjectRawTypeLiteral()
           
 Errors cannotInjectTypeLiteralOf(Type unsupportedType)
           
 Errors cannotSatisfyCircularDependency(Class<?> expectedType)
           
<T> T
checkForNull(T value, Object source, Dependency<?> dependency)
          Returns value if it is non-null allowed to be null.
 Errors childBindingAlreadySet(Key<?> key)
           
 Errors conversionError(String stringValue, Object source, TypeLiteral<?> type, MatcherAndConverter matchingConverter, RuntimeException cause)
           
 Errors conversionTypeError(String stringValue, Object source, TypeLiteral<?> type, MatcherAndConverter matchingConverter, Object converted)
           
static Object convert(Object o)
           
 Errors converterReturnedNull(String stringValue, Object source, TypeLiteral<?> type, MatcherAndConverter matchingConverter)
           
 Errors duplicateBindingAnnotations(Member member, Class<? extends Annotation> a, Class<? extends Annotation> b)
           
 Errors duplicateScopeAnnotations(Class<? extends Annotation> a, Class<? extends Annotation> b)
           
 Errors duplicateScopes(Scope existing, Class<? extends Annotation> annotationType, Scope scope)
           
 Errors errorInjectingConstructor(Throwable cause)
           
 Errors errorInjectingMethod(Throwable cause)
           
 Errors errorInProvider(RuntimeException runtimeException)
           
 Errors errorInUserCode(Throwable cause, String messageFormat, Object... arguments)
           
 Errors errorInUserInjector(MembersInjector<?> listener, TypeLiteral<?> type, RuntimeException cause)
           
 Errors errorNotifyingInjectionListener(InjectionListener<?> listener, TypeLiteral<?> type, RuntimeException cause)
           
 Errors errorNotifyingTypeListener(TypeListenerBinding listener, TypeLiteral<?> type, Throwable cause)
           
 void exposedButNotBound(Key<?> key)
           
static String format(String heading, Collection<Message> errorMessages)
          Returns the formatted message for an exception with the specified messages.
static String format(String messageFormat, Object... arguments)
           
static void formatInjectionPoint(Formatter formatter, Dependency<?> dependency, InjectionPoint injectionPoint)
           
static void formatSource(Formatter formatter, Object source)
           
 List<Message> getMessages()
           
static Collection<Message> getMessagesFromThrowable(Throwable throwable)
           
static Throwable getOnlyCause(Collection<Message> messages)
          Returns the cause throwable if there is exactly one cause in messages.
 List<Object> getSources()
           
 boolean hasErrors()
           
 Errors merge(Collection<Message> messages)
           
 Errors merge(Errors moreErrors)
           
 Errors misplacedBindingAnnotation(Member member, Annotation bindingAnnotation)
           
 Errors missingConstantValues()
           
 Errors missingConstructor(Class<?> implementation)
           
 Errors missingImplementation(Key key)
          We use a fairly generic error message here.
 Errors missingRuntimeRetention(Object source)
           
 Errors missingScopeAnnotation()
           
 Errors notASubtype(Class<?> implementationType, Class<?> type)
           
 Errors optionalConstructor(Constructor constructor)
           
 Errors recursiveBinding()
           
 Errors recursiveImplementationType()
           
 Errors recursiveProviderType()
           
 Errors scopeAnnotationOnAbstractType(Class<? extends Annotation> scopeAnnotation, Class<?> type, Object source)
           
 Errors scopeNotFound(Class<? extends Annotation> scopeAnnotation)
           
 int size()
           
 Errors subtypeNotProvided(Class<? extends Provider<?>> providerType, Class<?> type)
           
 void throwConfigurationExceptionIfErrorsExist()
           
 void throwCreationExceptionIfErrorsExist()
           
 void throwIfNewErrors(int expectedSize)
           
 void throwProvisionExceptionIfErrorsExist()
           
 ErrorsException toException()
           
 Errors tooManyConstructors(Class<?> implementation)
           
 Errors voidProviderMethod()
           
 Errors withSource(Object source)
          Returns an instance that uses source as a reference point for newly added errors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Errors

public Errors()

Errors

public Errors(Object source)
Method Detail

withSource

public Errors withSource(Object source)
Returns an instance that uses source as a reference point for newly added errors.


missingImplementation

public Errors missingImplementation(Key key)
We use a fairly generic error message here. The motivation is to share the same message for both bind time errors:
Guice.createInjector(new AbstractModule() {
   public void configure() {
     bind(Runnable.class);
   }
 }
...and at provide-time errors:
Guice.createInjector().getInstance(Runnable.class);
Otherwise we need to know who's calling when resolving a just-in-time binding, which makes things unnecessarily complex.


converterReturnedNull

public Errors converterReturnedNull(String stringValue,
                                    Object source,
                                    TypeLiteral<?> type,
                                    MatcherAndConverter matchingConverter)

conversionTypeError

public Errors conversionTypeError(String stringValue,
                                  Object source,
                                  TypeLiteral<?> type,
                                  MatcherAndConverter matchingConverter,
                                  Object converted)

conversionError

public Errors conversionError(String stringValue,
                              Object source,
                              TypeLiteral<?> type,
                              MatcherAndConverter matchingConverter,
                              RuntimeException cause)

ambiguousTypeConversion

public Errors ambiguousTypeConversion(String stringValue,
                                      Object source,
                                      TypeLiteral<?> type,
                                      MatcherAndConverter a,
                                      MatcherAndConverter b)

bindingToProvider

public Errors bindingToProvider()

subtypeNotProvided

public Errors subtypeNotProvided(Class<? extends Provider<?>> providerType,
                                 Class<?> type)

notASubtype

public Errors notASubtype(Class<?> implementationType,
                          Class<?> type)

recursiveImplementationType

public Errors recursiveImplementationType()

recursiveProviderType

public Errors recursiveProviderType()

missingRuntimeRetention

public Errors missingRuntimeRetention(Object source)

missingScopeAnnotation

public Errors missingScopeAnnotation()

optionalConstructor

public Errors optionalConstructor(Constructor constructor)

cannotBindToGuiceType

public Errors cannotBindToGuiceType(String simpleName)

scopeNotFound

public Errors scopeNotFound(Class<? extends Annotation> scopeAnnotation)

scopeAnnotationOnAbstractType

public Errors scopeAnnotationOnAbstractType(Class<? extends Annotation> scopeAnnotation,
                                            Class<?> type,
                                            Object source)

misplacedBindingAnnotation

public Errors misplacedBindingAnnotation(Member member,
                                         Annotation bindingAnnotation)

missingConstructor

public Errors missingConstructor(Class<?> implementation)

tooManyConstructors

public Errors tooManyConstructors(Class<?> implementation)

duplicateScopes

public Errors duplicateScopes(Scope existing,
                              Class<? extends Annotation> annotationType,
                              Scope scope)

voidProviderMethod

public Errors voidProviderMethod()

missingConstantValues

public Errors missingConstantValues()

cannotInjectInnerClass

public Errors cannotInjectInnerClass(Class<?> type)

duplicateBindingAnnotations

public Errors duplicateBindingAnnotations(Member member,
                                          Class<? extends Annotation> a,
                                          Class<? extends Annotation> b)

duplicateScopeAnnotations

public Errors duplicateScopeAnnotations(Class<? extends Annotation> a,
                                        Class<? extends Annotation> b)

recursiveBinding

public Errors recursiveBinding()

bindingAlreadySet

public Errors bindingAlreadySet(Key<?> key,
                                Object source)

childBindingAlreadySet

public Errors childBindingAlreadySet(Key<?> key)

errorInjectingMethod

public Errors errorInjectingMethod(Throwable cause)

errorNotifyingTypeListener

public Errors errorNotifyingTypeListener(TypeListenerBinding listener,
                                         TypeLiteral<?> type,
                                         Throwable cause)

errorInjectingConstructor

public Errors errorInjectingConstructor(Throwable cause)

errorInProvider

public Errors errorInProvider(RuntimeException runtimeException)

errorInUserInjector

public Errors errorInUserInjector(MembersInjector<?> listener,
                                  TypeLiteral<?> type,
                                  RuntimeException cause)

errorNotifyingInjectionListener

public Errors errorNotifyingInjectionListener(InjectionListener<?> listener,
                                              TypeLiteral<?> type,
                                              RuntimeException cause)

exposedButNotBound

public void exposedButNotBound(Key<?> key)

getMessagesFromThrowable

public static Collection<Message> getMessagesFromThrowable(Throwable throwable)

errorInUserCode

public Errors errorInUserCode(Throwable cause,
                              String messageFormat,
                              Object... arguments)

cannotInjectRawProvider

public Errors cannotInjectRawProvider()

cannotInjectRawMembersInjector

public Errors cannotInjectRawMembersInjector()

cannotInjectTypeLiteralOf

public Errors cannotInjectTypeLiteralOf(Type unsupportedType)

cannotInjectRawTypeLiteral

public Errors cannotInjectRawTypeLiteral()

cannotSatisfyCircularDependency

public Errors cannotSatisfyCircularDependency(Class<?> expectedType)

throwCreationExceptionIfErrorsExist

public void throwCreationExceptionIfErrorsExist()

throwConfigurationExceptionIfErrorsExist

public void throwConfigurationExceptionIfErrorsExist()

throwProvisionExceptionIfErrorsExist

public void throwProvisionExceptionIfErrorsExist()

merge

public Errors merge(Collection<Message> messages)

merge

public Errors merge(Errors moreErrors)

getSources

public List<Object> getSources()

throwIfNewErrors

public void throwIfNewErrors(int expectedSize)
                      throws ErrorsException
Throws:
ErrorsException

toException

public ErrorsException toException()

hasErrors

public boolean hasErrors()

addMessage

public Errors addMessage(String messageFormat,
                         Object... arguments)

addMessage

public Errors addMessage(Message message)

format

public static String format(String messageFormat,
                            Object... arguments)

getMessages

public List<Message> getMessages()

format

public static String format(String heading,
                            Collection<Message> errorMessages)
Returns the formatted message for an exception with the specified messages.


checkForNull

public <T> T checkForNull(T value,
                          Object source,
                          Dependency<?> dependency)
               throws ErrorsException
Returns value if it is non-null allowed to be null. Otherwise a message is added and an ErrorsException is thrown.

Throws:
ErrorsException

getOnlyCause

public static Throwable getOnlyCause(Collection<Message> messages)
Returns the cause throwable if there is exactly one cause in messages. If there are zero or multiple messages with causes, null is returned.


size

public int size()

convert

public static Object convert(Object o)

formatSource

public static void formatSource(Formatter formatter,
                                Object source)

formatInjectionPoint

public static void formatInjectionPoint(Formatter formatter,
                                        Dependency<?> dependency,
                                        InjectionPoint injectionPoint)


Copyright © 2009-2012. All Rights Reserved.