addChild() public method

Adds a source item that was parsed from this source file.
Since: 0.10.0
public addChild ( PDepend\Source\AST\AbstractASTArtifact $artifact ) : void
$artifact PDepend\Source\AST\AbstractASTArtifact
return void
Example #1
0
 /**
  * Parses an optional statement or returns <b>null</b>.
  *
  * @return \PDepend\Source\AST\ASTNode
  * @since  0.9.8
  */
 private function parseOptionalStatement()
 {
     $tokenType = $this->tokenizer->peek();
     switch ($tokenType) {
         case Tokens::T_ECHO:
             return $this->parseEchoStatement();
         case Tokens::T_SWITCH:
             return $this->parseSwitchStatement();
         case Tokens::T_TRY:
             return $this->parseTryStatement();
         case Tokens::T_THROW:
             return $this->parseThrowStatement();
         case Tokens::T_IF:
             return $this->parseIfStatement();
         case Tokens::T_FOR:
             return $this->parseForStatement();
         case Tokens::T_FOREACH:
             return $this->parseForeachStatement();
         case Tokens::T_DO:
             return $this->parseDoWhileStatement();
         case Tokens::T_WHILE:
             return $this->parseWhileStatement();
         case Tokens::T_RETURN:
             return $this->parseReturnStatement();
         case Tokens::T_BREAK:
             return $this->parseBreakStatement();
         case Tokens::T_CONTINUE:
             return $this->parseContinueStatement();
         case Tokens::T_GOTO:
             return $this->parseGotoStatement();
         case Tokens::T_GLOBAL:
             return $this->parseGlobalStatement();
         case Tokens::T_UNSET:
             return $this->parseUnsetStatement();
         case Tokens::T_STRING:
             if ($this->tokenizer->peekNext() === Tokens::T_COLON) {
                 return $this->parseLabelStatement();
             }
             break;
         case Tokens::T_CONST:
             return $this->parseConstantDefinition();
         case Tokens::T_FUNCTION:
             return $this->parseFunctionOrClosureDeclaration();
         case Tokens::T_COMMENT:
             return $this->parseCommentWithOptionalInlineClassOrInterfaceReference();
         case Tokens::T_DOC_COMMENT:
             return $this->builder->buildAstComment($this->consumeToken(Tokens::T_DOC_COMMENT)->image);
         case Tokens::T_CURLY_BRACE_OPEN:
             return $this->parseRegularScope();
         case Tokens::T_DECLARE:
             return $this->parseDeclareStatement();
         case Tokens::T_ELSE:
         case Tokens::T_ENDIF:
         case Tokens::T_ELSEIF:
         case Tokens::T_ENDFOR:
         case Tokens::T_ENDWHILE:
         case Tokens::T_ENDSWITCH:
         case Tokens::T_ENDDECLARE:
         case Tokens::T_ENDFOREACH:
         case Tokens::T_CURLY_BRACE_CLOSE:
             return null;
         case Tokens::T_DECLARE:
             return $this->parseDeclareStatement();
         case Tokens::T_CLOSE_TAG:
             if (($tokenType = $this->parseNonePhpCode()) === Tokenizer::T_EOF) {
                 return null;
             }
             return $this->parseOptionalStatement();
         case Tokens::T_TRAIT:
             $package = $this->getNamespaceOrPackage();
             $package->addType($trait = $this->parseTraitDeclaration());
             $this->builder->restoreTrait($trait);
             $this->compilationUnit->addChild($trait);
             return $trait;
         case Tokens::T_INTERFACE:
             $package = $this->getNamespaceOrPackage();
             $package->addType($interface = $this->parseInterfaceDeclaration());
             $this->builder->restoreInterface($interface);
             $this->compilationUnit->addChild($interface);
             return $interface;
         case Tokens::T_CLASS:
         case Tokens::T_FINAL:
         case Tokens::T_ABSTRACT:
             $package = $this->getNamespaceOrPackage();
             $package->addType($class = $this->parseClassDeclaration());
             $this->builder->restoreClass($class);
             $this->compilationUnit->addChild($class);
             return $class;
         case Tokens::T_YIELD:
             return $this->parseYield();
     }
     $this->tokenStack->push();
     $stmt = $this->builder->buildAstStatement();
     if (($expr = $this->parseOptionalExpression()) != null) {
         $stmt->addChild($expr);
     }
     $this->parseStatementTermination();
     return $this->setNodePositionsAndReturn($stmt);
 }
 /**
  * testMagicWakeupMethodInvokesSetSourceFileOnChildNodes
  *
  * @return void
  */
 public function testMagicWakeupMethodInvokesSetSourceFileOnChildNodes()
 {
     $node = $this->getMock('PDepend\\Source\\AST\\ASTClass', array('setCompilationUnit'), array(__CLASS__));
     $node->expects($this->once())->method('setCompilationUnit')->with(self::isInstanceOf('PDepend\\Source\\AST\\ASTCompilationUnit'));
     $compilationUnit = new ASTCompilationUnit(__FILE__);
     $compilationUnit->addChild($node);
     $compilationUnit->__wakeup();
 }