+ $result = '';
+ foreach ($diff as $i => $diffElem) {
+ $diffType = $diffElem->type;
+ /** @var Node|null $arrItem */
+ $arrItem = $diffElem->new;
+ /** @var Node|null $origArrItem */
+ $origArrItem = $diffElem->old;
+
+ if ($diffType === DiffElem::TYPE_KEEP || $diffType === DiffElem::TYPE_REPLACE) {
+ $beforeFirstKeepOrReplace = false;
+
+ if ($origArrItem === null || $arrItem === null) {
+ // We can only handle the case where both are null
+ if ($origArrItem === $arrItem) {
+ continue;
+ }
+ return null;
+ }
+
+ if (!$arrItem instanceof Node || !$origArrItem instanceof Node) {
+ // We can only deal with nodes. This can occur for Names, which use string arrays.
+ return null;
+ }
+
+ $itemStartPos = $origArrItem->getStartTokenPos();
+ $itemEndPos = $origArrItem->getEndTokenPos();
+ \assert($itemStartPos >= 0 && $itemEndPos >= 0);
+
+ if ($itemEndPos < $itemStartPos) {
+ // End can be before start for Nop nodes, because offsets refer to non-whitespace
+ // locations, which for an "empty" node might result in an inverted order.
+ assert($origArrItem instanceof Stmt\Nop);
+ continue;
+ }
+
+ $origIndentLevel = $this->indentLevel;
+ $lastElemIndentLevel = $this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment;
+ $this->setIndentLevel($lastElemIndentLevel);
+
+ $comments = $arrItem->getComments();
+ $origComments = $origArrItem->getComments();
+ $commentStartPos = $origComments ? $origComments[0]->getTokenPos() : $itemStartPos;
+ \assert($commentStartPos >= 0);
+
+ $commentsChanged = $comments !== $origComments;
+ if ($commentsChanged) {
+ // Remove old comments
+ $itemStartPos = $commentStartPos;
+ }
+
+ if (!empty($delayedAdd)) {
+ $result .= $this->origTokens->getTokenCode(
+ $pos, $commentStartPos, $indentAdjustment);
+
+ /** @var Node $delayedAddNode */
+ foreach ($delayedAdd as $delayedAddNode) {
+ if ($insertNewline) {
+ $delayedAddComments = $delayedAddNode->getComments();
+ if ($delayedAddComments) {
+ $result .= $this->pComments($delayedAddComments) . $this->nl;
+ }
+ }
+
+ $this->safeAppend($result, $this->p($delayedAddNode, true));
+
+ if ($insertNewline) {
+ $result .= $insertStr . $this->nl;
+ } else {
+ $result .= $insertStr;
+ }
+ }
+
+ $result .= $this->origTokens->getTokenCode(
+ $commentStartPos, $itemStartPos, $indentAdjustment);
+
+ $delayedAdd = [];
+ } else {
+ $result .= $this->origTokens->getTokenCode(
+ $pos, $itemStartPos, $indentAdjustment);
+ }
+
+ if ($commentsChanged && $comments) {
+ // Add new comments
+ $result .= $this->pComments($comments) . $this->nl;
+ }
+ } elseif ($diffType === DiffElem::TYPE_ADD) {
+ if (null === $insertStr) {
+ // We don't have insertion information for this list type
+ return null;
+ }
+
+ if ($insertStr === ', ' && $this->isMultiline($origNodes)) {
+ $insertStr = ',';
+ $insertNewline = true;
+ }
+
+ if ($beforeFirstKeepOrReplace) {
+ // Will be inserted at the next "replace" or "keep" element
+ $delayedAdd[] = $arrItem;
+ continue;
+ }
+
+ $itemStartPos = $pos;
+ $itemEndPos = $pos - 1;
+
+ $origIndentLevel = $this->indentLevel;
+ $this->setIndentLevel($lastElemIndentLevel);
+
+ if ($insertNewline) {
+ $comments = $arrItem->getComments();
+ if ($comments) {
+ $result .= $this->nl . $this->pComments($comments);
+ }
+ $result .= $insertStr . $this->nl;
+ } else {
+ $result .= $insertStr;
+ }
+ } elseif ($diffType === DiffElem::TYPE_REMOVE) {
+ if ($i === 0) {
+ // TODO Handle removal at the start
+ return null;
+ }
+
+ if (!$origArrItem instanceof Node) {
+ // We only support removal for nodes
+ return null;
+ }
+
+ $itemEndPos = $origArrItem->getEndTokenPos();
+ \assert($itemEndPos >= 0);
+
+ $pos = $itemEndPos + 1;
+ continue;
+ } else {
+ throw new \Exception("Shouldn't happen");
+ }
+
+ if (null !== $fixup && $arrItem->getAttribute('origNode') !== $origArrItem) {
+ $res = $this->pFixup($fixup, $arrItem, null, $itemStartPos, $itemEndPos);
+ } else {
+ $res = $this->p($arrItem, true);
+ }
+ $this->safeAppend($result, $res);
+
+ $this->setIndentLevel($origIndentLevel);
+ $pos = $itemEndPos + 1;
+ }
+
+ if (!empty($delayedAdd)) {
+ // TODO Handle insertion into empty list
+ return null;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Print node with fixups.
+ *
+ * Fixups here refer to the addition of extra parentheses, braces or other characters, that
+ * are required to preserve program semantics in a certain context (e.g. to maintain precedence
+ * or because only certain expressions are allowed in certain places).
+ *
+ * @param int $fixup Fixup type
+ * @param Node $subNode Subnode to print
+ * @param string|null $parentClass Class of parent node
+ * @param int $subStartPos Original start pos of subnode
+ * @param int $subEndPos Original end pos of subnode
+ *
+ * @return string Result of fixed-up print of subnode
+ */
+ protected function pFixup(int $fixup, Node $subNode, $parentClass, int $subStartPos, int $subEndPos) : string {
+ switch ($fixup) {
+ case self::FIXUP_PREC_LEFT:
+ case self::FIXUP_PREC_RIGHT:
+ if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) {
+ list($precedence, $associativity) = $this->precedenceMap[$parentClass];
+ return $this->pPrec($subNode, $precedence, $associativity,
+ $fixup === self::FIXUP_PREC_LEFT ? -1 : 1);
+ }
+ break;
+ case self::FIXUP_CALL_LHS:
+ if ($this->callLhsRequiresParens($subNode)
+ && !$this->origTokens->haveParens($subStartPos, $subEndPos)
+ ) {
+ return '(' . $this->p($subNode) . ')';
+ }
+ break;
+ case self::FIXUP_DEREF_LHS:
+ if ($this->dereferenceLhsRequiresParens($subNode)
+ && !$this->origTokens->haveParens($subStartPos, $subEndPos)
+ ) {
+ return '(' . $this->p($subNode) . ')';
+ }
+ break;
+ case self::FIXUP_BRACED_NAME:
+ case self::FIXUP_VAR_BRACED_NAME:
+ if ($subNode instanceof Expr
+ && !$this->origTokens->haveBraces($subStartPos, $subEndPos)
+ ) {
+ return ($fixup === self::FIXUP_VAR_BRACED_NAME ? '$' : '')
+ . '{' . $this->p($subNode) . '}';
+ }
+ break;
+ case self::FIXUP_ENCAPSED:
+ if (!$subNode instanceof Scalar\EncapsedStringPart
+ && !$this->origTokens->haveBraces($subStartPos, $subEndPos)
+ ) {
+ return '{' . $this->p($subNode) . '}';
+ }
+ break;
+ default:
+ throw new \Exception('Cannot happen');
+ }
+
+ // Nothing special to do
+ return $this->p($subNode);
+ }
+
+ /**
+ * Appends to a string, ensuring whitespace between label characters.
+ *
+ * Example: "echo" and "$x" result in "echo$x", but "echo" and "x" result in "echo x".
+ * Without safeAppend the result would be "echox", which does not preserve semantics.
+ *
+ * @param string $str
+ * @param string $append
+ */
+ protected function safeAppend(string &$str, string $append) {
+ // $append must not be empty in this function
+ if ($str === "") {
+ $str = $append;
+ return;
+ }
+
+ if (!$this->labelCharMap[$append[0]]
+ || !$this->labelCharMap[$str[\strlen($str) - 1]]) {
+ $str .= $append;
+ } else {
+ $str .= " " . $append;
+ }
+ }
+
+ /**
+ * Determines whether the LHS of a call must be wrapped in parenthesis.
+ *
+ * @param Node $node LHS of a call
+ *
+ * @return bool Whether parentheses are required
+ */
+ protected function callLhsRequiresParens(Node $node) : bool {
+ return !($node instanceof Node\Name
+ || $node instanceof Expr\Variable
+ || $node instanceof Expr\ArrayDimFetch
+ || $node instanceof Expr\FuncCall
+ || $node instanceof Expr\MethodCall
+ || $node instanceof Expr\StaticCall
+ || $node instanceof Expr\Array_);
+ }
+
+ /**
+ * Determines whether the LHS of a dereferencing operation must be wrapped in parenthesis.
+ *
+ * @param Node $node LHS of dereferencing operation
+ *
+ * @return bool Whether parentheses are required
+ */
+ protected function dereferenceLhsRequiresParens(Node $node) : bool {
+ return !($node instanceof Expr\Variable
+ || $node instanceof Node\Name
+ || $node instanceof Expr\ArrayDimFetch
+ || $node instanceof Expr\PropertyFetch
+ || $node instanceof Expr\StaticPropertyFetch
+ || $node instanceof Expr\FuncCall
+ || $node instanceof Expr\MethodCall
+ || $node instanceof Expr\StaticCall
+ || $node instanceof Expr\Array_
+ || $node instanceof Scalar\String_
+ || $node instanceof Expr\ConstFetch
+ || $node instanceof Expr\ClassConstFetch);
+ }
+
+ /**
+ * Print modifiers, including trailing whitespace.
+ *
+ * @param int $modifiers Modifier mask to print
+ *
+ * @return string Printed modifiers
+ */
+ protected function pModifiers(int $modifiers) {
+ return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '')
+ . ($modifiers & Stmt\Class_::MODIFIER_PROTECTED ? 'protected ' : '')
+ . ($modifiers & Stmt\Class_::MODIFIER_PRIVATE ? 'private ' : '')
+ . ($modifiers & Stmt\Class_::MODIFIER_STATIC ? 'static ' : '')
+ . ($modifiers & Stmt\Class_::MODIFIER_ABSTRACT ? 'abstract ' : '')
+ . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : '');
+ }
+
+ /**
+ * Determine whether a list of nodes uses multiline formatting.
+ *
+ * @param (Node|null)[] $nodes Node list
+ *
+ * @return bool Whether multiline formatting is used
+ */
+ protected function isMultiline(array $nodes) : bool {
+ if (\count($nodes) < 2) {
+ return false;
+ }
+
+ $pos = -1;
+ foreach ($nodes as $node) {
+ if (null === $node) {
+ continue;
+ }
+
+ $endPos = $node->getEndTokenPos() + 1;
+ if ($pos >= 0) {
+ $text = $this->origTokens->getTokenCode($pos, $endPos, 0);
+ if (false === strpos($text, "\n")) {
+ // We require that a newline is present between *every* item. If the formatting
+ // is inconsistent, with only some items having newlines, we don't consider it
+ // as multiline
+ return false;
+ }
+ }
+ $pos = $endPos;
+ }
+
+ return true;
+ }
+
+ /**
+ * Lazily initializes label char map.
+ *
+ * The label char map determines whether a certain character may occur in a label.
+ */
+ protected function initializeLabelCharMap() {
+ if ($this->labelCharMap) return;
+
+ $this->labelCharMap = [];
+ for ($i = 0; $i < 256; $i++) {
+ // Since PHP 7.1 The lower range is 0x80. However, we also want to support code for
+ // older versions.
+ $this->labelCharMap[chr($i)] = $i >= 0x7f || ctype_alnum($i);
+ }
+ }
+
+ /**
+ * Lazily initializes node list differ.
+ *
+ * The node list differ is used to determine differences between two array subnodes.
+ */
+ protected function initializeNodeListDiffer() {
+ if ($this->nodeListDiffer) return;
+
+ $this->nodeListDiffer = new Internal\Differ(function ($a, $b) {
+ if ($a instanceof Node && $b instanceof Node) {
+ return $a === $b->getAttribute('origNode');
+ }
+ // Can happen for array destructuring
+ return $a === null && $b === null;
+ });
+ }
+
+ /**
+ * Lazily initializes fixup map.
+ *
+ * The fixup map is used to determine whether a certain subnode of a certain node may require
+ * some kind of "fixup" operation, e.g. the addition of parenthesis or braces.
+ */
+ protected function initializeFixupMap() {
+ if ($this->fixupMap) return;
+
+ $this->fixupMap = [
+ Expr\PreInc::class => ['var' => self::FIXUP_PREC_RIGHT],
+ Expr\PreDec::class => ['var' => self::FIXUP_PREC_RIGHT],
+ Expr\PostInc::class => ['var' => self::FIXUP_PREC_LEFT],
+ Expr\PostDec::class => ['var' => self::FIXUP_PREC_LEFT],
+ Expr\Instanceof_::class => [
+ 'expr' => self::FIXUP_PREC_LEFT,
+ 'class' => self::FIXUP_PREC_RIGHT,
+ ],
+ Expr\Ternary::class => [
+ 'cond' => self::FIXUP_PREC_LEFT,
+ 'else' => self::FIXUP_PREC_RIGHT,
+ ],
+
+ Expr\FuncCall::class => ['name' => self::FIXUP_CALL_LHS],
+ Expr\StaticCall::class => ['class' => self::FIXUP_DEREF_LHS],
+ Expr\ArrayDimFetch::class => ['var' => self::FIXUP_DEREF_LHS],
+ Expr\MethodCall::class => [
+ 'var' => self::FIXUP_DEREF_LHS,
+ 'name' => self::FIXUP_BRACED_NAME,
+ ],
+ Expr\StaticPropertyFetch::class => [
+ 'class' => self::FIXUP_DEREF_LHS,
+ 'name' => self::FIXUP_VAR_BRACED_NAME,
+ ],
+ Expr\PropertyFetch::class => [
+ 'var' => self::FIXUP_DEREF_LHS,
+ 'name' => self::FIXUP_BRACED_NAME,
+ ],
+ Scalar\Encapsed::class => [
+ 'parts' => self::FIXUP_ENCAPSED,
+ ],
+ ];
+
+ $binaryOps = [
+ BinaryOp\Pow::class, BinaryOp\Mul::class, BinaryOp\Div::class, BinaryOp\Mod::class,
+ BinaryOp\Plus::class, BinaryOp\Minus::class, BinaryOp\Concat::class,
+ BinaryOp\ShiftLeft::class, BinaryOp\ShiftRight::class, BinaryOp\Smaller::class,
+ BinaryOp\SmallerOrEqual::class, BinaryOp\Greater::class, BinaryOp\GreaterOrEqual::class,
+ BinaryOp\Equal::class, BinaryOp\NotEqual::class, BinaryOp\Identical::class,
+ BinaryOp\NotIdentical::class, BinaryOp\Spaceship::class, BinaryOp\BitwiseAnd::class,
+ BinaryOp\BitwiseXor::class, BinaryOp\BitwiseOr::class, BinaryOp\BooleanAnd::class,
+ BinaryOp\BooleanOr::class, BinaryOp\Coalesce::class, BinaryOp\LogicalAnd::class,
+ BinaryOp\LogicalXor::class, BinaryOp\LogicalOr::class,
+ ];
+ foreach ($binaryOps as $binaryOp) {
+ $this->fixupMap[$binaryOp] = [
+ 'left' => self::FIXUP_PREC_LEFT,
+ 'right' => self::FIXUP_PREC_RIGHT
+ ];
+ }
+
+ $assignOps = [
+ Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class,
+ AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class,
+ AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class,
+ AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class,
+ ];
+ foreach ($assignOps as $assignOp) {
+ $this->fixupMap[$assignOp] = [
+ 'var' => self::FIXUP_PREC_LEFT,
+ 'expr' => self::FIXUP_PREC_RIGHT,
+ ];
+ }
+
+ $prefixOps = [
+ Expr\BitwiseNot::class, Expr\BooleanNot::class, Expr\UnaryPlus::class, Expr\UnaryMinus::class,
+ Cast\Int_::class, Cast\Double::class, Cast\String_::class, Cast\Array_::class,
+ Cast\Object_::class, Cast\Bool_::class, Cast\Unset_::class, Expr\ErrorSuppress::class,
+ Expr\YieldFrom::class, Expr\Print_::class, Expr\Include_::class,
+ ];
+ foreach ($prefixOps as $prefixOp) {
+ $this->fixupMap[$prefixOp] = ['expr' => self::FIXUP_PREC_RIGHT];
+ }
+ }
+
+ /**
+ * Lazily initializes the removal map.
+ *
+ * The removal map is used to determine which additional tokens should be returned when a
+ * certain node is replaced by null.
+ */
+ protected function initializeRemovalMap() {
+ if ($this->removalMap) return;
+
+ $stripBoth = ['left' => \T_WHITESPACE, 'right' => \T_WHITESPACE];
+ $stripLeft = ['left' => \T_WHITESPACE];
+ $stripRight = ['right' => \T_WHITESPACE];
+ $stripDoubleArrow = ['right' => \T_DOUBLE_ARROW];
+ $stripColon = ['left' => ':'];
+ $stripEquals = ['left' => '='];
+ $this->removalMap = [
+ 'Expr_ArrayDimFetch->dim' => $stripBoth,
+ 'Expr_ArrayItem->key' => $stripDoubleArrow,
+ 'Expr_Closure->returnType' => $stripColon,
+ 'Expr_Exit->expr' => $stripBoth,
+ 'Expr_Ternary->if' => $stripBoth,
+ 'Expr_Yield->key' => $stripDoubleArrow,
+ 'Expr_Yield->value' => $stripBoth,
+ 'Param->type' => $stripRight,
+ 'Param->default' => $stripEquals,
+ 'Stmt_Break->num' => $stripBoth,
+ 'Stmt_ClassMethod->returnType' => $stripColon,
+ 'Stmt_Class->extends' => ['left' => \T_EXTENDS],
+ 'Expr_PrintableNewAnonClass->extends' => ['left' => \T_EXTENDS],
+ 'Stmt_Continue->num' => $stripBoth,
+ 'Stmt_Foreach->keyVar' => $stripDoubleArrow,
+ 'Stmt_Function->returnType' => $stripColon,
+ 'Stmt_If->else' => $stripLeft,
+ 'Stmt_Namespace->name' => $stripLeft,
+ 'Stmt_PropertyProperty->default' => $stripEquals,
+ 'Stmt_Return->expr' => $stripBoth,
+ 'Stmt_StaticVar->default' => $stripEquals,
+ 'Stmt_TraitUseAdaptation_Alias->newName' => $stripLeft,
+ 'Stmt_TryCatch->finally' => $stripLeft,
+ // 'Stmt_Case->cond': Replace with "default"
+ // 'Stmt_Class->name': Unclear what to do
+ // 'Stmt_Declare->stmts': Not a plain node
+ // 'Stmt_TraitUseAdaptation_Alias->newModifier': Not a plain node
+ ];
+ }
+
+ protected function initializeInsertionMap() {
+ if ($this->insertionMap) return;
+
+ // TODO: "yield" where both key and value are inserted doesn't work
+ $this->insertionMap = [
+ 'Expr_ArrayDimFetch->dim' => ['[', null, null],
+ 'Expr_ArrayItem->key' => [null, null, ' => '],
+ 'Expr_Closure->returnType' => [')', ' : ', null],
+ 'Expr_Ternary->if' => ['?', ' ', ' '],
+ 'Expr_Yield->key' => [\T_YIELD, null, ' => '],
+ 'Expr_Yield->value' => [\T_YIELD, ' ', null],
+ 'Param->type' => [null, null, ' '],
+ 'Param->default' => [null, ' = ', null],
+ 'Stmt_Break->num' => [\T_BREAK, ' ', null],
+ 'Stmt_ClassMethod->returnType' => [')', ' : ', null],
+ 'Stmt_Class->extends' => [null, ' extends ', null],
+ 'Expr_PrintableNewAnonClass->extends' => [null, ' extends ', null],
+ 'Stmt_Continue->num' => [\T_CONTINUE, ' ', null],
+ 'Stmt_Foreach->keyVar' => [\T_AS, null, ' => '],
+ 'Stmt_Function->returnType' => [')', ' : ', null],
+ 'Stmt_If->else' => [null, ' ', null],
+ 'Stmt_Namespace->name' => [\T_NAMESPACE, ' ', null],
+ 'Stmt_PropertyProperty->default' => [null, ' = ', null],
+ 'Stmt_Return->expr' => [\T_RETURN, ' ', null],
+ 'Stmt_StaticVar->default' => [null, ' = ', null],
+ //'Stmt_TraitUseAdaptation_Alias->newName' => [T_AS, ' ', null], // TODO
+ 'Stmt_TryCatch->finally' => [null, ' ', null],
+
+ // 'Expr_Exit->expr': Complicated due to optional ()
+ // 'Stmt_Case->cond': Conversion from default to case
+ // 'Stmt_Class->name': Unclear
+ // 'Stmt_Declare->stmts': Not a proper node
+ // 'Stmt_TraitUseAdaptation_Alias->newModifier': Not a proper node
+ ];
+ }
+
+ protected function initializeListInsertionMap() {
+ if ($this->listInsertionMap) return;
+
+ $this->listInsertionMap = [
+ // special
+ //'Expr_ShellExec->parts' => '', // TODO These need to be treated more carefully
+ //'Scalar_Encapsed->parts' => '',
+ 'Stmt_Catch->types' => '|',
+ 'Stmt_If->elseifs' => ' ',
+ 'Stmt_TryCatch->catches' => ' ',
+
+ // comma-separated lists
+ 'Expr_Array->items' => ', ',
+ 'Expr_Closure->params' => ', ',
+ 'Expr_Closure->uses' => ', ',
+ 'Expr_FuncCall->args' => ', ',
+ 'Expr_Isset->vars' => ', ',
+ 'Expr_List->items' => ', ',
+ 'Expr_MethodCall->args' => ', ',
+ 'Expr_New->args' => ', ',
+ 'Expr_PrintableNewAnonClass->args' => ', ',
+ 'Expr_StaticCall->args' => ', ',
+ 'Stmt_ClassConst->consts' => ', ',
+ 'Stmt_ClassMethod->params' => ', ',
+ 'Stmt_Class->implements' => ', ',
+ 'Expr_PrintableNewAnonClass->implements' => ', ',
+ 'Stmt_Const->consts' => ', ',
+ 'Stmt_Declare->declares' => ', ',
+ 'Stmt_Echo->exprs' => ', ',
+ 'Stmt_For->init' => ', ',
+ 'Stmt_For->cond' => ', ',
+ 'Stmt_For->loop' => ', ',
+ 'Stmt_Function->params' => ', ',
+ 'Stmt_Global->vars' => ', ',
+ 'Stmt_GroupUse->uses' => ', ',
+ 'Stmt_Interface->extends' => ', ',
+ 'Stmt_Property->props' => ', ',
+ 'Stmt_StaticVar->vars' => ', ',
+ 'Stmt_TraitUse->traits' => ', ',
+ 'Stmt_TraitUseAdaptation_Precedence->insteadof' => ', ',
+ 'Stmt_Unset->vars' => ', ',
+ 'Stmt_Use->uses' => ', ',
+
+ // statement lists
+ 'Expr_Closure->stmts' => "\n",
+ 'Stmt_Case->stmts' => "\n",
+ 'Stmt_Catch->stmts' => "\n",
+ 'Stmt_Class->stmts' => "\n",
+ 'Expr_PrintableNewAnonClass->stmts' => "\n",
+ 'Stmt_Interface->stmts' => "\n",
+ 'Stmt_Trait->stmts' => "\n",
+ 'Stmt_ClassMethod->stmts' => "\n",
+ 'Stmt_Declare->stmts' => "\n",
+ 'Stmt_Do->stmts' => "\n",
+ 'Stmt_ElseIf->stmts' => "\n",
+ 'Stmt_Else->stmts' => "\n",
+ 'Stmt_Finally->stmts' => "\n",
+ 'Stmt_Foreach->stmts' => "\n",
+ 'Stmt_For->stmts' => "\n",
+ 'Stmt_Function->stmts' => "\n",
+ 'Stmt_If->stmts' => "\n",
+ 'Stmt_Namespace->stmts' => "\n",
+ 'Stmt_Switch->cases' => "\n",
+ 'Stmt_TraitUse->adaptations' => "\n",
+ 'Stmt_TryCatch->stmts' => "\n",
+ 'Stmt_While->stmts' => "\n",
+ ];
+ }
+
+ protected function initializeModifierChangeMap() {
+ if ($this->modifierChangeMap) return;
+
+ $this->modifierChangeMap = [
+ 'Stmt_ClassConst->flags' => \T_CONST,
+ 'Stmt_ClassMethod->flags' => \T_FUNCTION,
+ 'Stmt_Class->flags' => \T_CLASS,
+ 'Stmt_Property->flags' => \T_VARIABLE,
+ //'Stmt_TraitUseAdaptation_Alias->newModifier' => 0, // TODO
+ ];
+
+ // List of integer subnodes that are not modifiers:
+ // Expr_Include->type
+ // Stmt_GroupUse->type
+ // Stmt_Use->type
+ // Stmt_UseUse->type