Package com.google.inject.internal
Class Errors
- java.lang.Object
-
- com.google.inject.internal.Errors
-
- All Implemented Interfaces:
java.io.Serializable
public final class Errors extends java.lang.Object implements java.io.SerializableA collection of error messages. If this type is passed as a method parameter, the method is considered to have executed successfully 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 method'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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static com.google.common.collect.ImmutableSet<java.lang.Class<?>>COMMON_AMBIGUOUS_TYPESIf the key is unknown and it is one of these types, it generally means there is a missing annotation.private static java.lang.StringCONSTRUCTOR_RULESprivate java.util.List<Message>errorsnull unless (root == this) and error messages exist.private static intMAX_MATCHING_TYPES_REPORTEDWhen a binding is not found, show at most this many bindings with the same typeprivate static intMAX_RELATED_TYPES_REPORTEDWhen a binding is not found, show at most this many bindings that have some similaritiesprivate ErrorsparentThe parent errors object.private ErrorsrootThe root errors object.private java.lang.ObjectsourceThe leaf source for errors added here.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ErrorsaddMessage(Message message)ErrorsaddMessage(java.lang.String messageFormat, java.lang.Object... arguments)private ErrorsaddMessage(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... arguments)ErrorsambiguousTypeConversion(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding a, TypeConverterBinding b)ErrorsatInjectRequired(java.lang.Class clazz)ErrorsbindingAlreadySet(Key<?> key, java.lang.Object source)ErrorsbindingToProvider()ErrorscannotBindToGuiceType(java.lang.String simpleName)ErrorscannotInjectAbstractMethod(java.lang.reflect.Method method)ErrorscannotInjectFinalField(java.lang.reflect.Field field)ErrorscannotInjectInnerClass(java.lang.Class<?> type)ErrorscannotInjectMethodWithTypeParameters(java.lang.reflect.Method method)ErrorscannotInjectNonVoidMethod(java.lang.reflect.Method method)ErrorscannotInjectRawMembersInjector()ErrorscannotInjectRawProvider()ErrorscannotInjectRawTypeLiteral()ErrorscannotInjectTypeLiteralOf(java.lang.reflect.Type unsupportedType)(package private) static voidcheckConfiguration(boolean condition, java.lang.String format, java.lang.Object... args)Throws a ConfigurationException with a formattedMessageif this condition isfalse.(package private) static <T> TcheckNotNull(T reference, java.lang.String name)Throws a ConfigurationException with an NullPointerExceptions as the cause if the given reference isnull.ErrorschildBindingAlreadySet(Key<?> key, java.util.Set<java.lang.Object> sources)ErrorsconstructorNotDefinedByType(java.lang.reflect.Constructor<?> constructor, TypeLiteral<?> type)ErrorsconversionError(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, java.lang.RuntimeException cause)ErrorsconversionTypeError(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, java.lang.Object converted)static java.lang.Objectconvert(java.lang.Object o)static java.lang.Objectconvert(java.lang.Object o, ElementSource source)ErrorsconverterReturnedNull(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding)ErrorsduplicateBindingAnnotations(java.lang.reflect.Member member, java.lang.Class<? extends java.lang.annotation.Annotation> a, java.lang.Class<? extends java.lang.annotation.Annotation> b)ErrorsduplicateScopeAnnotations(java.lang.Class<? extends java.lang.annotation.Annotation> a, java.lang.Class<? extends java.lang.annotation.Annotation> b)ErrorsduplicateScopes(ScopeBinding existing, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, Scope scope)ErrorserrorCheckingDuplicateBinding(Key<?> key, java.lang.Object source, java.lang.Throwable t)ErrorserrorEnhancingClass(java.lang.Class<?> clazz, java.lang.Throwable cause)ErrorserrorInUserCode(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... arguments)ErrorserrorNotifyingTypeListener(TypeListenerBinding listener, TypeLiteral<?> type, java.lang.Throwable cause)ErrorsexposedButNotBound(Key<?> key)static java.lang.Stringformat(java.lang.String messageFormat, java.lang.Object... arguments)static voidformatSource(java.util.Formatter formatter, java.lang.Object source)java.util.List<Message>getMessages()static java.util.Collection<Message>getMessagesFromThrowable(java.lang.Throwable throwable)private java.util.List<java.lang.Object>getSources()booleanhasErrors()ErrorsjitBindingAlreadySet(Key<?> key)ErrorsjitDisabled(Key<?> key)ErrorsjitDisabledInParent(Key<?> key)ErrorskeyNotFullySpecified(TypeLiteral<?> typeLiteral)Errorsmerge(Errors moreErrors)Errorsmerge(InternalProvisionException ipe)Errorsmerge(java.util.Collection<Message> messages)ErrorsmisplacedBindingAnnotation(java.lang.reflect.Member member, java.lang.annotation.Annotation bindingAnnotation)ErrorsmissingConstantValues()ErrorsmissingConstructor(java.lang.Class<?> implementation)ErrorsmissingImplementation(Key key)We use a fairly generic error message here.(package private) <T> ErrorsmissingImplementationWithHint(Key<T> key, Injector injector)Within guice's core, allow for better missing binding messagesErrorsmissingRuntimeRetention(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)ErrorsmissingScopeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)ErrorsnotASubtype(java.lang.Class<?> implementationType, java.lang.Class<?> type)ErrorsoptionalConstructor(java.lang.reflect.Constructor constructor)ErrorsrecursiveBinding()ErrorsrecursiveImplementationType()ErrorsrecursiveProviderType()ErrorsscopeAnnotationOnAbstractType(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation, java.lang.Class<?> type, java.lang.Object source)ErrorsscopeNotFound(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation)intsize()ErrorsstaticInjectionOnInterface(java.lang.Class<?> clazz)voidthrowConfigurationExceptionIfErrorsExist()voidthrowCreationExceptionIfErrorsExist()voidthrowIfNewErrors(int expectedSize)voidthrowProvisionExceptionIfErrorsExist()ErrorsExceptiontoException()ErrorstooManyConstructors(java.lang.Class<?> implementation)ErrorsvoidProviderMethod()ErrorswithSource(java.lang.Object source)Returns an instance that usessourceas a reference point for newly added errors.
-
-
-
Field Detail
-
MAX_MATCHING_TYPES_REPORTED
private static final int MAX_MATCHING_TYPES_REPORTED
When a binding is not found, show at most this many bindings with the same type- See Also:
- Constant Field Values
-
MAX_RELATED_TYPES_REPORTED
private static final int MAX_RELATED_TYPES_REPORTED
When a binding is not found, show at most this many bindings that have some similarities- See Also:
- Constant Field Values
-
COMMON_AMBIGUOUS_TYPES
private static final com.google.common.collect.ImmutableSet<java.lang.Class<?>> COMMON_AMBIGUOUS_TYPES
If the key is unknown and it is one of these types, it generally means there is a missing annotation.
-
root
private final Errors root
The root errors object. Used to access the list of error messages.
-
parent
private final Errors parent
The parent errors object. Used to obtain the chain of source objects.
-
source
private final java.lang.Object source
The leaf source for errors added here.
-
errors
private java.util.List<Message> errors
null unless (root == this) and error messages exist. Never an empty list.
-
CONSTRUCTOR_RULES
private static final java.lang.String CONSTRUCTOR_RULES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Errors
public Errors()
-
Errors
public Errors(java.lang.Object source)
-
Errors
private Errors(Errors parent, java.lang.Object source)
-
-
Method Detail
-
checkNotNull
static <T> T checkNotNull(T reference, java.lang.String name)Throws a ConfigurationException with an NullPointerExceptions as the cause if the given reference isnull.
-
checkConfiguration
static void checkConfiguration(boolean condition, java.lang.String format, java.lang.Object... args)Throws a ConfigurationException with a formattedMessageif this condition isfalse.
-
withSource
public Errors withSource(java.lang.Object source)
Returns an instance that usessourceas 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:
...and at provide-time errors:Guice.createInjector(new AbstractModule() { public void configure() { bind(Runnable.class); } }
Otherwise we need to know who's calling when resolving a just-in-time binding, which makes things unnecessarily complex.Guice.createInjector().getInstance(Runnable.class);
-
missingImplementationWithHint
<T> Errors missingImplementationWithHint(Key<T> key, Injector injector)
Within guice's core, allow for better missing binding messages
-
atInjectRequired
public Errors atInjectRequired(java.lang.Class clazz)
-
converterReturnedNull
public Errors converterReturnedNull(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding)
-
conversionTypeError
public Errors conversionTypeError(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, java.lang.Object converted)
-
conversionError
public Errors conversionError(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, java.lang.RuntimeException cause)
-
ambiguousTypeConversion
public Errors ambiguousTypeConversion(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding a, TypeConverterBinding b)
-
bindingToProvider
public Errors bindingToProvider()
-
notASubtype
public Errors notASubtype(java.lang.Class<?> implementationType, java.lang.Class<?> type)
-
recursiveImplementationType
public Errors recursiveImplementationType()
-
recursiveProviderType
public Errors recursiveProviderType()
-
missingRuntimeRetention
public Errors missingRuntimeRetention(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
-
missingScopeAnnotation
public Errors missingScopeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
-
optionalConstructor
public Errors optionalConstructor(java.lang.reflect.Constructor constructor)
-
cannotBindToGuiceType
public Errors cannotBindToGuiceType(java.lang.String simpleName)
-
scopeNotFound
public Errors scopeNotFound(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation)
-
scopeAnnotationOnAbstractType
public Errors scopeAnnotationOnAbstractType(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation, java.lang.Class<?> type, java.lang.Object source)
-
misplacedBindingAnnotation
public Errors misplacedBindingAnnotation(java.lang.reflect.Member member, java.lang.annotation.Annotation bindingAnnotation)
-
missingConstructor
public Errors missingConstructor(java.lang.Class<?> implementation)
-
tooManyConstructors
public Errors tooManyConstructors(java.lang.Class<?> implementation)
-
constructorNotDefinedByType
public Errors constructorNotDefinedByType(java.lang.reflect.Constructor<?> constructor, TypeLiteral<?> type)
-
duplicateScopes
public Errors duplicateScopes(ScopeBinding existing, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, Scope scope)
-
voidProviderMethod
public Errors voidProviderMethod()
-
missingConstantValues
public Errors missingConstantValues()
-
cannotInjectInnerClass
public Errors cannotInjectInnerClass(java.lang.Class<?> type)
-
duplicateBindingAnnotations
public Errors duplicateBindingAnnotations(java.lang.reflect.Member member, java.lang.Class<? extends java.lang.annotation.Annotation> a, java.lang.Class<? extends java.lang.annotation.Annotation> b)
-
staticInjectionOnInterface
public Errors staticInjectionOnInterface(java.lang.Class<?> clazz)
-
cannotInjectFinalField
public Errors cannotInjectFinalField(java.lang.reflect.Field field)
-
cannotInjectAbstractMethod
public Errors cannotInjectAbstractMethod(java.lang.reflect.Method method)
-
cannotInjectNonVoidMethod
public Errors cannotInjectNonVoidMethod(java.lang.reflect.Method method)
-
cannotInjectMethodWithTypeParameters
public Errors cannotInjectMethodWithTypeParameters(java.lang.reflect.Method method)
-
duplicateScopeAnnotations
public Errors duplicateScopeAnnotations(java.lang.Class<? extends java.lang.annotation.Annotation> a, java.lang.Class<? extends java.lang.annotation.Annotation> b)
-
recursiveBinding
public Errors recursiveBinding()
-
childBindingAlreadySet
public Errors childBindingAlreadySet(Key<?> key, java.util.Set<java.lang.Object> sources)
-
errorCheckingDuplicateBinding
public Errors errorCheckingDuplicateBinding(Key<?> key, java.lang.Object source, java.lang.Throwable t)
-
errorNotifyingTypeListener
public Errors errorNotifyingTypeListener(TypeListenerBinding listener, TypeLiteral<?> type, java.lang.Throwable cause)
-
keyNotFullySpecified
public Errors keyNotFullySpecified(TypeLiteral<?> typeLiteral)
-
errorEnhancingClass
public Errors errorEnhancingClass(java.lang.Class<?> clazz, java.lang.Throwable cause)
-
getMessagesFromThrowable
public static java.util.Collection<Message> getMessagesFromThrowable(java.lang.Throwable throwable)
-
errorInUserCode
public Errors errorInUserCode(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... arguments)
-
cannotInjectRawProvider
public Errors cannotInjectRawProvider()
-
cannotInjectRawMembersInjector
public Errors cannotInjectRawMembersInjector()
-
cannotInjectTypeLiteralOf
public Errors cannotInjectTypeLiteralOf(java.lang.reflect.Type unsupportedType)
-
cannotInjectRawTypeLiteral
public Errors cannotInjectRawTypeLiteral()
-
throwCreationExceptionIfErrorsExist
public void throwCreationExceptionIfErrorsExist()
-
throwConfigurationExceptionIfErrorsExist
public void throwConfigurationExceptionIfErrorsExist()
-
throwProvisionExceptionIfErrorsExist
public void throwProvisionExceptionIfErrorsExist()
-
merge
public Errors merge(InternalProvisionException ipe)
-
getSources
private java.util.List<java.lang.Object> getSources()
-
throwIfNewErrors
public void throwIfNewErrors(int expectedSize) throws ErrorsException- Throws:
ErrorsException
-
toException
public ErrorsException toException()
-
hasErrors
public boolean hasErrors()
-
addMessage
public Errors addMessage(java.lang.String messageFormat, java.lang.Object... arguments)
-
addMessage
private Errors addMessage(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... arguments)
-
format
public static java.lang.String format(java.lang.String messageFormat, java.lang.Object... arguments)
-
getMessages
public java.util.List<Message> getMessages()
-
size
public int size()
-
convert
public static java.lang.Object convert(java.lang.Object o)
-
convert
public static java.lang.Object convert(java.lang.Object o, ElementSource source)
-
formatSource
public static void formatSource(java.util.Formatter formatter, java.lang.Object source)
-
-