encounter.addError("Cannot obtain config value for " + parameter.getParameterizedType() + " at path: " + path); return Optional.empty();
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { if (Initializable.class.isAssignableFrom(type.getRawType())) { encounter.register(new InjectionListener<I>() { @Override public void afterInjection(I injectee) { if (injectee instanceof Initializable) { Initializable initializable = (Initializable) injectee; initializable.init(); } } }); } else { encounter.addError("Unsupported type: %s", type); } } }
/** * Allows traverse the input klass hierarchy. * * @param parentType the owning type being heard * @param klass encountered by Guice. * @param encounter the injection context. */ private <I> void hear(final TypeLiteral<I> parentType, Class<? super I> klass, TypeEncounter<I> encounter) { Package pkg; if (klass == null || ((pkg = klass.getPackage()) != null && pkg.getName().startsWith(JAVA_PACKAGE))) { return; } for (Class<? extends Annotation> annotationType : annotationTypes) { for (Method method : klass.getDeclaredMethods()) { if (method.isAnnotationPresent(annotationType)) { if (method.getParameterTypes().length != 0) { encounter.addError("Annotated methods with @%s must not accept any argument, found %s", annotationType.getName(), method); } hear(method, parentType, encounter, annotationType); } } } hear(parentType, klass.getSuperclass(), encounter); }
/** * Allows traverse the input type hierarchy. * * @param type encountered by Guice. * @param encounter the injection context. */ private <I> void hear( Class<? super I> type, TypeEncounter<I> encounter ) { if ( type == null || type.getPackage().getName().startsWith( JAVA_PACKAGE ) ) { return; } for ( Method method : type.getDeclaredMethods() ) { if ( method.isAnnotationPresent( annotationType ) ) { if ( method.getParameterTypes().length != 0 ) { encounter.addError( "Annotated methods with @%s must not accept any argument, found %s", annotationType.getName(), method ); } hear( method, encounter ); } } hear( type.getSuperclass(), encounter ); }
@Override public <I> void hear(final TypeLiteral<I> literal, TypeEncounter<I> encounter) { Class<? super I> klass = literal.getRawType(); do { for (Method method : klass.getDeclaredMethods()) { if (method.isSynthetic()) { continue; } final Gauge annotation = annotationResolver.findAnnotation(Gauge.class, method); if (annotation != null) { if (method.getParameterTypes().length == 0) { final String metricName = metricNamer.getNameForGauge(method, annotation); if (!method.isAccessible()) { method.setAccessible(true); } encounter.register(new GaugeInjectionListener<I>(metricRegistry, metricName, method)); } else { encounter.addError("Method %s is annotated with @Gauge but requires parameters.", method); } } } } while ((klass = klass.getSuperclass()) != null); } }
encounter.addError("Method %s is annotated with @Gauge but requires parameters.", method);
/** * {@inheritDoc} */ public <I> void hear( final TypeLiteral<I> typeLiteral, final TypeEncounter<I> typeEncounter ) { try { new ClassVisitor() .registerHandler( Mock.class, new AnnotationHandler<Mock, Field>() { public void handle( Mock annotation, Field field ) throws HandleException { typeEncounter.register( new MockMembersInjector<I>( field, mockedObjects ) ); } } ) .visit( typeLiteral.getRawType() ); } catch ( HandleException e ) { typeEncounter.addError( e ); } }
@Override public <I> void hear(final TypeLiteral<I> literal, TypeEncounter<I> encounter) { for (final Method method : literal.getRawType().getMethods()) { final Gauge annotation = method.getAnnotation(Gauge.class); if (annotation != null) { if (method.getParameterTypes().length == 0) { final String group = MetricName.chooseGroup(annotation.group(), literal.getRawType()); final String type = MetricName.chooseType(annotation.type(), literal.getRawType()); final String name = MetricName.chooseName(annotation.name(), method); final MetricName metricName = new MetricName(group, type, name); encounter.register(new GaugeInjectionListener<I>(metricsRegistry, metricName, method)); } else { encounter.addError("Method %s is annotated with @Gauge but requires parameters.", method); } } } }
encounter.addError( "Error binding bean property: " + property + " reason: " + e );
encounter.addError( new ProvisionException( "Error binding: " + property, e ) );
encounter.addError( new ProvisionException( "Error binding: " + property, e ) );