static String createMessage(String value, Key<?> key, Member member, String reason) { String annotationMessage = key.hasAnnotationType() ? " annotated with " + key.getAnnotationName() : ""; return member == null ? "Error converting '" + value + "' to " + key.getRawType().getSimpleName() + " while getting binding value" + annotationMessage + ". Reason: " + reason : "Error converting '" + value + "' to " + key.getRawType().getSimpleName() + " while injecting " + member.getName() + " with binding value" + annotationMessage + " required by " + member.getDeclaringClass().getSimpleName() + ". Reason: " + reason; } }
<T> List<String> getNamesOfBindingAnnotations(TypeLiteral<T> type) { List<String> names = new ArrayList<String>(); for (Binding<T> binding : findBindingsByType(type)) { Key<T> key = binding.getKey(); if (!key.hasAnnotationType()) { names.add("[no annotation]"); } else { names.add(key.getAnnotationName()); } } return names; }
public String toString(Key k) { return k.hasAnnotationType() ? k.getTypeLiteral() + " annotated with " + k.getAnnotationName() : k.getTypeLiteral().toString(); } }
InternalFactory<? extends T> getInternalFactory(InjectorImpl injector) { if (this.factory == null && !key.hasAnnotationType()) { // Try an implicit binding. final ImplicitImplementation<T> implicitImplementation = new ImplicitImplementation<T>(key, scope, source); binder.creationListeners.add(implicitImplementation); // We need to record the scope. If it's singleton, we'll preload in prod. if (this.scope == null) { // We can ignore errors because the error will already have been // recorded. this.scope = Scopes.getScopeForType( key.getTypeLiteral().getRawType(), binder.scopes, IGNORE_ERRORS); } return implicitImplementation; } return Scopes.scope(this.key, injector, this.factory, scope); }
public BindingBuilderImpl<T> annotatedWith(Annotation annotation) { if (this.key.hasAnnotationType()) { binder.addError(source, ErrorMessages.ANNOTATION_ALREADY_SPECIFIED); } else { Class<? extends Annotation> annotationType = annotation.annotationType(); boolean retainedAtRuntime = Annotations.isRetainedAtRuntime(annotationType); boolean bindingAnnotation = Key.isBindingAnnotation(annotationType); if (!retainedAtRuntime) { binder.addError(StackTraceElements.forType(annotationType), ErrorMessages.MISSING_RUNTIME_RETENTION, binder.source()); } if (!bindingAnnotation) { binder.addError(StackTraceElements.forType(annotationType), ErrorMessages.MISSING_BINDING_ANNOTATION, binder.source()); } if (retainedAtRuntime && bindingAnnotation) { this.key = Key.get(this.key.getTypeLiteral(), annotation); } } return this; }
public BindingBuilderImpl<T> annotatedWith( Class<? extends Annotation> annotationType) { if (this.key.hasAnnotationType()) { binder.addError(source, ErrorMessages.ANNOTATION_ALREADY_SPECIFIED); } else { boolean retainedAtRuntime = Annotations.isRetainedAtRuntime(annotationType); boolean bindingAnnotation = Key.isBindingAnnotation(annotationType); if (!retainedAtRuntime) { binder.addError(StackTraceElements.forType(annotationType), ErrorMessages.MISSING_RUNTIME_RETENTION, binder.source()); } if (!bindingAnnotation) { binder.addError(StackTraceElements.forType(annotationType), ErrorMessages.MISSING_BINDING_ANNOTATION, binder.source()); } if (retainedAtRuntime && bindingAnnotation) { this.key = Key.get(this.key.getTypeLiteral(), annotationType); } } return this; }
if (key.hasAnnotationType()) {