def apply()

in scrooge-generator/src/main/scala/com/twitter/scrooge/frontend/TypeResolver.scala [280:321]


  def apply(definition: Definition, scopePrefix: Option[Identifier]): ResolvedDefinition = {
    definition match {
      case d: Typedef =>
        val resolved = apply(d.fieldType)
        ResolvedDefinition(d.copy(fieldType = resolved), withType(d.sid.name, resolved))
      case s: Struct =>
        // Do not allow Structs with the same name as a Typedef
        if (typeMap.contains(s.sid.name)) {
          val fieldType: FieldType = typeMap(s.sid.name)
          if (fieldType != StructType(s, scopePrefix))
            throw DuplicatedIdentifierException(
              s"Detected a duplicated identifier [${s.sid.name}] for differing types: Struct, ${typeMap(
                s.sid.name)}",
              s
            )
        }
        val resolved = s.copy(fields = s.fields.map(apply))
        ResolvedDefinition(resolved, withType(s.sid.name, StructType(resolved, scopePrefix)))
      case u: Union =>
        val resolved = u.copy(fields = u.fields.map(apply))
        ResolvedDefinition(resolved, withType(u.sid.name, StructType(resolved, scopePrefix)))
      case e: Exception_ =>
        val resolved = e.copy(fields = e.fields.map(apply))
        ResolvedDefinition(resolved, withType(e.sid.name, StructType(resolved, scopePrefix)))
      case c: ConstDefinition =>
        val fieldType = apply(c.fieldType)
        val resolved = c.copy(fieldType = fieldType, value = apply(c.value, fieldType))
        ResolvedDefinition(resolved, withConst(resolved))
      case s: Service =>
        // No need to modify Service, but check that we can resolve parent.
        s.parent.foreach { serviceParent => resolveServiceParent(serviceParent) }
        val resolved = s.copy(functions = s.functions.map(apply))
        ResolvedDefinition(resolved, withService(resolved))
      case e: Enum =>
        ResolvedDefinition(e, withType(e.sid.name, EnumType(e, scopePrefix)))
      case s: Senum =>
        ResolvedDefinition(s, withType(s.sid.name, TString))
      case d: EnumField => ResolvedDefinition(d, this)
      case d: FunctionArgs => ResolvedDefinition(d, this)
      case d: FunctionResult => ResolvedDefinition(d, this)
    }
  }