示例#1
0
  /**
   * Create a bind rule that matches a desire when the desired type equals <tt>depType</tt> and the
   * desire's qualifier matches <tt>qualifier</tt> .
   *
   * @param depType The dependency type this bind rule matches
   * @param satisfaction The Satisfaction used by applied desires
   * @param policy The CachePolicy for nodes created by this bind rule
   * @param qualifier The Qualifier the bind rule applies to
   * @param flags The flags to apply to this bind rule and its results.
   * @throws NullPointerException if arguments are null
   */
  public BindRuleImpl(
      @Nonnull Class<?> depType,
      @Nonnull Satisfaction satisfaction,
      @Nonnull CachePolicy policy,
      @Nonnull QualifierMatcher qualifier,
      EnumSet<BindingFlag> flags) {
    Preconditions.notNull("dependency type", depType);
    Preconditions.notNull("satisfaction", satisfaction);
    Preconditions.notNull("policy", policy);
    Preconditions.notNull("qualifier matcher", qualifier);

    this.qualifier = qualifier;
    this.satisfaction = satisfaction;
    this.implType = satisfaction.getErasedType();
    this.policy = policy;
    this.depType = Types.box(depType);
    this.flags = flags.clone();

    // verify that the satisfaction produces proper types
    Preconditions.isAssignable(this.depType, this.implType);
  }
示例#2
0
  /**
   * As the other constructor, but this is used for type to type bindings where the implementation
   * type is not yet instantiable, so there is no satisfaction for the applied desires.
   *
   * @param depType The dependency type this bind rule matches
   * @param implType The implementation type that is bound
   * @param policy The CachePolicy for nodes created by this bind rule
   * @param qualifier The Qualifier the bind rule applies to
   * @param flags The flags to apply to this bind rule and its results.
   * @throws NullPointerException if arguments are null
   */
  public BindRuleImpl(
      @Nonnull Class<?> depType,
      @Nonnull Class<?> implType,
      @Nonnull CachePolicy policy,
      @Nonnull QualifierMatcher qualifier,
      EnumSet<BindingFlag> flags) {
    Preconditions.notNull("dependency type", depType);
    Preconditions.notNull("implementation type", implType);
    Preconditions.notNull("policy", policy);
    Preconditions.notNull("qualifier matcher", qualifier);

    this.qualifier = qualifier;
    this.satisfaction = null;
    this.implType = Types.box(implType);
    this.policy = policy;
    this.depType = Types.box(depType);
    this.flags = flags.clone();

    // verify that implType extends depType
    Preconditions.isAssignable(this.depType, this.implType);
  }