private[this] def bind()

in inject/inject-app/src/main/scala/com/twitter/inject/app/internal/FlagsModule.scala [130:169]


  private[this] def bind(f: Flag[_]): Unit = {
    debug("Binding flag: " + f.name + " = " + f.getWithDefaultUnparsed)

    // Preserve the legacy behavior and bind raw flag value as Strings.
    bindAsString(f)

    collectInjectTypes(f.flaggable) match {
      case Some((full, _)) if full == classOf[String] =>
        // We've already bound this flag as String.
        // What's left is Option[String] and Optional[String] (provided f has no default value).
        bindAsStringOption(f)

      case Some((full, partial)) if full == partial =>
        // Full and partial types are the same (there were no primitive types involved).
        // Binding to one of them is sufficient.
        bindAsOptionT(f, full)
        bindAsT(f, full)

      case Some((full, partial)) if partial == classOf[Object] =>
        // Full and partial types are different but partial was simplified to an Object (from a
        // full primitive type). No need to bind to an Object as Guice never looks it up. Turns out,
        // `@Flag i: Int` would look for java.lang.Integer and not the java.lang.Object.
        bindAsOptionT(f, full)
        bindAsT(f, full)
        bindAsOptionT(f, partial)

      case Some((full, partial)) =>
        // Full and partial types are different so we bind both of them.
        bindAsOptionT(f, full)
        bindAsT(f, full)
        bindAsOptionT(f, partial)
        bindAsT(f, partial)

      case None =>
        // Not all Flaggables were Flaggable.Typed. Fallback to string-based injection.
        // We've already bound this flag as String. What's left is Option[String] and
        // Optional[String] (provided f has no default value).
        bindAsStringOption(f)
    }
  }