@Override public Object get() { try { return constructor.newInstance(params(pp)); } catch (Exception e) { throw new InjectException(e, "cannot instantiate %s", spec); } } };
private static void foundCircularDependency(Set<BeanSpec> chain, BeanSpec last) { throw InjectException.circularDependency(debugChain(chain, last)); }
@Override public Object get() { try { return constructor.newInstance(params(pp)); } catch (Exception e) { throw new InjectException(e, "cannot instantiate %s", spec); } } };
private static void foundCircularDependency(Set<BeanSpec> chain, BeanSpec last) { throw InjectException.circularDependency(debugChain(chain, last)); }
Object applyTo(Object bean) { try { return method.invoke(bean, params(providers)); } catch (Exception e) { throw new InjectException(e, "Unable to invoke method[%s] on %s", method.getName(), bean.getClass()); } }
Object applyTo(Object bean) { try { return method.invoke(bean, params(providers)); } catch (Exception e) { throw new InjectException(e, "Unable to invoke method[%s] on %s", method.getName(), bean.getClass()); } }
Constructor getDeclaredConstructor() { try { return rawType().getDeclaredConstructor(); } catch (NoSuchMethodException e) { throw new InjectException(e, "cannot instantiate %s", rawType); } }
void setField(Object bean, Object value) { E.illegalStateIf(null == field); try { field.set(bean, value); } catch (Exception e) { throw new InjectException(e, "Unable to inject field value on %s", bean.getClass()); } }
Constructor getDeclaredConstructor() { try { return rawType().getDeclaredConstructor(); } catch (NoSuchMethodException e) { throw new InjectException(e, "cannot instantiate %s", rawType); } }
void setField(Object bean, Object value) { E.illegalStateIf(null == field); try { field.set(bean, value); } catch (Exception e) { throw new InjectException(e, "Unable to inject field value on %s", bean.getClass()); } }
/** * Add qualifier annotation constraints to this binder * * Each qualifier annotation type must be tagged with {@link Qualifier} annotation. * Otherwise an {@link InjectException} will be thrown out * * @param qualifiers * an array of qualifier annotation types * @return this binder instance * @throws InjectException * if the any qualifier class is not tagged with {@link Qualifier} * @see Qualifier */ public Binder<T> qualifiedWith(Class<? extends Annotation>... qualifiers) { for (Class<? extends Annotation> qualifier : qualifiers) { if (!qualifier.isAnnotationPresent(Qualifier.class)) { throw new InjectException( "Qualifier annotation type must have \"@Qualifier\" annotation presented: " + qualifier.getName()); } this.annotations.add(AnnotationUtil.createAnnotation(qualifier)); } this.fireEvent = false; return this; }
/** * Add qualifier annotation constraints to this binder * * Each qualifier annotation type must be tagged with {@link Qualifier} annotation. * Otherwise an {@link InjectException} will be thrown out * * @param qualifiers * an array of qualifier annotation types * @return this binder instance * @throws InjectException * if the any qualifier class is not tagged with {@link Qualifier} * @see Qualifier */ public Binder<T> qualifiedWith(Class<? extends Annotation>... qualifiers) { for (Class<? extends Annotation> qualifier : qualifiers) { if (!qualifier.isAnnotationPresent(Qualifier.class)) { throw new InjectException( "Qualifier annotation type must have \"@Qualifier\" annotation presented: " + qualifier.getName()); } this.annotations.add(AnnotationUtil.createAnnotation(qualifier)); } this.fireEvent = false; return this; }
/** * Constraint the binder with a scope annotation class. * * Once the constraint is added to this binder the binding will search * for candidates within the scope constraint only * * The scope annotation class must be tagged with {@link Scope} annotation. * Otherwise a {@link InjectException} will be thrown out. * * @param scope * the scope annotation class * @return this binder instance * @throws InjectException * if the scope class is not annotated with {@link Scope} * @throws IllegalStateException * if there is already a scope annotation constraint put on this binder * @see Scope */ public Binder<T> in(Class<? extends Annotation> scope) { if (!scope.isAnnotationPresent(Scope.class)) { throw new InjectException( "the scope annotation type must have @Scope annotation presented: " + scope.getName()); } E.illegalStateIf(null != this.scope, "Scope has already been specified"); this.scope = scope; this.fireEvent = false; return this; }
/** * Add qualifier annotation constraints to this binder * * The type of each qualifier annotation must be tagged with {@link Qualifier} * annotation. Otherwise an {@link InjectException} will be thrown out * * @param qualifiers * an array of qualifier annotations * @return this binder instance * @throws InjectException * if the any qualifier's class is not tagged with {@link Qualifier} * @see Qualifier */ public Binder<T> qualifiedWith(Annotation... qualifiers) { for (Annotation qualifier : qualifiers) { Class<? extends Annotation> qulifierType = qualifier.annotationType(); if (!qulifierType.isAnnotationPresent(Qualifier.class)) { throw new InjectException( "Qualifier annotation type must have \"@Qualifier\" annotation presented: " + qulifierType.getName()); } this.annotations.add(AnnotationUtil.createAnnotation(qulifierType)); } this.fireEvent = false; return this; }
/** * Add qualifier annotation constraints to this binder * * The type of each qualifier annotation must be tagged with {@link Qualifier} * annotation. Otherwise an {@link InjectException} will be thrown out * * @param qualifiers * an array of qualifier annotations * @return this binder instance * @throws InjectException * if the any qualifier's class is not tagged with {@link Qualifier} * @see Qualifier */ public Binder<T> qualifiedWith(Annotation... qualifiers) { for (Annotation qualifier : qualifiers) { Class<? extends Annotation> qulifierType = qualifier.annotationType(); if (!qulifierType.isAnnotationPresent(Qualifier.class)) { throw new InjectException( "Qualifier annotation type must have \"@Qualifier\" annotation presented: " + qulifierType.getName()); } this.annotations.add(AnnotationUtil.createAnnotation(qulifierType)); } this.fireEvent = false; return this; }
/** * Constraint the binder with a scope annotation class. * * Once the constraint is added to this binder the binding will search * for candidates within the scope constraint only * * The scope annotation class must be tagged with {@link Scope} annotation. * Otherwise a {@link InjectException} will be thrown out. * * @param scope * the scope annotation class * @return this binder instance * @throws InjectException * if the scope class is not annotated with {@link Scope} * @throws IllegalStateException * if there is already a scope annotation constraint put on this binder * @see Scope */ public Binder<T> in(Class<? extends Annotation> scope) { if (!scope.isAnnotationPresent(Scope.class)) { throw new InjectException( "the scope annotation type must have @Scope annotation presented: " + scope.getName()); } E.illegalStateIf(null != this.scope, "Scope has already been specified"); this.scope = scope; this.fireEvent = false; return this; }
throw (RuntimeException) t; throw new InjectException(t, "cannot instantiate %s", spec); } catch (Exception e) { throw new InjectException(e, "cannot instantiate %s", spec);
throw (RuntimeException) t; throw new InjectException(t, "cannot instantiate %s", spec); } catch (Exception e) { throw new InjectException(e, "cannot instantiate %s", spec);
private Class<T> targetClass($.Var<ElementType> typeVar, Map<String, Object> options, BeanSpec container) { Object hint = options.get("value"); E.illegalArgumentIf(!(hint instanceof Class)); Class<?> targetClass = $.cast(hint); Class<?> inferredTargetClass = LoaderUtil.targetClass(typeVar, container); if (null != inferredTargetClass) { if (TypeOf.PlaceHolder.class == targetClass) { targetClass = inferredTargetClass; } else if (!inferredTargetClass.isAssignableFrom(targetClass)) { throw new InjectException("specified class[%s] doesn't match the container spec: %s", targetClass, container); } } else if (TypeOf.PlaceHolder.class == targetClass) { if (TypeOf.PlaceHolder.class == targetClass) { throw new InjectException("Cannot load element - target type info is missing"); } } return $.cast(targetClass); }
private Class<T> targetClass($.Var<ElementType> typeVar, Map<String, Object> options, BeanSpec container) { Object hint = options.get("value"); E.illegalArgumentIf(!(hint instanceof Class)); Class<?> targetClass = $.cast(hint); Class<?> inferredTargetClass = LoaderUtil.targetClass(typeVar, container); if (null != inferredTargetClass) { if (TypeOf.PlaceHolder.class == targetClass) { targetClass = inferredTargetClass; } else if (!inferredTargetClass.isAssignableFrom(targetClass)) { throw new InjectException("specified class[%s] doesn't match the container spec: %s", targetClass, container); } } else if (TypeOf.PlaceHolder.class == targetClass) { if (TypeOf.PlaceHolder.class == targetClass) { throw new InjectException("Cannot load element - target type info is missing"); } } return $.cast(targetClass); }