/**
* Parses a class/interface/trait body.
*
* @param \PDepend\Source\AST\AbstractASTType $type
* @return \PDepend\Source\AST\AbstractASTType
* @throws \PDepend\Source\Parser\UnexpectedTokenException
* @throws \PDepend\Source\Parser\TokenStreamEndException
*/
private function parseTypeBody(AbstractASTType $type)
{
$this->classOrInterface = $type;
// Consume comments and read opening curly brace
$this->consumeComments();
$this->consumeToken(Tokens::T_CURLY_BRACE_OPEN);
$defaultModifier = State::IS_PUBLIC;
if ($type instanceof ASTInterface) {
$defaultModifier |= State::IS_ABSTRACT;
}
$this->reset();
$tokenType = $this->tokenizer->peek();
while ($tokenType !== Tokenizer::T_EOF) {
switch ($tokenType) {
case Tokens::T_ABSTRACT:
case Tokens::T_PUBLIC:
case Tokens::T_PRIVATE:
case Tokens::T_PROTECTED:
case Tokens::T_STATIC:
case Tokens::T_FINAL:
case Tokens::T_FUNCTION:
case Tokens::T_VARIABLE:
case Tokens::T_VAR:
$methodOrProperty = $this->parseMethodOrFieldDeclaration($defaultModifier);
if ($methodOrProperty instanceof \PDepend\Source\AST\ASTNode) {
$type->addChild($methodOrProperty);
}
$this->reset();
break;
case Tokens::T_CONST:
$type->addChild($this->parseConstantDefinition());
$this->reset();
break;
case Tokens::T_CURLY_BRACE_CLOSE:
$this->consumeToken(Tokens::T_CURLY_BRACE_CLOSE);
$this->reset();
// Reset context class or interface instance
$this->classOrInterface = null;
// Stop processing
return $type;
case Tokens::T_COMMENT:
$token = $this->consumeToken(Tokens::T_COMMENT);
$comment = $this->builder->buildAstComment($token->image);
$comment->configureLinesAndColumns($token->startLine, $token->endLine, $token->startColumn, $token->endColumn);
$type->addChild($comment);
break;
case Tokens::T_DOC_COMMENT:
$token = $this->consumeToken(Tokens::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 Tokens::T_USE:
$type->addChild($this->parseTraitUseStatement());
break;
default:
throw new UnexpectedTokenException($this->tokenizer->next(), $this->tokenizer->getSourceFile());
}
$tokenType = $this->tokenizer->peek();
}
throw new TokenStreamEndException($this->tokenizer);
}