def functionDictionary()

in scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ServiceTemplate.scala [25:94]


  def functionDictionary(function: Function, generic: Option[String]): Dictionary = {
    val hasThrows = function.throws.nonEmpty
    val throwsDictionaries =
      if (hasThrows) {
        function.throws map { ex =>
          Dictionary("throwType" -> genType(ex.fieldType), "throwName" -> genID(ex.sid))
        }
      } else {
        Nil
      }

    val argNames = function.args.map { field => genID(field.sid).toData }

    Dictionary(
      "generic" -> v(generic.map(v)),
      "docstring" -> v(function.docstring.getOrElse("")),
      "hasThrows" -> v(hasThrows),
      "throws" -> v(throwsDictionaries),
      "funcName" -> genID(function.funcName.toCamelCase),
      "violationReturningFuncName" -> genID(
        function.funcName.toTitleCase.prepend("violationReturning")),
      "originalFuncName" -> v(function.originalName),
      "funcObjectName" -> genID(functionObjectName(function)),
      "typeName" -> genType(function.funcType),
      "fieldParams" -> genFieldParams(
        function.args
      ), // A list of parameters with types: (a: A, b: B...)
      "argNames" -> v(argNames.mkString(", ")),
      "argsFieldNames" -> {
        val code = argNames
          .map { field => s"args.$field" }
          .mkString(", ")
        v(code)
      },
      "argTypes" -> {
        function.args match {
          case Nil => v("Unit")
          case singleArg +: Nil => genType(singleArg.fieldType)
          case args =>
            val typesString = args
              .map { arg => genType(arg.fieldType) }
              .mkString(", ")
            v(s"($typesString)")
        }
      },
      "args" -> v(function.args.map { arg =>
        Dictionary(
          "arg" -> genID(arg.sid),
          "typeParameter" -> genType(arg.fieldType),
          "deReferencedArg" -> genOptional(genID(arg.sid), arg.requiredness.isOptional),
          "isOption" -> v(arg.requiredness.isOptional),
          "isValidationType" -> v(arg.fieldType.isInstanceOf[StructType])
        )
      }),
      "isVoid" -> v(function.funcType == Void || function.funcType == OnewayVoid),
      "is_oneway" -> v(function.funcType == OnewayVoid),
      "functionType" -> {
        val returnType = s"Future[${genType(function.funcType)}]"
        val types = s"[Args,$returnType]"
        v(s"Function1$types")
      },
      "reqRepFunctionType" -> {
        val returnType =
          s"Future[_root_.com.twitter.scrooge.Response[${genType(function.funcType)}]]"
        val types = s"[_root_.com.twitter.scrooge.Request[Args],$returnType]"
        v(s"Function1$types")
      },
      "moreThan22Args" -> v(function.args.size > 22)
    )
  }