Package com.google.inject.internal
Class Errors
java.lang.Object
com.google.inject.internal.Errors
- All Implemented Interfaces:
Serializable
A 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.google.common.collect.ImmutableSet<Class<?>>
If the key is unknown and it is one of these types, it generally means there is a missing annotation.private static final String
null unless (root == this) and error messages exist.private static final int
When a binding is not found, show at most this many bindings with the same typeprivate static final int
When a binding is not found, show at most this many bindings that have some similaritiesprivate final Errors
The parent errors object.private final Errors
The root errors object.private final Object
The leaf source for errors added here. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddMessage
(Message message) addMessage
(String messageFormat, Object... arguments) private Errors
addMessage
(Throwable cause, String messageFormat, Object... arguments) ambiguousTypeConversion
(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding a, TypeConverterBinding b) atInjectRequired
(Class clazz) bindingAlreadySet
(Key<?> key, Object source) cannotBindToGuiceType
(String simpleName) cannotInjectAbstractMethod
(Method method) cannotInjectFinalField
(Field field) cannotInjectInnerClass
(Class<?> type) cannotInjectNonVoidMethod
(Method method) cannotInjectTypeLiteralOf
(Type unsupportedType) (package private) static void
checkConfiguration
(boolean condition, String format, Object... args) Throws a ConfigurationException with a formattedMessage
if this condition isfalse
.(package private) static <T> T
checkNotNull
(T reference, String name) Throws a ConfigurationException with an NullPointerExceptions as the cause if the given reference isnull
.childBindingAlreadySet
(Key<?> key, Set<Object> sources) constructorNotDefinedByType
(Constructor<?> constructor, TypeLiteral<?> type) conversionError
(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, RuntimeException cause) conversionTypeError
(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, Object converted) static Object
static Object
convert
(Object o, ElementSource source) converterReturnedNull
(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding) duplicateBindingAnnotations
(Member member, Class<? extends Annotation> a, Class<? extends Annotation> b) duplicateScopeAnnotations
(Class<? extends Annotation> a, Class<? extends Annotation> b) duplicateScopes
(ScopeBinding existing, Class<? extends Annotation> annotationType, Scope scope) errorCheckingDuplicateBinding
(Key<?> key, Object source, Throwable t) errorEnhancingClass
(Class<?> clazz, Throwable cause) errorInUserCode
(Throwable cause, String messageFormat, Object... arguments) errorNotifyingTypeListener
(TypeListenerBinding listener, TypeLiteral<?> type, Throwable cause) exposedButNotBound
(Key<?> key) static String
static void
formatSource
(Formatter formatter, Object source) static Collection<Message>
getMessagesFromThrowable
(Throwable throwable) boolean
jitBindingAlreadySet
(Key<?> key) jitDisabled
(Key<?> key) jitDisabledInParent
(Key<?> key) keyNotFullySpecified
(TypeLiteral<?> typeLiteral) merge
(Collection<Message> messages) misplacedBindingAnnotation
(Member member, Annotation bindingAnnotation) missingConstructor
(TypeLiteral<?> type) missingImplementation
(Key key) We use a fairly generic error message here.(package private) <T> Errors
missingImplementationWithHint
(Key<T> key, Injector injector) Within guice's core, allow for better missing binding messagesmissingRuntimeRetention
(Class<? extends Annotation> annotation) missingScopeAnnotation
(Class<? extends Annotation> annotation) notASubtype
(Class<?> implementationType, Class<?> type) optionalConstructor
(Constructor constructor) scopeAnnotationOnAbstractType
(Class<? extends Annotation> scopeAnnotation, Class<?> type, Object source) scopeNotFound
(Class<? extends Annotation> scopeAnnotation) int
size()
staticInjectionOnInterface
(Class<?> clazz) void
void
void
throwIfNewErrors
(int expectedSize) void
tooManyConstructors
(Class<?> implementation) withSource
(Object source) Returns an instance that usessource
as a reference point for newly added errors.
-
Field Details
-
MAX_MATCHING_TYPES_REPORTED
private static final int MAX_MATCHING_TYPES_REPORTEDWhen a binding is not found, show at most this many bindings with the same type- See Also:
-
MAX_RELATED_TYPES_REPORTED
private static final int MAX_RELATED_TYPES_REPORTEDWhen a binding is not found, show at most this many bindings that have some similarities- See Also:
-
COMMON_AMBIGUOUS_TYPES
If the key is unknown and it is one of these types, it generally means there is a missing annotation. -
root
The root errors object. Used to access the list of error messages. -
parent
The parent errors object. Used to obtain the chain of source objects. -
source
The leaf source for errors added here. -
errors
null unless (root == this) and error messages exist. Never an empty list. -
CONSTRUCTOR_RULES
- See Also:
-
-
Constructor Details
-
Errors
public Errors() -
Errors
-
Errors
-
-
Method Details
-
checkNotNull
Throws a ConfigurationException with an NullPointerExceptions as the cause if the given reference isnull
. -
checkConfiguration
Throws a ConfigurationException with a formattedMessage
if this condition isfalse
. -
withSource
Returns an instance that usessource
as a reference point for newly added errors. -
missingImplementation
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
Within guice's core, allow for better missing binding messages -
jitDisabled
-
jitDisabledInParent
-
atInjectRequired
-
converterReturnedNull
public Errors converterReturnedNull(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding) -
conversionTypeError
public Errors conversionTypeError(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, Object converted) -
conversionError
public Errors conversionError(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, RuntimeException cause) -
ambiguousTypeConversion
public Errors ambiguousTypeConversion(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding a, TypeConverterBinding b) -
bindingToProvider
-
notASubtype
-
recursiveImplementationType
-
recursiveProviderType
-
missingRuntimeRetention
-
missingScopeAnnotation
-
optionalConstructor
-
cannotBindToGuiceType
-
scopeNotFound
-
scopeAnnotationOnAbstractType
public Errors scopeAnnotationOnAbstractType(Class<? extends Annotation> scopeAnnotation, Class<?> type, Object source) -
misplacedBindingAnnotation
-
missingConstructor
-
tooManyConstructors
-
constructorNotDefinedByType
-
duplicateScopes
public Errors duplicateScopes(ScopeBinding existing, Class<? extends Annotation> annotationType, Scope scope) -
voidProviderMethod
-
missingConstantValues
-
cannotInjectInnerClass
-
duplicateBindingAnnotations
public Errors duplicateBindingAnnotations(Member member, Class<? extends Annotation> a, Class<? extends Annotation> b) -
staticInjectionOnInterface
-
cannotInjectFinalField
-
cannotInjectAbstractMethod
-
cannotInjectNonVoidMethod
-
cannotInjectMethodWithTypeParameters
-
duplicateScopeAnnotations
public Errors duplicateScopeAnnotations(Class<? extends Annotation> a, Class<? extends Annotation> b) -
recursiveBinding
-
bindingAlreadySet
-
jitBindingAlreadySet
-
childBindingAlreadySet
-
errorCheckingDuplicateBinding
-
errorNotifyingTypeListener
public Errors errorNotifyingTypeListener(TypeListenerBinding listener, TypeLiteral<?> type, Throwable cause) -
exposedButNotBound
-
keyNotFullySpecified
-
errorEnhancingClass
-
getMessagesFromThrowable
-
errorInUserCode
-
cannotInjectRawProvider
-
cannotInjectRawMembersInjector
-
cannotInjectTypeLiteralOf
-
cannotInjectRawTypeLiteral
-
throwCreationExceptionIfErrorsExist
public void throwCreationExceptionIfErrorsExist() -
throwConfigurationExceptionIfErrorsExist
public void throwConfigurationExceptionIfErrorsExist() -
throwProvisionExceptionIfErrorsExist
public void throwProvisionExceptionIfErrorsExist() -
merge
-
merge
-
merge
-
getSources
-
throwIfNewErrors
- Throws:
ErrorsException
-
toException
-
hasErrors
public boolean hasErrors() -
addMessage
-
addMessage
-
addMessage
-
format
-
getMessages
-
size
public int size() -
convert
-
convert
-
formatSource
-