protected void checkNotTargetted() { if (!(binding instanceof UntargettedBindingImpl)) { binder.addError(IMPLEMENTATION_ALREADY_SET); } }
protected void checkNotAnnotated() { if (key.getAnnotationType() != null) { binder.addError(AbstractBindingBuilder.ANNOTATION_ALREADY_SPECIFIED); } }
private void copyErrorsToBinder(ConfigurationException e) { for (Message message : e.getErrorMessages()) { binder.addError(message); } } }
/** * @see Binder#addError(Message) * @since 2.0 */ protected void addError(Message message) { binder().addError(message); }
/** @see Binder#addError(String, Object[]) */ protected void addError(String message, Object... arguments) { binder().addError(message, arguments); }
/** @see Binder#addError(Throwable) */ protected void addError(Throwable t) { binder().addError(t); }
/** Returns the annotation that is claimed by the scanner, or null if there is none. */ private Annotation getAnnotation(Binder binder, Method method) { if (method.isBridge() || method.isSynthetic()) { return null; } Annotation annotation = null; for (Class<? extends Annotation> annotationClass : scanner.annotationClasses()) { Annotation foundAnnotation = method.getAnnotation(annotationClass); if (foundAnnotation != null) { if (annotation != null) { binder.addError( "More than one annotation claimed by %s on method %s." + " Methods can only have one annotation claimed per scanner.", scanner, method); return null; } annotation = foundAnnotation; } } return annotation; }
/** @since 2.0 */ @Override public void applyTo(Binder binder) { binder.withSource(getSource()).addError(this); }
protected void checkNotAnnotated() { if (binding.getKey().getAnnotationType() != null) { binder.addError(ANNOTATION_ALREADY_SPECIFIED); } }
if (mapKey != null) { if (foundAnnotation != null) { binder.addError("Found more than one MapKey annotations on %s.", method); return AnnotationOrError.forError(); binder.addError( "Array types are not allowed in a MapKey with unwrapValue=true: %s", annotation.annotationType()); binder.addError( "No 'value' method in MapKey with unwrapValue=true: %s", annotation.annotationType());
? "@Provides" : "@" + provider.getAnnotation().annotationType().getCanonicalName(); binder.addError( "Overriding " + annotationString
@Override public Void visit(ScopeBinding scopeBinding) { ScopeBinding overideBinding = overridesScopeAnnotations.remove(scopeBinding.getAnnotationType()); if (overideBinding == null) { super.visit(scopeBinding); } else { List<Object> usedSources = scopeInstancesInUse.get(scopeBinding.getScope()); if (usedSources != null) { StringBuilder sb = new StringBuilder( "The scope for @%s is bound directly and cannot be overridden."); sb.append("%n original binding at " + Errors.convert(scopeBinding.getSource())); for (Object usedSource : usedSources) { sb.append("%n bound directly at " + Errors.convert(usedSource) + ""); } binder .withSource(overideBinding.getSource()) .addError(sb.toString(), scopeBinding.getAnnotationType().getSimpleName()); } } return null; } }.writeAll(scopeBindings);
private <T> ProviderMethod<T> createProviderMethod( Binder binder, Method method, Annotation annotation) { binder = binder.withSource(method); Errors errors = new Errors(method); // prepare the parameter providers InjectionPoint point = InjectionPoint.forMethod(method, typeLiteral); @SuppressWarnings("unchecked") // Define T as the method's return type. TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method); Key<T> key = getKey(errors, returnType, method, method.getAnnotations()); try { key = scanner.prepareMethod(binder, annotation, key, point); } catch (Throwable t) { binder.addError(t); } Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations()); for (Message message : errors.getMessages()) { binder.addError(message); } return ProviderMethod.create( key, method, delegate, ImmutableSet.copyOf(point.getDependencies()), scopeAnnotation, skipFastClassGeneration, annotation); }
if (annotation instanceof Provides) { if (mapKey.annotation != null) { binder.addError("Found a MapKey annotation on non map binding at %s.", method); binder.addError("Found a MapKey annotation on non map binding at %s.", method); binder.addError("No MapKey found for map binding at %s.", method); return key; } else if (annotation instanceof ProvidesIntoOptional) { if (mapKey.annotation != null) { binder.addError("Found a MapKey annotation on non map binding at %s.", method);
private void toConstant(Class<?> type, Object instance) { // this type will define T, so these assignments are safe @SuppressWarnings("unchecked") Class<T> typeAsClassT = (Class<T>) type; @SuppressWarnings("unchecked") T instanceAsT = (T) instance; if (keyTypeIsSet()) { binder.addError(CONSTANT_VALUE_ALREADY_SET); return; } BindingImpl<T> base = getBinding(); Key<T> key; if (base.getKey().getAnnotation() != null) { key = Key.get(typeAsClassT, base.getKey().getAnnotation()); } else if (base.getKey().getAnnotationType() != null) { key = Key.get(typeAsClassT, base.getKey().getAnnotationType()); } else { key = Key.get(typeAsClassT); } if (instanceAsT == null) { binder.addError(BINDING_TO_NULL); } setBinding( new InstanceBindingImpl<T>( base.getSource(), key, base.getScoping(), ImmutableSet.<InjectionPoint>of(), instanceAsT)); }
@Override public void toInstance(T instance) { checkNotTargetted(); // lookup the injection points, adding any errors to the binder's errors list Set<InjectionPoint> injectionPoints; if (instance != null) { try { injectionPoints = InjectionPoint.forInstanceMethodsAndFields(instance.getClass()); } catch (ConfigurationException e) { copyErrorsToBinder(e); injectionPoints = e.getPartialValue(); } } else { binder.addError(BINDING_TO_NULL); injectionPoints = ImmutableSet.of(); } BindingImpl<T> base = getBinding(); setBinding( new InstanceBindingImpl<T>( base.getSource(), base.getKey(), Scoping.EAGER_SINGLETON, injectionPoints, instance)); }
@Override protected void setup(Binder binder) { MaxmindGeoIPModuleConfig geoIPModuleConfig = buildConfigObject(MaxmindGeoIPModuleConfig.class); MaxmindGeoIPEventMapper geoIPEventMapper; try { geoIPEventMapper = new MaxmindGeoIPEventMapper(geoIPModuleConfig); } catch (IOException e) { binder.addError(e); return; } Multibinder.newSetBinder(binder, UserPropertyMapper.class).addBinding().toInstance(geoIPEventMapper); Multibinder.newSetBinder(binder, EventMapper.class).addBinding().toInstance(geoIPEventMapper); }
@Override protected void setup(Binder binder) { GeoIPModuleConfig geoIPModuleConfig = buildConfigObject(GeoIPModuleConfig.class); IP2LocationGeoIPEventMapper geoIPEventMapper; try { geoIPEventMapper = new IP2LocationGeoIPEventMapper(geoIPModuleConfig); } catch (IOException e) { binder.addError(e); return; } Multibinder.newSetBinder(binder, UserPropertyMapper.class).addBinding().toInstance(geoIPEventMapper); Multibinder.newSetBinder(binder, EventMapper.class).addBinding().toInstance(geoIPEventMapper); }
private List<UriPatternMatcher> parsePatterns(UriPatternType type, List<String> patterns) { List<UriPatternMatcher> patternMatchers = new ArrayList<>(); for (String pattern : patterns) { UriPatternMatcher matcher = null; try { matcher = UriPatternType.get(type, pattern); } catch (IllegalArgumentException iae) { binder .skipSources(ServletModule.class, FiltersModuleBuilder.class) .addError("%s", iae.getMessage()); } if (matcher != null) { patternMatchers.add(matcher); } } return patternMatchers; }