Facebook\HackCodegen\HackBuilder
Facebook\HackCodegen\HackBuilder
Class to facilitate building code
It has methods for some common patterns used to generate code. It also deals with indentation and new lines.
Interface Synopsis
namespace Facebook\HackCodegen;
final class HackBuilder extends BaseCodeBuilder {...}
Public Methods
::multilineCall(IHackCodegenConfig $config, string $name, \ Traversable<string> $params, bool $close_statement = false): string
->addAssignment<\T>(string $var_name, \T $value, \ IHackBuilderValueRenderer<\T> $renderer): \this
->addCase<\T>(\T $case, \ IHackBuilderValueRenderer<\T> $formatter): \this
->addCaseBlocks<\T>(\ Traversable<\T> $switch_values, \callable $func): \this
->addCatchBlock(string $class, string $variable): \this
Start a catch block->addDefault(): \this
->addDocBlock(?string $comment, ?int $max_length = NULL): \this
Add a Doc Block in the buffer->addElseBlock(): \this
End current if/else block, and start a else block->addElseIfBlock(string $condition): \this
End current if/else block, and start a ‘else if (condition)’ block->addElseIfBlockf(\HH\Lib\Str\SprintfFormatString $condition, \mixed ...$args): \this
->addFinallyBlock(): \this
Start a finally block->addInlineComment(?string $comment): \this
Add a //-style comment->addInlineCommentWithStars(?string $comment): \this
Add a /*-style comment->addMultilineCall(string $func_call_line, \ Traversable<string> $params, bool $include_close_statement = true): \this
This method lets you call Multiline methods and also allows you to suggest line breaks->addRenderer(ICodeBuilderRenderer $renderer): \this
->addReturn<\T>(\T $value, \ IHackBuilderValueRenderer<\T> $renderer): \this
->addReturnf(\HH\Lib\Str\SprintfFormatString $value, \mixed ...$args): \this
->addValue<\T>(\T $value, \IHackBuilderValueRenderer<\T> $r): \this
->addWrappedString(string $line, ?int $max_length = NULL): \this
Add a string that is auto-wrapped to not exceed the maximum length->addWrappedStringNoIndent(string $line, ?int $max_length = NULL): \this
Add a string that is auto-wrapped to not exceed the maximum length->breakCase(): \this
->closeBrace(): \this
Close a brace in a new line and sets one less level of indentation->closeContainer(ContainerType $type): \this
->closeStatement(): \this
->endDefault(): \this
->endForeachLoop(): \this
Strictly equivalent to calling closeBrace, which unindent and newline, but for readability, you should use this with startForeach->endIfBlock(): \this
Strictly equivalent to calling closeBrace, which unindent and newline, but for readability, you should use this with startIfBlock->endSwitch(): \this
->endTryBlock(): \this
Strictly equivalent to calling closeBrace, which unindent and newline, but for readability, you should use this with startTryBlock->openBrace(): \this
Open a brace in the current line and start a new line with one more level of indentation->openContainer(ContainerType $type): \this
->returnCase<\T>(\T $value, \ IHackBuilderValueRenderer<\T> $r): \this
->returnCasef(\HH\Lib\Str\SprintfFormatString $value, \mixed ...$args): \this
->startForeachLoop(string $traversable, ?string $key, string $value): \this
Start a foreach loop, generate the temporary variable assignement, then it’s equivalent to calling openBrace, which newline and indent->startIfBlock(string $condition): \this
Start a if block, put the condition between the parenthesis, then it’s equivalent to calling openBrace, which newline and indent->startIfBlockf(\HH\Lib\Str\SprintfFormatString $condition, \mixed ...$args): \this
->startSwitch(string $condition): \this
Starts building a switch-statement that can loop over an Iterable to build each case-statement->startTryBlock(): \this
Start try-catch-finally blocks in the code
Private Methods
->addSimpleMultilineCall(string $name, \ Traversable<string> $params): \this
Used in static function multilineCall where we don’t know the current indentation to wrap code correctly->addWrappedStringImpl(string $line, ?int $max_length = NULL, bool $indent_non_first_lines = true): \this
->assertIsVariable(string $name): \void
->splitString(string $str, int $maxlen, bool $preserve_space = false): vec<string>
Split a string on lines of at most $maxlen length