public function render()

in src/CodegenFile.hack [304:375]


  public function render(): string {
    $builder = new HackBuilder($this->config);

    $shebang = $this->shebang;
    if ($shebang !== null) {
      $builder->addLine($shebang);
    }

    $decl = $this->getFileTypeDeclaration();
    if ($decl !== '') {
      $builder->addLine($decl);
    }
    $header = $this->config->getFileHeader();
    if ($header) {
      foreach ($header as $line) {
        $builder->addInlineComment($line);
      }
    }

    $content = $this->getContent();

    $doc_block = $this->docBlock;
    $gen_from = $this->generatedFrom;
    if ($gen_from !== null) {
      if ($doc_block !== null && !Str\ends_with($doc_block, "\n")) {
        $doc_block .= "\n";
      }
      $doc_block = ($doc_block ?? '').$gen_from->render()."\n";
    }

    $formatter = $this->config->getFormatter();

    if (!$this->isSignedFile) {
      $builder->addDocBlock($doc_block);
      $builder->add($content);
      $content = $builder->getCode();
      if ($formatter !== null) {
        $content = $formatter->format($content, $this->getFileName());
      }
      return $content;
    }

    $old_content = $this->loadExistingFiles();

    if (PartiallyGeneratedCode::containsManualSection($content)) {
      $builder->addDocBlock(
        PartiallyGeneratedSignedSource::getDocBlock($doc_block),
      );
      $builder->add($content);

      $code = $builder->getCode();
      $partial = new PartiallyGeneratedCode($code);
      if ($old_content !== null) {
        $code = $partial->merge($old_content, $this->rekey);
      } else {
        $partial->assertValidManualSections();
      }
      if ($formatter !== null) {
        $code = $formatter->format($code, $this->getFileName());
      }
      return PartiallyGeneratedSignedSource::signFile($code);

    } else {
      $builder->addDocBlock(SignedSource::getDocBlock($doc_block));
      $builder->add($content);
      $code = $builder->getCode();
      if ($formatter !== null) {
        $code = $formatter->format($code, $this->getFileName());
      }
      return SignedSource::signFile($code);
    }
  }