Facebook\HackCodegen\BaseCodeBuilder
Facebook\HackCodegen\BaseCodeBuilder
Class containing basic language-agnostic code generation functions
This should not be used directly; instantiable language-specific subclasses should be used to generate code. For example, Hack code is generated using the ` HackBuilder ` class.
Interface Synopsis
namespace Facebook\HackCodegen;
abstract class BaseCodeBuilder {...}
Public Methods
->__construct(IHackCodegenConfig $config)
->add(?string $code): \this
Add code to the buffer->addIf(bool $condition, string $code): \this
If the condition is true, add code to the buffer; otherwise, do nothing->addIff(bool $condition, \HH\Lib\Str\SprintfFormatString $code, \mixed ...$args): \this
If the condition is true, add code to the buffer using a %-placeholder format string and arguments; otherwise, do nothing->addLine(?string $code): \this
Add the code to the buffer followed by a new line->addLineIf(bool $condition, string $code): \this
If the condition is true, append the code followed by a newline->addLineIff(bool $condition, \HH\Lib\Str\SprintfFormatString $code, \mixed ...$args): \this
If the condition is true, append code to the buffer using a %-placeholder format string and arguments, followed by a newline->addLinef(\HH\Lib\Str\SprintfFormatString $code, \mixed ...$args): \this
Add code specified using a %-placeholder format string and arguments, followed by a newline->addLines(Traversable<string> $lines): \this
Add each element of theTraversable
as a new line->addLinesWithSuggestedLineBreaks(\ Traversable<string> $lines): \this
Similar to addWithSuggestedLineBreaks but allows to add more than one line at a time->addVerbatim(string $code): \this
Add the specified code with no additional processing->addVerbatimf(\HH\Lib\Str\SprintfFormatString $code, \mixed ...$args): \this
Add the specified code with a %-placeholder format string, but no further processing->addWithSuggestedLineBreaks(?string $code): \this
Let’s the user suggest linebreaks in the code string provided, marked by the delimiter->addWithSuggestedLineBreaksf(\HH\Lib\Str\SprintfFormatString $code, \mixed ...$args): \this
Insert code with %-placeholder format strings and suggested line breaks->addf(\HH\Lib\Str\SprintfFormatString $code, \mixed ...$args): \this
Add code to the buffer, using a % placeholder format string->endManualSection(): \this
Add to the buffer the end of a manual section->ensureEmptyLine(): \this
Ensures that the cursor is in a new line right after an empty line->ensureNewLine(): \this
If the cursor is not in a new line, it will insert a line break->getCode(): string
Get all the code that has been appended to the buffer->indent(): \this
Increase the logical indentation level->newLine(): \this
Append a new line->setIsInsideFunction(): \this
Indicate that the code that will follow will be inside a function, so that the indentation is taken into account for the max line length->startManualSection(string $id): \this
Add to the buffer the begin of a manual section with the specified id->unindent(): \this
Decrease the logical indentation level
Protected Methods
::checkIfLineIsTooLong(string $code, int $max_length): bool
Returns true if any lines are longer than the maximum length->addLineImplvf(?string $code, \array<\mixed> $args): \this
Add code using the %-placeholder format string and array of values, then insert a newline->addvf(string $code, \array<\mixed> $args): \this
Add code to the buffer, using a % placeholder format string and an array of arguments->getClone(): \this
Create a new builder for the same scope, but a new buffer->getMaxCodeLength(): int
Returns the maximum length of code based on the current identation level->setIndentationLevel(int $level): \void
The logical indentation level