public final class Errors
extends java.lang.Object
implements java.io.Serializable
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.
Modifier and Type | Class and Description |
---|---|
private static class |
Errors.Converter<T> |
(package private) static class |
Errors.ThrowableEquivalence |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
CONSTRUCTOR_RULES |
private static java.util.Collection<Errors.Converter<?>> |
converters |
private java.util.List<Message> |
errors
null unless (root == this) and error messages exist.
|
private static java.util.logging.Logger |
logger |
private Errors |
parent
The parent errors object.
|
private Errors |
root
The root errors object.
|
private java.lang.Object |
source
The leaf source for errors added here.
|
private static java.util.Set<Dependency<?>> |
warnedDependencies |
Modifier | Constructor and Description |
---|---|
|
Errors() |
private |
Errors(Errors parent,
java.lang.Object source) |
|
Errors(java.lang.Object source) |
Modifier and Type | Method and Description |
---|---|
Errors |
addMessage(Message message) |
Errors |
addMessage(java.lang.String messageFormat,
java.lang.Object... arguments) |
private Errors |
addMessage(java.lang.Throwable cause,
java.lang.String messageFormat,
java.lang.Object... arguments) |
Errors |
ambiguousTypeConversion(java.lang.String stringValue,
java.lang.Object source,
TypeLiteral<?> type,
TypeConverterBinding a,
TypeConverterBinding b) |
private static java.lang.Object |
appendModules(java.lang.Object source,
ElementSource elementSource) |
Errors |
atInjectRequired(java.lang.Class clazz) |
Errors |
bindingAlreadySet(Key<?> key,
java.lang.Object source) |
Errors |
bindingToProvider() |
Errors |
cannotBindToGuiceType(java.lang.String simpleName) |
Errors |
cannotInjectAbstractMethod(java.lang.reflect.Method method) |
Errors |
cannotInjectFinalField(java.lang.reflect.Field field) |
Errors |
cannotInjectInnerClass(java.lang.Class<?> type) |
Errors |
cannotInjectMethodWithTypeParameters(java.lang.reflect.Method method) |
Errors |
cannotInjectNonVoidMethod(java.lang.reflect.Method method) |
Errors |
cannotInjectRawMembersInjector() |
Errors |
cannotInjectRawProvider() |
Errors |
cannotInjectRawTypeLiteral() |
Errors |
cannotInjectTypeLiteralOf(java.lang.reflect.Type unsupportedType) |
Errors |
cannotProxyClass(java.lang.Class<?> expectedType) |
<T> T |
checkForNull(T value,
java.lang.Object source,
Dependency<?> dependency)
Returns
value if it is non-null or allowed to be null. |
Errors |
childBindingAlreadySet(Key<?> key,
java.util.Set<java.lang.Object> sources) |
Errors |
circularDependenciesDisabled(java.lang.Class<?> expectedType) |
Errors |
constructorNotDefinedByType(java.lang.reflect.Constructor<?> constructor,
TypeLiteral<?> type) |
Errors |
conversionError(java.lang.String stringValue,
java.lang.Object source,
TypeLiteral<?> type,
TypeConverterBinding typeConverterBinding,
java.lang.RuntimeException cause) |
Errors |
conversionTypeError(java.lang.String stringValue,
java.lang.Object source,
TypeLiteral<?> type,
TypeConverterBinding typeConverterBinding,
java.lang.Object converted) |
static java.lang.Object |
convert(java.lang.Object o) |
static java.lang.Object |
convert(java.lang.Object o,
ElementSource source) |
Errors |
converterReturnedNull(java.lang.String stringValue,
java.lang.Object source,
TypeLiteral<?> type,
TypeConverterBinding typeConverterBinding) |
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) |
Errors |
duplicateScopeAnnotations(java.lang.Class<? extends java.lang.annotation.Annotation> a,
java.lang.Class<? extends java.lang.annotation.Annotation> b) |
Errors |
duplicateScopes(ScopeBinding existing,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
Scope scope) |
Errors |
errorCheckingDuplicateBinding(Key<?> key,
java.lang.Object source,
java.lang.Throwable t) |
Errors |
errorEnhancingClass(java.lang.Class<?> clazz,
java.lang.Throwable cause) |
Errors |
errorInjectingConstructor(java.lang.Throwable cause) |
Errors |
errorInjectingMethod(java.lang.Throwable cause) |
Errors |
errorInProvider(java.lang.Throwable cause) |
Errors |
errorInUserCode(java.lang.Throwable cause,
java.lang.String messageFormat,
java.lang.Object... arguments) |
Errors |
errorInUserInjector(MembersInjector<?> listener,
TypeLiteral<?> type,
java.lang.RuntimeException cause) |
Errors |
errorNotifyingInjectionListener(InjectionListener<?> listener,
TypeLiteral<?> type,
java.lang.RuntimeException cause) |
Errors |
errorNotifyingTypeListener(TypeListenerBinding listener,
TypeLiteral<?> type,
java.lang.Throwable cause) |
Errors |
exposedButNotBound(Key<?> key) |
static java.lang.String |
format(java.lang.String heading,
java.util.Collection<Message> errorMessages)
Returns the formatted message for an exception with the specified messages.
|
static java.lang.String |
format(java.lang.String messageFormat,
java.lang.Object... arguments) |
static void |
formatInjectionPoint(java.util.Formatter formatter,
Dependency<?> dependency,
InjectionPoint injectionPoint,
ElementSource elementSource) |
private static java.lang.String |
formatParameter(Dependency<?> dependency) |
static void |
formatSource(java.util.Formatter formatter,
java.lang.Object source) |
static void |
formatSource(java.util.Formatter formatter,
java.lang.Object source,
ElementSource elementSource) |
java.util.List<Message> |
getMessages() |
static java.util.Collection<Message> |
getMessagesFromThrowable(java.lang.Throwable throwable) |
static java.lang.Throwable |
getOnlyCause(java.util.Collection<Message> messages)
Returns the cause throwable if there is exactly one cause in
messages . |
private static java.lang.String |
getOrdinalSuffix(int ordinal)
Maps
1 to the string "1st" ditto for all non-negative numbers |
java.util.List<java.lang.Object> |
getSources() |
boolean |
hasErrors() |
Errors |
jitBindingAlreadySet(Key<?> key) |
Errors |
jitDisabled(Key key) |
Errors |
jitDisabledInParent(Key<?> key) |
Errors |
keyNotFullySpecified(TypeLiteral<?> typeLiteral) |
Errors |
merge(java.util.Collection<Message> messages) |
Errors |
merge(Errors moreErrors) |
private Message |
merge(Message message) |
Errors |
misplacedBindingAnnotation(java.lang.reflect.Member member,
java.lang.annotation.Annotation bindingAnnotation) |
Errors |
missingConstantValues() |
Errors |
missingConstructor(java.lang.Class<?> implementation) |
Errors |
missingImplementation(Key key)
We use a fairly generic error message here.
|
Errors |
missingRuntimeRetention(java.lang.Class<? extends java.lang.annotation.Annotation> annotation) |
Errors |
missingScopeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation) |
private static java.lang.String |
moduleSourceString(ElementSource elementSource) |
Errors |
notASubtype(java.lang.Class<?> implementationType,
java.lang.Class<?> type) |
Errors |
optionalConstructor(java.lang.reflect.Constructor constructor) |
Errors |
recursiveBinding() |
Errors |
recursiveImplementationType() |
Errors |
recursiveProviderType() |
Errors |
scopeAnnotationOnAbstractType(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation,
java.lang.Class<?> type,
java.lang.Object source) |
Errors |
scopeNotFound(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation) |
int |
size() |
Errors |
staticInjectionOnInterface(java.lang.Class<?> clazz) |
Errors |
subtypeNotProvided(java.lang.Class<? extends javax.inject.Provider<?>> providerType,
java.lang.Class<?> type) |
void |
throwConfigurationExceptionIfErrorsExist() |
void |
throwCreationExceptionIfErrorsExist() |
void |
throwIfNewErrors(int expectedSize) |
void |
throwProvisionExceptionIfErrorsExist() |
ErrorsException |
toException() |
Errors |
tooManyConstructors(java.lang.Class<?> implementation) |
private java.lang.Throwable |
unwrap(java.lang.Throwable runtimeException) |
Errors |
voidProviderMethod() |
Errors |
withSource(java.lang.Object source)
Returns an instance that uses
source as a reference point for newly added errors. |
private static final java.util.logging.Logger logger
private static final java.util.Set<Dependency<?>> warnedDependencies
private final Errors root
private final Errors parent
private final java.lang.Object source
private java.util.List<Message> errors
private static final java.lang.String CONSTRUCTOR_RULES
private static final java.util.Collection<Errors.Converter<?>> converters
public Errors()
public Errors(java.lang.Object source)
private Errors(Errors parent, java.lang.Object source)
public Errors withSource(java.lang.Object source)
source
as a reference point for newly added errors.public Errors missingImplementation(Key key)
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.public Errors atInjectRequired(java.lang.Class clazz)
public Errors converterReturnedNull(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding)
public Errors conversionTypeError(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, java.lang.Object converted)
public Errors conversionError(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, java.lang.RuntimeException cause)
public Errors ambiguousTypeConversion(java.lang.String stringValue, java.lang.Object source, TypeLiteral<?> type, TypeConverterBinding a, TypeConverterBinding b)
public Errors bindingToProvider()
public Errors subtypeNotProvided(java.lang.Class<? extends javax.inject.Provider<?>> providerType, java.lang.Class<?> type)
public Errors notASubtype(java.lang.Class<?> implementationType, java.lang.Class<?> type)
public Errors recursiveImplementationType()
public Errors recursiveProviderType()
public Errors missingRuntimeRetention(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
public Errors missingScopeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
public Errors optionalConstructor(java.lang.reflect.Constructor constructor)
public Errors cannotBindToGuiceType(java.lang.String simpleName)
public Errors scopeNotFound(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation)
public Errors scopeAnnotationOnAbstractType(java.lang.Class<? extends java.lang.annotation.Annotation> scopeAnnotation, java.lang.Class<?> type, java.lang.Object source)
public Errors misplacedBindingAnnotation(java.lang.reflect.Member member, java.lang.annotation.Annotation bindingAnnotation)
public Errors missingConstructor(java.lang.Class<?> implementation)
public Errors tooManyConstructors(java.lang.Class<?> implementation)
public Errors constructorNotDefinedByType(java.lang.reflect.Constructor<?> constructor, TypeLiteral<?> type)
public Errors duplicateScopes(ScopeBinding existing, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, Scope scope)
public Errors voidProviderMethod()
public Errors missingConstantValues()
public Errors cannotInjectInnerClass(java.lang.Class<?> type)
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)
public Errors staticInjectionOnInterface(java.lang.Class<?> clazz)
public Errors cannotInjectFinalField(java.lang.reflect.Field field)
public Errors cannotInjectAbstractMethod(java.lang.reflect.Method method)
public Errors cannotInjectNonVoidMethod(java.lang.reflect.Method method)
public Errors cannotInjectMethodWithTypeParameters(java.lang.reflect.Method method)
public Errors duplicateScopeAnnotations(java.lang.Class<? extends java.lang.annotation.Annotation> a, java.lang.Class<? extends java.lang.annotation.Annotation> b)
public Errors recursiveBinding()
public Errors childBindingAlreadySet(Key<?> key, java.util.Set<java.lang.Object> sources)
public Errors errorCheckingDuplicateBinding(Key<?> key, java.lang.Object source, java.lang.Throwable t)
public Errors errorInjectingMethod(java.lang.Throwable cause)
public Errors errorNotifyingTypeListener(TypeListenerBinding listener, TypeLiteral<?> type, java.lang.Throwable cause)
public Errors errorInjectingConstructor(java.lang.Throwable cause)
public Errors errorInProvider(java.lang.Throwable cause)
public Errors errorInUserInjector(MembersInjector<?> listener, TypeLiteral<?> type, java.lang.RuntimeException cause)
public Errors errorNotifyingInjectionListener(InjectionListener<?> listener, TypeLiteral<?> type, java.lang.RuntimeException cause)
public Errors keyNotFullySpecified(TypeLiteral<?> typeLiteral)
public Errors errorEnhancingClass(java.lang.Class<?> clazz, java.lang.Throwable cause)
public static java.util.Collection<Message> getMessagesFromThrowable(java.lang.Throwable throwable)
public Errors errorInUserCode(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... arguments)
private java.lang.Throwable unwrap(java.lang.Throwable runtimeException)
public Errors cannotInjectRawProvider()
public Errors cannotInjectRawMembersInjector()
public Errors cannotInjectTypeLiteralOf(java.lang.reflect.Type unsupportedType)
public Errors cannotInjectRawTypeLiteral()
public Errors cannotProxyClass(java.lang.Class<?> expectedType)
public Errors circularDependenciesDisabled(java.lang.Class<?> expectedType)
public void throwCreationExceptionIfErrorsExist()
public void throwConfigurationExceptionIfErrorsExist()
public void throwProvisionExceptionIfErrorsExist()
public java.util.List<java.lang.Object> getSources()
public void throwIfNewErrors(int expectedSize) throws ErrorsException
ErrorsException
public ErrorsException toException()
public boolean hasErrors()
public Errors addMessage(java.lang.String messageFormat, java.lang.Object... arguments)
private Errors addMessage(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... arguments)
public static java.lang.String format(java.lang.String messageFormat, java.lang.Object... arguments)
public java.util.List<Message> getMessages()
public static java.lang.String format(java.lang.String heading, java.util.Collection<Message> errorMessages)
public <T> T checkForNull(T value, java.lang.Object source, Dependency<?> dependency) throws ErrorsException
value
if it is non-null or allowed to be null. Otherwise a message is added and
an ErrorsException
is thrown.ErrorsException
public static java.lang.Throwable getOnlyCause(java.util.Collection<Message> messages)
messages
. If there are
zero or multiple messages with causes, null is returned.public int size()
public static java.lang.Object convert(java.lang.Object o)
public static java.lang.Object convert(java.lang.Object o, ElementSource source)
private static java.lang.Object appendModules(java.lang.Object source, ElementSource elementSource)
private static java.lang.String moduleSourceString(ElementSource elementSource)
public static void formatSource(java.util.Formatter formatter, java.lang.Object source)
public static void formatSource(java.util.Formatter formatter, java.lang.Object source, ElementSource elementSource)
public static void formatInjectionPoint(java.util.Formatter formatter, Dependency<?> dependency, InjectionPoint injectionPoint, ElementSource elementSource)
private static java.lang.String formatParameter(Dependency<?> dependency)
private static java.lang.String getOrdinalSuffix(int ordinal)
1
to the string "1st"
ditto for all non-negative numbers