---
layout: docs
title: Facebook\HackCodegen\CodegenFile
id: class.Facebook.HackCodegen.CodegenFile
docid: class.Facebook.HackCodegen.CodegenFile
permalink: /docs/reference/class.Facebook.HackCodegen.CodegenFile/
---
# Facebook\\HackCodegen\\CodegenFile




File of generated code




The file is composed by classes.
The file will be signed, either as autogenerated or partially generated,
depending on whether there are manual sections.




## Interface Synopsis




``` Hack
namespace Facebook\HackCodegen;

final class CodegenFile {...}
```




### Public Methods




* [` ->__construct(IHackCodegenConfig $config, string $file_name) `](<class.Facebook.HackCodegen.CodegenFile.__construct.md>)
* [` ->addAfterType(CodegenType $type): \this `](<class.Facebook.HackCodegen.CodegenFile.addAfterType.md>)
* [` ->addAfterTypes(Traversable<CodegenType> $types): \this `](<class.Facebook.HackCodegen.CodegenFile.addAfterTypes.md>)
* [` ->addBeforeType(CodegenType $type): \this `](<class.Facebook.HackCodegen.CodegenFile.addBeforeType.md>)
* [` ->addBeforeTypes(Traversable<CodegenType> $types): \this `](<class.Facebook.HackCodegen.CodegenFile.addBeforeTypes.md>)
* [` ->addClass(CodegenClassish $class): \this `](<class.Facebook.HackCodegen.CodegenFile.addClass.md>)
* [` ->addClasses(Traversable<CodegenClassish> $classes): \this `](<class.Facebook.HackCodegen.CodegenFile.addClasses.md>)
* [` ->addConstant(CodegenConstant $const): \this `](<class.Facebook.HackCodegen.CodegenFile.addConstant.md>)
* [` ->addConstants(Traversable<CodegenConstant> $constants): \this `](<class.Facebook.HackCodegen.CodegenFile.addConstants.md>)
* [` ->addFunction(CodegenFunction $function): \this `](<class.Facebook.HackCodegen.CodegenFile.addFunction.md>)
* [` ->addFunctions(Traversable<CodegenFunction> $functions): \this `](<class.Facebook.HackCodegen.CodegenFile.addFunctions.md>)
* [` ->addOriginalFile(string $file_name): \this `](<class.Facebook.HackCodegen.CodegenFile.addOriginalFile.md>)\
  Use this when refactoring generated code
* [` ->addTrait(CodegenTrait $trait): \this `](<class.Facebook.HackCodegen.CodegenFile.addTrait.md>)
* [` ->createOnly(): \this `](<class.Facebook.HackCodegen.CodegenFile.createOnly.md>)\
  If called, save() will only write the file if it doesn't exist
* [` ->exists(): bool `](<class.Facebook.HackCodegen.CodegenFile.exists.md>)
* [` ->getAfterTypes(): vec<CodegenType> `](<class.Facebook.HackCodegen.CodegenFile.getAfterTypes.md>)
* [` ->getBeforeTypes(): vec<CodegenType> `](<class.Facebook.HackCodegen.CodegenFile.getBeforeTypes.md>)
* [` ->getClasses(): vec<CodegenClassish> `](<class.Facebook.HackCodegen.CodegenFile.getClasses.md>)
* [` ->getFileName(): string `](<class.Facebook.HackCodegen.CodegenFile.getFileName.md>)\
  The absolute path
* [` ->getFunctions(): vec<CodegenFunction> `](<class.Facebook.HackCodegen.CodegenFile.getFunctions.md>)
* [` ->getRelativeFileName(): string `](<class.Facebook.HackCodegen.CodegenFile.getRelativeFileName.md>)
* [` ->rekeyManualSection(string $old_key, string $new_key): \this `](<class.Facebook.HackCodegen.CodegenFile.rekeyManualSection.md>)\
  Use this to pull manual code from a section keyed by $old_key and
  place it in a section keyed by $new_key
* [` ->render(): string `](<class.Facebook.HackCodegen.CodegenFile.render.md>)
* [` ->save(): CodegenFileResult `](<class.Facebook.HackCodegen.CodegenFile.save.md>)\
  Saves the generated file
* [` ->setDoClobber(bool $do_force): \this `](<class.Facebook.HackCodegen.CodegenFile.setDoClobber.md>)\
  Use this to skip reading in the existing file
* [` ->setDocBlock(string $comment): \this `](<class.Facebook.HackCodegen.CodegenFile.setDocBlock.md>)
* [` ->setFileType(CodegenFileType $type): \this `](<class.Facebook.HackCodegen.CodegenFile.setFileType.md>)
* [` ->setGeneratedFrom(CodegenGeneratedFrom $from): \this `](<class.Facebook.HackCodegen.CodegenFile.setGeneratedFrom.md>)
* [` ->setIsSignedFile(bool $value): \this `](<class.Facebook.HackCodegen.CodegenFile.setIsSignedFile.md>)
* [` ->setNamespace(string $file_namespace): \this `](<class.Facebook.HackCodegen.CodegenFile.setNamespace.md>)
* [` ->setPseudoMainFooter(string $code): \this `](<class.Facebook.HackCodegen.CodegenFile.setPseudoMainFooter.md>)\
  Use to execute code after declarations
* [` ->setPseudoMainFooterf(\HH\Lib\Str\SprintfFormatString $format, \mixed ...$args): \this `](<class.Facebook.HackCodegen.CodegenFile.setPseudoMainFooterf.md>)
* [` ->setPseudoMainHeader(string $code): \this `](<class.Facebook.HackCodegen.CodegenFile.setPseudoMainHeader.md>)\
  Use to execute code before declarations
* [` ->setPseudoMainHeaderf(\HH\Lib\Str\SprintfFormatString $format, \mixed ...$args): \this `](<class.Facebook.HackCodegen.CodegenFile.setPseudoMainHeaderf.md>)
* [` ->setShebangLine(string $shebang): \this `](<class.Facebook.HackCodegen.CodegenFile.setShebangLine.md>)\
  Useful when creating scripts
* [` ->setShebangLinef(\HH\Lib\Str\SprintfFormatString $format, \mixed ...$args): \this `](<class.Facebook.HackCodegen.CodegenFile.setShebangLinef.md>)
* [` ->useConst(string $ns, ?string $as = NULL): \this `](<class.Facebook.HackCodegen.CodegenFile.useConst.md>)
* [` ->useFunction(string $ns, ?string $as = NULL): \this `](<class.Facebook.HackCodegen.CodegenFile.useFunction.md>)
* [` ->useNamespace(string $ns, ?string $as = NULL): \this `](<class.Facebook.HackCodegen.CodegenFile.useNamespace.md>)
* [` ->useType(string $ns, ?string $as = NULL): \this `](<class.Facebook.HackCodegen.CodegenFile.useType.md>)







### Private Methods




- [` ->assertNotHackStrictForExecutable(): \void `](<class.Facebook.HackCodegen.CodegenFile.assertNotHackStrictForExecutable.md>)
- [` ->getContent(): string `](<class.Facebook.HackCodegen.CodegenFile.getContent.md>)
- [` ->getFileTypeDeclaration(): string `](<class.Facebook.HackCodegen.CodegenFile.getFileTypeDeclaration.md>)
- [` ->loadExistingFiles(): ?string `](<class.Facebook.HackCodegen.CodegenFile.loadExistingFiles.md>)