Example #1
0
 /**
  * Parses a class/interface/trait body.
  *
  * @param PHP_Depend_Code_AbstractType $type Context class, trait or interface
  *
  * @return PHP_Depend_Code_AbstractType
  */
 private function _parseTypeBody(PHP_Depend_Code_AbstractType $type)
 {
     $this->_classOrInterface = $type;
     // Consume comments and read opening curly brace
     $this->consumeComments();
     $this->consumeToken(self::T_CURLY_BRACE_OPEN);
     $defaultModifier = self::IS_PUBLIC;
     if ($type instanceof PHP_Depend_Code_Interface) {
         $defaultModifier |= self::IS_ABSTRACT;
     }
     $this->reset();
     $tokenType = $this->tokenizer->peek();
     while ($tokenType !== self::T_EOF) {
         switch ($tokenType) {
             case self::T_ABSTRACT:
             case self::T_PUBLIC:
             case self::T_PRIVATE:
             case self::T_PROTECTED:
             case self::T_STATIC:
             case self::T_FINAL:
             case self::T_FUNCTION:
             case self::T_VARIABLE:
             case self::T_VAR:
                 $methodOrProperty = $this->_parseMethodOrFieldDeclaration($defaultModifier);
                 if ($methodOrProperty instanceof PHP_Depend_Code_ASTNode) {
                     $type->addChild($methodOrProperty);
                 }
                 $this->reset();
                 break;
             case self::T_CONST:
                 $type->addChild($this->_parseConstantDefinition());
                 $this->reset();
                 break;
             case self::T_CURLY_BRACE_CLOSE:
                 $this->consumeToken(self::T_CURLY_BRACE_CLOSE);
                 $this->reset();
                 // Reset context class or interface instance
                 $this->_classOrInterface = null;
                 // Stop processing
                 return $type;
             case self::T_COMMENT:
                 $token = $this->consumeToken(self::T_COMMENT);
                 $comment = $this->builder->buildASTComment($token->image);
                 $comment->configureLinesAndColumns($token->startLine, $token->endLine, $token->startColumn, $token->endColumn);
                 $type->addChild($comment);
                 break;
             case self::T_DOC_COMMENT:
                 $token = $this->consumeToken(self::T_DOC_COMMENT);
                 $comment = $this->builder->buildASTComment($token->image);
                 $comment->configureLinesAndColumns($token->startLine, $token->endLine, $token->startColumn, $token->endColumn);
                 $type->addChild($comment);
                 $this->_docComment = $token->image;
                 break;
             case self::T_USE:
                 $type->addChild($this->_parseTraitUseStatement());
                 break;
             default:
                 throw new PHP_Depend_Parser_UnexpectedTokenException($this->tokenizer->next(), $this->tokenizer->getSourceFile());
         }
         $tokenType = $this->tokenizer->peek();
     }
     throw new PHP_Depend_Parser_TokenStreamEndException($this->tokenizer);
 }