in src/PartiallyGeneratedCode.hack [54:93]
public function merge(
string $existing_code,
?KeyedContainer<string, Traversable<string>> $rekeys = null,
): string {
$merged = varray[];
$existing = $this->extractManualCode($existing_code);
$generated = $this->iterateCodeSections($this->code);
foreach ($generated as $section) {
list($id, $chunk) = $section;
if ($id === null) {
// Autogenerated section, add it as it is
$merged[] = $chunk;
} else {
if (C\contains_key($existing, $id)) {
// This manual section was present in the existing code, so insert it
$merged[] = $existing[$id];
} else {
$content = vec[];
if ($rekeys !== null) {
if (C\contains_key($rekeys, $id)) {
foreach ($rekeys[$id] as $old_id) {
if (C\contains_key($existing, $old_id)) {
$content[] = $existing[$old_id];
}
}
}
}
if ($content) {
$merged[] = Str\join($content, "\n\n");
} else {
// This manual section is new, so insert inside it the chunk from
// the generated code (e.g. the generated code can have a comment
// saying what that manual section should be used for)
$merged[] = $chunk;
}
}
}
}
return Str\join(\array_filter($merged), "\n");
}