override def apply()

in scrooge-generator/src/main/scala/com/twitter/scrooge/backend/CocoaGenerator.scala [348:423]


  override def apply(
    serviceOptions: Set[ServiceOption],
    outputPath: File,
    dryRun: Boolean = false,
    genAdapt: Boolean = false
  ): Iterable[File] = {
    val generatedFiles = new mutable.ListBuffer[File]
    val doc = normalizeCase(resolvedDoc.document)
    val header = headerTemplateLoader.header(resolvedDoc.filePath)
    val namespace = getNamespace(resolvedDoc.document)
    currentNamespace = namespace.fullName
    val packageDir = outputPath
    val includes = doc.headers.collect {
      case x: Include => x
    }

    val enumsWithNamespace = doc.enums.map(enum =>
      Enum(
        SimpleID(currentNamespace + enum.sid.name),
        enum.values,
        enum.docstring,
        enum.annotations
      ))

    if (!dryRun) {
      enumsWithNamespace.foreach { enum =>
        val hFile = new File(packageDir, enum.sid.toTitleCase.name + headerExtension)
        val dict = enumDict(namespace, enum)
        writeFile(hFile, header, headerTemplateLoader("enum").generate(dict))
      }
    }

    val structsWithNamespace = doc.structs.map {
      case union: Union =>
        Union(
          SimpleID(currentNamespace + union.sid.name),
          union.originalName,
          union.fields,
          union.docstring,
          union.annotations
        )
      case struct =>
        Struct(
          SimpleID(currentNamespace + struct.sid.name),
          struct.originalName,
          struct.fields,
          struct.docstring,
          struct.annotations
        )
    }

    if (!dryRun) {
      structsWithNamespace.foreach { struct =>
        val hFile = new File(packageDir, struct.sid.toTitleCase.name + headerExtension)
        val mFile = new File(packageDir, struct.sid.toTitleCase.name + fileExtension)

        val templateName = "struct"
        val dict = structDict(struct, Some(namespace), includes, serviceOptions, true)
        writeFile(
          mFile,
          header,
          implementationTemplateLoader(templateName).generate(dict)
        )
        writeFile(
          hFile,
          header,
          headerTemplateLoader(templateName).generate(dict)
        )

        generatedFiles += hFile
        generatedFiles += mFile
      }
    }

    generatedFiles
  }