diff --git a/src/main/php/PHP/Depend/Builder/Default.php b/src/main/php/PHP/Depend/Builder/Default.php index f672fa24e..74c278dad 100644 --- a/src/main/php/PHP/Depend/Builder/Default.php +++ b/src/main/php/PHP/Depend/Builder/Default.php @@ -1234,6 +1234,17 @@ public function buildASTTypeArray() return $this->_buildASTNodeInstance('ASTTypeArray'); } + /** + * Builds a new node for the callable type. + * + * @return PHP_Depend_Code_ASTTypeCallable + * @since 0.11.0 + */ + public function buildASTTypeCallable() + { + return $this->_buildASTNodeInstance('ASTTypeCallable'); + } + /** * Builds a new primitive type node. * diff --git a/src/main/php/PHP/Depend/BuilderI.php b/src/main/php/PHP/Depend/BuilderI.php index ed1f2e1de..532b96959 100644 --- a/src/main/php/PHP/Depend/BuilderI.php +++ b/src/main/php/PHP/Depend/BuilderI.php @@ -810,6 +810,14 @@ function buildASTArguments(); */ function buildASTTypeArray(); + /** + * Builds a new node for the callable type. + * + * @return PHP_Depend_Code_ASTTypeCallable + * @since 0.11.0 + */ + function buildASTTypeCallable(); + /** * Builds a new primitive type node. * diff --git a/src/main/php/PHP/Depend/Code/ASTTypeCallable.php b/src/main/php/PHP/Depend/Code/ASTTypeCallable.php new file mode 100644 index 000000000..3a7997f88 --- /dev/null +++ b/src/main/php/PHP/Depend/Code/ASTTypeCallable.php @@ -0,0 +1,88 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Manuel Pichler nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category PHP + * @package PHP_Depend + * @subpackage Code + * @author Manuel Pichler + * @copyright 2008-2011 Manuel Pichler. All rights reserved. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://www.pdepend.org/ + * @since 0.11.0 + */ + +/** + * This class represents a callable type node. + * + * @category PHP + * @package PHP_Depend + * @subpackage Code + * @author Manuel Pichler + * @copyright 2008-2011 Manuel Pichler. All rights reserved. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://www.pdepend.org/ + * @since 0.11.0 + */ +class PHP_Depend_Code_ASTTypeCallable extends PHP_Depend_Code_ASTType +{ + /** + * The type of this node. + */ + const CLAZZ = __CLASS__; + + /** + * The visual image for this node type. + */ + const IMAGE = 'callable'; + + /** + * Accept method of the visitor design pattern. This method will be called + * by a visitor during tree traversal. + * + * @param PHP_Depend_Code_ASTVisitorI $visitor The calling visitor instance. + * @param mixed $data Optional previous calculated data. + * + * @return mixed + */ + public function accept( PHP_Depend_Code_ASTVisitorI $visitor, $data = null ) + { + return $visitor->visitTypeCallable($this, $data); + } +} diff --git a/src/main/php/PHP/Depend/ConstantsI.php b/src/main/php/PHP/Depend/ConstantsI.php index b1a279deb..5af87081e 100644 --- a/src/main/php/PHP/Depend/ConstantsI.php +++ b/src/main/php/PHP/Depend/ConstantsI.php @@ -873,6 +873,11 @@ interface PHP_Depend_ConstantsI */ const T_ENDDECLARE = 153; + /** + * Token that represents the new Callable type hint. + */ + const T_CALLABLE = 154; + /** * Marks any content not between php tags. */ diff --git a/src/main/php/PHP/Depend/Parser.php b/src/main/php/PHP/Depend/Parser.php index b1df34534..325901483 100644 --- a/src/main/php/PHP/Depend/Parser.php +++ b/src/main/php/PHP/Depend/Parser.php @@ -160,7 +160,7 @@ abstract class PHP_Depend_Parser implements PHP_Depend_ConstantsI * * @var PHP_Depend_BuilderI */ - private $_builder; + protected $builder; /** * The currently parsed file instance. @@ -255,7 +255,7 @@ public function __construct( PHP_Depend_Util_Cache_Driver $cache ) { $this->tokenizer = $tokenizer; - $this->_builder = $builder; + $this->builder = $builder; $this->cache = $cache; $this->_uuidBuilder = new PHP_Depend_Util_UuidBuilder(); @@ -263,7 +263,7 @@ public function __construct( $this->_useSymbolTable = new PHP_Depend_Parser_SymbolTable(); - $this->_builder->setCache($this->cache); + $this->builder->setCache($this->cache); } /** @@ -490,7 +490,7 @@ private function _parseInterfaceSignature() $qualifiedName = $this->_createQualifiedTypeName($this->parseClassName()); - $interface = $this->_builder->buildInterface($qualifiedName); + $interface = $this->builder->buildInterface($qualifiedName); $interface->setSourceFile($this->_sourceFile); $interface->setDocComment($this->_docComment); $interface->setUUID($this->_uuidBuilder->forClassOrInterface($interface)); @@ -555,7 +555,7 @@ private function _parseClassSignature() $qualifiedName = $this->_createQualifiedTypeName($this->parseClassName()); - $class = $this->_builder->buildClass($qualifiedName); + $class = $this->builder->buildClass($qualifiedName); $class->setSourceFile($this->_sourceFile); $class->setModifiers($this->_modifiers); $class->setDocComment($this->_docComment); @@ -617,8 +617,8 @@ private function _parseClassExtends(PHP_Depend_Code_Class $class) $class->setParentClassReference( $this->_setNodePositionsAndReturn( - $this->_builder->buildASTClassReference( - $this->_parseQualifiedName() + $this->builder->buildASTClassReference( + $this->parseQualifiedName() ) ) ); @@ -645,8 +645,8 @@ private function _parseInterfaceList( $abstractType->addInterfaceReference( $this->_setNodePositionsAndReturn( - $this->_builder->buildASTClassOrInterfaceReference( - $this->_parseQualifiedName() + $this->builder->buildASTClassOrInterfaceReference( + $this->parseQualifiedName() ) ) ); @@ -730,7 +730,7 @@ private function _parseClassOrInterfaceBody( case self::T_COMMENT: $token = $this->consumeToken(self::T_COMMENT); - $comment = $this->_builder->buildASTComment($token->image); + $comment = $this->builder->buildASTComment($token->image); $comment->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -745,7 +745,7 @@ private function _parseClassOrInterfaceBody( case self::T_DOC_COMMENT: $token = $this->consumeToken(self::T_DOC_COMMENT); - $comment = $this->_builder->buildASTComment($token->image); + $comment = $this->builder->buildASTComment($token->image); $comment->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -867,7 +867,7 @@ private function _parseMethodOrFieldDeclaration($modifiers = 0) */ private function _parseFieldDeclaration() { - $declaration = $this->_builder->buildASTFieldDeclaration(); + $declaration = $this->builder->buildASTFieldDeclaration(); $declaration->setComment($this->_docComment); $type = $this->_parseFieldDeclarationType(); @@ -1002,7 +1002,7 @@ private function _parseFunctionDeclaration() // Next token must be the function identifier $functionName = $this->parseFunctionName(); - $function = $this->_builder->buildFunction($functionName); + $function = $this->builder->buildFunction($functionName); $function->setSourceFile($this->_sourceFile); $function->setUUID($this->_uuidBuilder->forFunction($function)); @@ -1017,7 +1017,7 @@ private function _parseFunctionDeclaration() $packageName = $this->_globalPackageName; } - $this->_builder + $this->builder ->buildPackage($packageName) ->addFunction($function); @@ -1045,7 +1045,7 @@ private function _parseMethodDeclaration() $methodName = $this->parseFunctionName(); - $method = $this->_builder->buildMethod($methodName); + $method = $this->builder->buildMethod($methodName); $method->setDocComment($this->_docComment); $method->setSourceFile($this->_sourceFile); @@ -1075,7 +1075,7 @@ private function _parseClosureDeclaration() $this->consumeToken(self::T_FUNCTION); } - $closure = $this->_builder->buildASTClosure(); + $closure = $this->builder->buildASTClosure(); $closure->setReturnsByReference($this->_parseOptionalReturnbyReference()); $closure->addChild($this->_parseFormalParameters()); $closure = $this->_parseOptionalBoundVariables($closure); @@ -1129,7 +1129,7 @@ private function _parseAllocationExpression() $token = $this->consumeToken(self::T_NEW); - $allocation = $this->_builder->buildASTAllocationExpression($token->image); + $allocation = $this->builder->buildASTAllocationExpression($token->image); $allocation = $this->_parseExpressionTypeReference($allocation, true); if ($this->_isNextTokenArguments()) { @@ -1149,7 +1149,7 @@ private function _parseEvalExpression() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_EVAL); - $expr = $this->_builder->buildASTEvalExpression($token->image); + $expr = $this->builder->buildASTEvalExpression($token->image); $expr->addChild($this->_parseParenthesisExpression()); return $this->_setNodePositionsAndReturn($expr); @@ -1166,7 +1166,7 @@ private function _parseExitExpression() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_EXIT); - $expr = $this->_builder->buildASTExitExpression($token->image); + $expr = $this->builder->buildASTExitExpression($token->image); $this->consumeComments(); if ($this->tokenizer->peek() === self::T_PARENTHESIS_OPEN) { @@ -1186,7 +1186,7 @@ private function _parseCloneExpression() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_CLONE); - $expr = $this->_builder->buildASTCloneExpression($token->image); + $expr = $this->builder->buildASTCloneExpression($token->image); // TODO: $expr->addChild($this->_parseExpression()); if (($child = $this->_parseOptionalExpression()) != null) { $expr->addChild($child); @@ -1208,7 +1208,7 @@ private function _parseListExpression() $token = $this->consumeToken(self::T_LIST); $this->consumeComments(); - $list = $this->_builder->buildASTListExpression($token->image); + $list = $this->builder->buildASTListExpression($token->image); $this->consumeToken(self::T_PARENTHESIS_OPEN); $this->consumeComments(); @@ -1248,7 +1248,7 @@ private function _parseListExpression() */ private function _parseIncludeExpression() { - $expr = $this->_builder->buildASTIncludeExpression(); + $expr = $this->builder->buildASTIncludeExpression(); return $this->_parseRequireOrIncludeExpression($expr, self::T_INCLUDE); } @@ -1261,7 +1261,7 @@ private function _parseIncludeExpression() */ private function _parseIncludeOnceExpression() { - $expr = $this->_builder->buildASTIncludeExpression(); + $expr = $this->builder->buildASTIncludeExpression(); $expr->setOnce(); return $this->_parseRequireOrIncludeExpression($expr, self::T_INCLUDE_ONCE); @@ -1275,7 +1275,7 @@ private function _parseIncludeOnceExpression() */ private function _parseRequireExpression() { - $expr = $this->_builder->buildASTRequireExpression(); + $expr = $this->builder->buildASTRequireExpression(); return $this->_parseRequireOrIncludeExpression($expr, self::T_REQUIRE); } @@ -1288,7 +1288,7 @@ private function _parseRequireExpression() */ private function _parseRequireOnceExpression() { - $expr = $this->_builder->buildASTRequireExpression(); + $expr = $this->builder->buildASTRequireExpression(); $expr->setOnce(); return $this->_parseRequireOrIncludeExpression($expr, self::T_REQUIRE_ONCE); @@ -1333,7 +1333,7 @@ private function _parseCastExpression() { $token = $this->consumeToken($this->tokenizer->peek()); - $expr = $this->_builder->buildASTCastExpression($token->image); + $expr = $this->builder->buildASTCastExpression($token->image); $expr->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -1374,7 +1374,7 @@ private function _parsePostIncrementExpression(PHP_Depend_Code_ASTNode $child) { $token = $this->consumeToken(self::T_INC); - $expr = $this->_builder->buildASTPostfixExpression($token->image); + $expr = $this->builder->buildASTPostfixExpression($token->image); $expr->addChild($child); $expr->configureLinesAndColumns( $child->getStartLine(), @@ -1396,7 +1396,7 @@ private function _parsePreIncrementExpression() { $token = $this->consumeToken(self::T_INC); - $expr = $this->_builder->buildASTPreIncrementExpression(); + $expr = $this->builder->buildASTPreIncrementExpression(); $expr->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -1437,7 +1437,7 @@ private function _parsePostDecrementExpression(PHP_Depend_Code_ASTNode $child) { $token = $this->consumeToken(self::T_DEC); - $expr = $this->_builder->buildASTPostfixExpression($token->image); + $expr = $this->builder->buildASTPostfixExpression($token->image); $expr->addChild($child); $expr->configureLinesAndColumns( $child->getStartLine(), @@ -1459,7 +1459,7 @@ private function _parsePreDecrementExpression() { $token = $this->consumeToken(self::T_DEC); - $expr = $this->_builder->buildASTPreDecrementExpression(); + $expr = $this->builder->buildASTPreDecrementExpression(); $expr->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -1560,7 +1560,7 @@ private function _parseIndexExpression( */ private function _parseArrayIndexExpression(PHP_Depend_Code_ASTNode $node) { - $expr = $this->_builder->buildASTArrayIndexExpression(); + $expr = $this->builder->buildASTArrayIndexExpression(); $expr->addChild($node); return $this->_parseIndexExpression( @@ -1587,7 +1587,7 @@ private function _parseArrayIndexExpression(PHP_Depend_Code_ASTNode $node) */ private function _parseStringIndexExpression(PHP_Depend_Code_ASTNode $node) { - $expr = $this->_builder->buildASTStringIndexExpression(); + $expr = $this->builder->buildASTStringIndexExpression(); $expr->addChild($node); return $this->_parseIndexExpression( @@ -1670,7 +1670,7 @@ private function _parseInstanceOfExpression() $token = $this->consumeToken(self::T_INSTANCEOF); return $this->_parseExpressionTypeReference( - $this->_builder->buildASTInstanceOfExpression($token->image), false + $this->builder->buildASTInstanceOfExpression($token->image), false ); } @@ -1698,7 +1698,7 @@ private function _parseIssetExpression() $this->consumeComments(); $this->consumeToken(self::T_PARENTHESIS_OPEN); - $expr = $this->_builder->buildASTIssetExpression(); + $expr = $this->builder->buildASTIssetExpression(); $expr = $this->_parseVariableList($expr); $stopToken = $this->consumeToken(self::T_PARENTHESIS_CLOSE); @@ -1791,7 +1791,7 @@ private function _parseConditionalExpression() $this->_tokenStack->push(); $this->consumeToken(self::T_QUESTION_MARK); - $expr = $this->_builder->buildASTConditionalExpression(); + $expr = $this->builder->buildASTConditionalExpression(); if (($child = $this->_parseOptionalExpression()) != null) { $expr->addChild($child); } @@ -1816,7 +1816,7 @@ private function _parseBooleanAndExpression() { $token = $this->consumeToken(self::T_BOOLEAN_AND); - $expr = $this->_builder->buildASTBooleanAndExpression(); + $expr = $this->builder->buildASTBooleanAndExpression(); $expr->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -1836,7 +1836,7 @@ private function _parseBooleanOrExpression() { $token = $this->consumeToken(self::T_BOOLEAN_OR); - $expr = $this->_builder->buildASTBooleanOrExpression(); + $expr = $this->builder->buildASTBooleanOrExpression(); $expr->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -1856,7 +1856,7 @@ private function _parseLogicalAndExpression() { $token = $this->consumeToken(self::T_LOGICAL_AND); - $expr = $this->_builder->buildASTLogicalAndExpression(); + $expr = $this->builder->buildASTLogicalAndExpression(); $expr->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -1876,7 +1876,7 @@ private function _parseLogicalOrExpression() { $token = $this->consumeToken(self::T_LOGICAL_OR); - $expr = $this->_builder->buildASTLogicalOrExpression(); + $expr = $this->builder->buildASTLogicalOrExpression(); $expr->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -1896,7 +1896,7 @@ private function _parseLogicalXorExpression() { $token = $this->consumeToken(self::T_LOGICAL_XOR); - $expr = $this->_builder->buildASTLogicalXorExpression(); + $expr = $this->builder->buildASTLogicalXorExpression(); $expr->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -1920,14 +1920,14 @@ private function _parseClassOrInterfaceReference($classReference) if ($classReference === true) { return $this->_setNodePositionsAndReturn( - $this->_builder->buildASTClassReference( - $this->_parseQualifiedName() + $this->builder->buildASTClassReference( + $this->parseQualifiedName() ) ); } return $this->_setNodePositionsAndReturn( - $this->_builder->buildASTClassOrInterfaceReference( - $this->_parseQualifiedName() + $this->builder->buildASTClassOrInterfaceReference( + $this->parseQualifiedName() ) ); } @@ -2054,7 +2054,7 @@ private function _parseAlternativeScope() */ private function _parseScopeStatements() { - $scope = $this->_builder->buildASTScopeStatement(); + $scope = $this->builder->buildASTScopeStatement(); while (($child = $this->_parseOptionalStatement()) != null) { if ($child instanceof PHP_Depend_Code_ASTNode) { $scope->addChild($child); @@ -2261,7 +2261,7 @@ private function _parseOptionalExpression() case self::T_CURLY_BRACE_OPEN: $expressions[] = $this->_parseBraceExpression( - $this->_builder->buildASTExpression(), + $this->builder->buildASTExpression(), $this->consumeToken(self::T_CURLY_BRACE_OPEN), self::T_CURLY_BRACE_CLOSE ); @@ -2269,7 +2269,7 @@ private function _parseOptionalExpression() case self::T_SQUARED_BRACKET_OPEN: $expressions[] = $this->_parseBraceExpression( - $this->_builder->buildASTExpression(), + $this->builder->buildASTExpression(), $this->consumeToken(self::T_SQUARED_BRACKET_OPEN), self::T_SQUARED_BRACKET_CLOSE ); @@ -2331,7 +2331,7 @@ private function _parseOptionalExpression() case self::T_MOD: $token = $this->consumeToken($tokenType); - $expr = $this->_builder->buildASTExpression(); + $expr = $this->builder->buildASTExpression(); $expr->setImage($token->image); $expr->setStartLine($token->startLine); $expr->setStartColumn($token->startColumn); @@ -2357,7 +2357,7 @@ private function _parseOptionalExpression() return $expressions[0]; } - $expr = $this->_builder->buildASTExpression(); + $expr = $this->builder->buildASTExpression(); foreach ($expressions as $node) { $expr->addChild($node); } @@ -2422,7 +2422,7 @@ private function _parseSwitchStatement() $this->_tokenStack->push(); $this->consumeToken(self::T_SWITCH); - $switch = $this->_builder->buildASTSwitchStatement(); + $switch = $this->builder->buildASTSwitchStatement(); $switch->addChild($this->_parseParenthesisExpression()); $this->_parseSwitchStatementBody($switch); @@ -2493,7 +2493,7 @@ private function _parseSwitchLabel() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_CASE); - $label = $this->_builder->buildASTSwitchLabel($token->image); + $label = $this->builder->buildASTSwitchLabel($token->image); // TODO: $label->addChild($this->_parseExpression()); if (($expr = $this->_parseOptionalExpression()) != null) { $label->addChild($expr); @@ -2528,7 +2528,7 @@ private function _parseSwitchLabelDefault() $this->consumeToken(self::T_SEMICOLON); } - $label = $this->_builder->buildASTSwitchLabel($token->image); + $label = $this->builder->buildASTSwitchLabel($token->image); $label->setDefault(); $this->_parseSwitchLabelBody($label); @@ -2614,7 +2614,7 @@ private function _parseTryStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_TRY); - $stmt = $this->_builder->buildASTTryStatement($token->image); + $stmt = $this->builder->buildASTTryStatement($token->image); $stmt->addChild($this->_parseRegularScope()); do { @@ -2636,7 +2636,7 @@ private function _parseThrowStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_THROW); - $stmt = $this->_builder->buildASTThrowStatement($token->image); + $stmt = $this->builder->buildASTThrowStatement($token->image); // TODO: $stmt->addChild($this->_parseExpression()); if (($expr = $this->_parseOptionalExpression()) != null) { $stmt->addChild($expr); @@ -2663,7 +2663,7 @@ private function _parseGotoStatement() $this->_parseStatementTermination(); - $stmt = $this->_builder->buildASTGotoStatement($token->image); + $stmt = $this->builder->buildASTGotoStatement($token->image); return $this->_setNodePositionsAndReturn($stmt); } @@ -2682,7 +2682,7 @@ private function _parseLabelStatement() $this->consumeToken(self::T_COLON); return $this->_setNodePositionsAndReturn( - $this->_builder->buildASTLabelStatement($token->image) + $this->builder->buildASTLabelStatement($token->image) ); } @@ -2697,7 +2697,7 @@ private function _parseGlobalStatement() $this->_tokenStack->push(); $this->consumeToken(self::T_GLOBAL); - $stmt = $this->_builder->buildASTGlobalStatement(); + $stmt = $this->builder->buildASTGlobalStatement(); $stmt = $this->_parseVariableList($stmt); $this->_parseStatementTermination(); @@ -2719,7 +2719,7 @@ private function _parseUnsetStatement() $this->consumeComments(); $this->consumeToken(self::T_PARENTHESIS_OPEN); - $stmt = $this->_builder->buildASTUnsetStatement(); + $stmt = $this->builder->buildASTUnsetStatement(); $stmt = $this->_parseVariableList($stmt); $this->consumeToken(self::T_PARENTHESIS_CLOSE); @@ -2742,14 +2742,14 @@ private function _parseCatchStatement() $token = $this->consumeToken(self::T_CATCH); - $catch = $this->_builder->buildASTCatchStatement($token->image); + $catch = $this->builder->buildASTCatchStatement($token->image); $this->consumeComments(); $this->consumeToken(self::T_PARENTHESIS_OPEN); $catch->addChild( - $this->_builder->buildASTClassOrInterfaceReference( - $this->_parseQualifiedName() + $this->builder->buildASTClassOrInterfaceReference( + $this->parseQualifiedName() ) ); @@ -2775,7 +2775,7 @@ private function _parseIfStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_IF); - $stmt = $this->_builder->buildASTIfStatement($token->image); + $stmt = $this->builder->buildASTIfStatement($token->image); $stmt->addChild($this->_parseParenthesisExpression()); $this->_parseStatementBody($stmt); @@ -2795,7 +2795,7 @@ private function _parseElseIfStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_ELSEIF); - $stmt = $this->_builder->buildASTElseIfStatement($token->image); + $stmt = $this->builder->buildASTElseIfStatement($token->image); $stmt->addChild($this->_parseParenthesisExpression()); $this->_parseStatementBody($stmt); @@ -2850,7 +2850,7 @@ private function _parseForStatement() $this->consumeComments(); $this->consumeToken(self::T_PARENTHESIS_OPEN); - $stmt = $this->_builder->buildASTForStatement($token->image); + $stmt = $this->builder->buildASTForStatement($token->image); if (($init = $this->_parseForInit()) !== null) { $stmt->addChild($init); @@ -2885,7 +2885,7 @@ private function _parseForStatement() private function _parseForInit() { if (($expr = $this->_parseOptionalExpression())) { - $init = $this->_builder->buildASTForInit(); + $init = $this->builder->buildASTForInit(); $init->addChild($expr); $init->configureLinesAndColumns( $expr->getStartLine(), @@ -2929,7 +2929,7 @@ private function _parseForUpdate() $update = null; if (($expr = $this->_parseOptionalExpression()) != null) { - $update = $this->_builder->buildASTForUpdate(); + $update = $this->builder->buildASTForUpdate(); $update->addChild($expr); return $this->_setNodePositionsAndReturn($update); @@ -2949,7 +2949,7 @@ private function _parseForeachStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_FOREACH); - $foreach = $this->_builder->buildASTForeachStatement($token->image); + $foreach = $this->builder->buildASTForeachStatement($token->image); $this->consumeComments(); $this->consumeToken(self::T_PARENTHESIS_OPEN); @@ -2994,7 +2994,7 @@ private function _parseWhileStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_WHILE); - $stmt = $this->_builder->buildASTWhileStatement($token->image); + $stmt = $this->builder->buildASTWhileStatement($token->image); $stmt->addChild($this->_parseParenthesisExpression()); return $this->_setNodePositionsAndReturn( @@ -3013,7 +3013,7 @@ private function _parseDoWhileStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_DO); - $stmt = $this->_builder->buildASTDoWhileStatement($token->image); + $stmt = $this->builder->buildASTDoWhileStatement($token->image); $stmt = $this->_parseStatementBody($stmt); $this->consumeComments(); @@ -3055,7 +3055,7 @@ private function _parseDeclareStatement() $this->_tokenStack->push(); $this->consumeToken(self::T_DECLARE); - $stmt = $this->_builder->buildASTDeclareStatement(); + $stmt = $this->builder->buildASTDeclareStatement(); $stmt = $this->_parseDeclareList($stmt); $stmt = $this->_parseStatementBody($stmt); @@ -3112,7 +3112,7 @@ private function _parseReturnStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_RETURN); - $stmt = $this->_builder->buildASTReturnStatement($token->image); + $stmt = $this->builder->buildASTReturnStatement($token->image); if (($expr = $this->_parseOptionalExpression()) != null) { $stmt->addChild($expr); } @@ -3132,7 +3132,7 @@ private function _parseBreakStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_BREAK); - $stmt = $this->_builder->buildASTBreakStatement($token->image); + $stmt = $this->builder->buildASTBreakStatement($token->image); if (($expr = $this->_parseOptionalExpression()) != null) { $stmt->addChild($expr); } @@ -3152,7 +3152,7 @@ private function _parseContinueStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_CONTINUE); - $stmt = $this->_builder->buildASTContinueStatement($token->image); + $stmt = $this->builder->buildASTContinueStatement($token->image); if (($expr = $this->_parseOptionalExpression()) != null) { $stmt->addChild($expr); } @@ -3172,7 +3172,7 @@ private function _parseEchoStatement() $this->_tokenStack->push(); $token = $this->consumeToken(self::T_ECHO); - $stmt = $this->_builder->buildASTEchoStatement($token->image); + $stmt = $this->builder->buildASTEchoStatement($token->image); // TODO: $stmt->addChild($this->_parseExpression()) if (($expr = $this->_parseOptionalExpression()) != null) { $stmt->addChild($expr); @@ -3216,7 +3216,7 @@ private function _parseParenthesisExpression() $this->_tokenStack->push(); $this->consumeComments(); - $expression = $this->_builder->buildASTExpression(); + $expression = $this->builder->buildASTExpression(); $expression = $this->_parseBraceExpression( $expression, $this->consumeToken(self::T_PARENTHESIS_OPEN), @@ -3270,7 +3270,7 @@ private function _parseMemberPrefixOrFunctionPostfix() $this->_tokenStack->push(); $this->_tokenStack->push(); - $qName = $this->_parseQualifiedName(); + $qName = $this->parseQualifiedName(); // Remove comments $this->consumeComments(); @@ -3281,19 +3281,19 @@ private function _parseMemberPrefixOrFunctionPostfix() switch ($tokenType) { case self::T_DOUBLE_COLON: - $node = $this->_builder->buildASTClassOrInterfaceReference($qName); + $node = $this->builder->buildASTClassOrInterfaceReference($qName); $node = $this->_setNodePositionsAndReturn($node); $node = $this->_parseStaticMemberPrimaryPrefix($node); break; case self::T_PARENTHESIS_OPEN: - $node = $this->_builder->buildASTIdentifier($qName); + $node = $this->builder->buildASTIdentifier($qName); $node = $this->_setNodePositionsAndReturn($node); $node = $this->_parseFunctionPostfix($node); break; default: - $node = $this->_builder->buildASTConstant($qName); + $node = $this->builder->buildASTConstant($qName); $node = $this->_setNodePositionsAndReturn($node); break; } @@ -3345,7 +3345,7 @@ private function _parseFunctionPostfix(PHP_Depend_Code_ASTNode $node) { $image = $this->_extractPostfixImage($node); - $function = $this->_builder->buildASTFunctionPostfix($image); + $function = $this->builder->buildASTFunctionPostfix($image); $function->addChild($node); $function->addChild($this->_parseArguments()); @@ -3406,7 +3406,7 @@ private function _parseMemberPrimaryPrefix(PHP_Depend_Code_ASTNode $node) // Consume double colon and optional comments $token = $this->consumeToken(self::T_OBJECT_OPERATOR); - $prefix = $this->_builder->buildASTMemberPrimaryPrefix($token->image); + $prefix = $this->builder->buildASTMemberPrimaryPrefix($token->image); $prefix->addChild($node); $this->consumeComments(); @@ -3479,7 +3479,7 @@ private function _parseStaticMemberPrimaryPrefix(PHP_Depend_Code_ASTNode $node) { $token = $this->consumeToken(self::T_DOUBLE_COLON); - $prefix = $this->_builder->buildASTMemberPrimaryPrefix($token->image); + $prefix = $this->builder->buildASTMemberPrimaryPrefix($token->image); $prefix->addChild($node); $this->consumeComments(); @@ -3526,7 +3526,7 @@ private function _parseMethodOrConstantPostfix() if ($this->tokenizer->peek() === self::T_PARENTHESIS_OPEN) { $postfix = $this->_parseMethodPostfix($node); } else { - $postfix = $this->_builder->buildASTConstantPostfix($node->getImage()); + $postfix = $this->builder->buildASTConstantPostfix($node->getImage()); $postfix->addChild($node); } @@ -3577,7 +3577,7 @@ private function _parsePropertyPostfix(PHP_Depend_Code_ASTNode $node) { $image = $this->_extractPostfixImage($node); - $postfix = $this->_builder->buildASTPropertyPostfix($image); + $postfix = $this->builder->buildASTPropertyPostfix($image); $postfix->addChild($node); $postfix->setEndLine($node->getEndLine()); @@ -3622,7 +3622,7 @@ private function _parseMethodPostfix(PHP_Depend_Code_ASTNode $node) $args = $this->_parseArguments(); $image = $this->_extractPostfixImage($node); - $postfix = $this->_builder->buildASTMethodPostfix($image); + $postfix = $this->builder->buildASTMethodPostfix($image); $postfix->addChild($node); $postfix->addChild($args); @@ -3647,7 +3647,7 @@ private function _parseArguments() $this->consumeComments(); return $this->_parseBraceExpression( - $this->_builder->buildASTArguments(), + $this->builder->buildASTArguments(), $this->consumeToken(self::T_PARENTHESIS_OPEN), self::T_PARENTHESIS_CLOSE ); @@ -3751,7 +3751,7 @@ private function _parseAssignmentExpression(PHP_Depend_Code_ASTNode $left) { $token = $this->consumeToken($this->tokenizer->peek()); - $node = $this->_builder->buildASTAssignmentExpression($token->image); + $node = $this->builder->buildASTAssignmentExpression($token->image); $node->addChild($left); $node->setStartLine($left->getStartLine()); $node->setStartColumn($left->getStartColumn()); @@ -3793,7 +3793,7 @@ private function _parseStaticReference(PHP_Depend_Token $token) ); } - $ref = $this->_builder->buildASTStaticReference($this->_classOrInterface); + $ref = $this->builder->buildASTStaticReference($this->_classOrInterface); $ref->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -3826,7 +3826,7 @@ private function _parseSelfReference(PHP_Depend_Token $token) ); } - $ref = $this->_builder->buildASTSelfReference($this->_classOrInterface); + $ref = $this->builder->buildASTSelfReference($this->_classOrInterface); $ref->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -3862,7 +3862,7 @@ private function _parseConstantOrSelfMemberPrimaryPrefix() $this->_parseSelfReference($token) ); } - return $this->_builder->buildASTConstant($token->image); + return $this->builder->buildASTConstant($token->image); } /** @@ -3901,7 +3901,7 @@ private function _parseParentReference(PHP_Depend_Token $token) ); } - $ref = $this->_builder->buildASTParentReference($classReference); + $ref = $this->builder->buildASTParentReference($classReference); $ref->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -3937,7 +3937,7 @@ private function _parseConstantOrParentMemberPrimaryPrefix() $this->_parseParentReference($token) ); } - return $this->_builder->buildASTConstant($token->image); + return $this->builder->buildASTConstant($token->image); } /** @@ -3990,7 +3990,7 @@ private function _parseVariableOrMemberByReference() $token = $this->consumeToken(self::T_BITWISE_AND); $this->consumeComments(); - $expression = $this->_builder->buildASTUnaryExpression($token->image); + $expression = $this->builder->buildASTUnaryExpression($token->image); $expression->addChild($this->_parseVariableOrConstantOrPrimaryPrefix()); return $this->_setNodePositionsAndReturn($expression); @@ -4008,7 +4008,7 @@ private function _parseVariable() { $token = $this->consumeToken(self::T_VARIABLE); - $variable = $this->_builder->buildASTVariable($token->image); + $variable = $this->builder->buildASTVariable($token->image); $variable->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -4102,12 +4102,12 @@ private function _parseCompoundVariableOrLiteral() switch ($tokenType) { case self::T_CURLY_BRACE_OPEN: - $variable = $this->_builder->buildASTCompoundVariable($token->image); + $variable = $this->builder->buildASTCompoundVariable($token->image); $variable->addChild($this->_parseCompoundExpression()); break; default: - $variable = $this->_builder->buildASTLiteral($token->image); + $variable = $this->builder->buildASTLiteral($token->image); break; } @@ -4146,7 +4146,7 @@ private function _parseCompoundVariableOrVariableVariable() case self::T_DOLLAR: case self::T_VARIABLE: - $variable = $this->_builder->buildASTVariableVariable($token->image); + $variable = $this->builder->buildASTVariableVariable($token->image); $variable->addChild( $this->_parseCompoundVariableOrVariableVariableOrVariable() ); @@ -4177,7 +4177,7 @@ private function _parseCompoundVariableOrVariableVariable() private function _parseCompoundVariable(PHP_Depend_Token $token) { return $this->_parseBraceExpression( - $this->_builder->buildASTCompoundVariable($token->image), + $this->builder->buildASTCompoundVariable($token->image), $this->consumeToken(self::T_CURLY_BRACE_OPEN), self::T_CURLY_BRACE_CLOSE ); @@ -4213,13 +4213,13 @@ private function _parseCompoundExpressionOrLiteral() case self::T_DOLLAR: case self::T_VARIABLE: return $this->_parseBraceExpression( - $this->_builder->buildASTCompoundExpression(), + $this->builder->buildASTCompoundExpression(), $token, self::T_CURLY_BRACE_CLOSE ); } - $literal = $this->_builder->buildASTLiteral($token->image); + $literal = $this->builder->buildASTLiteral($token->image); $literal->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -4251,7 +4251,7 @@ private function _parseCompoundExpression() $this->consumeComments(); return $this->_parseBraceExpression( - $this->_builder->buildASTCompoundExpression(), + $this->builder->buildASTCompoundExpression(), $this->consumeToken(self::T_CURLY_BRACE_OPEN), self::T_CURLY_BRACE_CLOSE ); @@ -4268,7 +4268,7 @@ private function _parseIdentifier() { $token = $this->consumeToken(self::T_STRING); - $node = $this->_builder->buildASTIdentifier($token->image); + $node = $this->builder->buildASTIdentifier($token->image); $node->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -4303,7 +4303,7 @@ private function _parseLiteralOrString() case self::T_CONSTANT_ENCAPSED_STRING: $token = $this->consumeToken($tokenType); - $literal = $this->_builder->buildASTLiteral($token->image); + $literal = $this->builder->buildASTLiteral($token->image); $literal->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -4328,7 +4328,7 @@ private function _parseHeredoc() $this->_tokenStack->push(); $this->consumeToken(self::T_START_HEREDOC); - $heredoc = $this->_builder->buildASTHeredoc(); + $heredoc = $this->builder->buildASTHeredoc(); $this->_parseStringExpressions($heredoc, self::T_END_HEREDOC); $token = $this->consumeToken(self::T_END_HEREDOC); @@ -4385,7 +4385,7 @@ private function _parseString($delimiterType) { $token = $this->consumeToken($delimiterType); - $string = $this->_builder->buildASTString(); + $string = $this->builder->buildASTString(); $string->setStartLine($token->startLine); $string->setStartColumn($token->startColumn); @@ -4475,7 +4475,7 @@ private function _parseEscapedASTLiteralString() } } return $this->_setNodePositionsAndReturn( - $this->_builder->buildASTLiteral($image) + $this->builder->buildASTLiteral($image) ); } @@ -4490,7 +4490,7 @@ private function _parseLiteral() { $token = $this->consumeToken($this->tokenizer->peek()); - $node = $this->_builder->buildASTLiteral($token->image); + $node = $this->builder->buildASTLiteral($token->image); $node->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -4513,7 +4513,7 @@ private function _parseFormalParameters() $this->_tokenStack->push(); - $formalParameters = $this->_builder->buildASTFormalParameters(); + $formalParameters = $this->builder->buildASTFormalParameters(); $this->consumeToken(self::T_PARENTHESIS_OPEN); $this->consumeComments(); @@ -4579,9 +4579,7 @@ private function _parseFormalParameterOrTypeHintOrByReference() $parameter = $this->_parseFormalParameterAndArrayTypeHint(); break; - case self::T_STRING: - case self::T_BACKSLASH: - case self::T_NAMESPACE: + case ($this->isFormalParameterTypeHint($tokenType)): $parameter = $this->_parseFormalParameterAndTypeHint(); break; @@ -4620,7 +4618,7 @@ private function _parseFormalParameterAndArrayTypeHint() { $token = $this->consumeToken(self::T_ARRAY); - $node = $this->_builder->buildASTTypeArray(); + $node = $this->builder->buildASTTypeArray(); $node->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -4628,7 +4626,7 @@ private function _parseFormalParameterAndArrayTypeHint() $token->endColumn ); - $parameter = $this->_parseFormalParameterOrByReference(); + $parameter = $this->parseFormalParameterOrByReference(); $parameter->prependChild($node); return $parameter; @@ -4651,12 +4649,10 @@ private function _parseFormalParameterAndTypeHint() $this->_tokenStack->push(); $classReference = $this->_setNodePositionsAndReturn( - $this->_builder->buildASTClassOrInterfaceReference( - $this->_parseQualifiedName() - ) + $this->parseFormalParameterTypeHint() ); - $parameter = $this->_parseFormalParameterOrByReference(); + $parameter = $this->parseFormalParameterOrByReference(); $parameter->addChild($classReference); return $parameter; @@ -4686,7 +4682,7 @@ private function _parseFormalParameterAndParentTypeHint() $token = $this->consumeToken(self::T_PARENT); $reference = $this->_parseParentReference($token); - $parameter = $this->_parseFormalParameterOrByReference(); + $parameter = $this->parseFormalParameterOrByReference(); $parameter->prependChild($reference); return $parameter; @@ -4712,7 +4708,7 @@ private function _parseFormalParameterAndSelfTypeHint() { $token = $this->consumeToken(self::T_SELF); - $self = $this->_builder->buildASTSelfReference($this->_classOrInterface); + $self = $this->builder->buildASTSelfReference($this->_classOrInterface); $self->configureLinesAndColumns( $token->startLine, $token->endLine, @@ -4720,7 +4716,7 @@ private function _parseFormalParameterAndSelfTypeHint() $token->endColumn ); - $parameter = $this->_parseFormalParameterOrByReference(); + $parameter = $this->parseFormalParameterOrByReference(); $parameter->addChild($self); return $parameter; @@ -4739,7 +4735,7 @@ private function _parseFormalParameterAndSelfTypeHint() * @return PHP_Depend_Code_ASTFormalParameter * @since 0.9.6 */ - private function _parseFormalParameterOrByReference() + protected function parseFormalParameterOrByReference() { $this->consumeComments(); if ($this->tokenizer->peek() === self::T_BITWISE_AND) { @@ -4786,12 +4782,32 @@ private function _parseFormalParameterAndByReference() */ private function _parseFormalParameter() { - $parameter = $this->_builder->buildASTFormalParameter(); + $parameter = $this->builder->buildASTFormalParameter(); $parameter->addChild($this->_parseVariableDeclarator()); return $parameter; } + /** + * Tests if the given token type is a valid formal parameter in the supported + * PHP version. + * + * @param integer $tokenType Numerical token identifier. + * + * @return boolean + * @since 0.11.0 + */ + protected abstract function isFormalParameterTypeHint($tokenType); + + /** + * Parses a formal parameter type hint that is valid in the supported PHP + * version. + * + * @return PHP_Depend_Code_ASTNode + * @since 0.11.0 + */ + protected abstract function parseFormalParameterTypeHint(); + /** * Extracts all dependencies from a callable body. * @@ -4800,7 +4816,7 @@ private function _parseFormalParameter() */ private function _parseScope() { - $scope = $this->_builder->buildASTScope(); + $scope = $this->builder->buildASTScope(); $this->_tokenStack->push(); @@ -4891,7 +4907,7 @@ private function _parseOptionalStatement() return $this->_parseCommentWithOptionalInlineClassOrInterfaceReference(); case self::T_DOC_COMMENT: - return $this->_builder->buildASTComment( + return $this->builder->buildASTComment( $this->consumeToken(self::T_DOC_COMMENT)->image ); @@ -4925,7 +4941,7 @@ private function _parseOptionalStatement() $package = $this->_getNamespaceOrPackage(); $package->addType($interface = $this->_parseInterfaceDeclaration()); - $this->_builder->restoreInterface($interface); + $this->builder->restoreInterface($interface); $this->_sourceFile->addChild($interface); return $interface; @@ -4935,13 +4951,13 @@ private function _parseOptionalStatement() $package = $this->_getNamespaceOrPackage(); $package->addType($class = $this->_parseClassDeclaration()); - $this->_builder->restoreClass($class); + $this->builder->restoreClass($class); $this->_sourceFile->addChild($class); return $class; } $this->_tokenStack->push(); - $stmt = $this->_builder->buildASTStatement(); + $stmt = $this->builder->buildASTStatement(); if (($expr = $this->_parseOptionalExpression()) != null) { $stmt->addChild($expr); } @@ -4991,10 +5007,10 @@ private function _parseCommentWithOptionalInlineClassOrInterfaceReference() { $token = $this->consumeToken(self::T_COMMENT); - $comment = $this->_builder->buildASTComment($token->image); + $comment = $this->builder->buildASTComment($token->image); if (preg_match(self::REGEXP_INLINE_TYPE, $token->image, $match)) { $comment->addChild( - $this->_builder->buildASTClassOrInterfaceReference($match[1]) + $this->builder->buildASTClassOrInterfaceReference($match[1]) ); } @@ -5074,7 +5090,7 @@ private function _parseBoundVariables(PHP_Depend_Code_ASTClosure $closure) * @return string * @link http://php.net/manual/en/language.namespaces.importing.php */ - private function _parseQualifiedName() + protected function parseQualifiedName() { $fragments = $this->_parseQualifiedNameRaw(); @@ -5175,7 +5191,7 @@ private function _parseNamespaceDeclaration() // Reset namespace property $this->_namespaceName = null; - $qualifiedName = $this->_parseQualifiedName(); + $qualifiedName = $this->parseQualifiedName(); $this->consumeComments(); if ($this->tokenizer->peek() === self::T_CURLY_BRACE_OPEN) { @@ -5301,7 +5317,7 @@ private function _parseConstantDefinition() $token = $this->consumeToken(self::T_CONST); - $definition = $this->_builder->buildASTConstantDefinition($token->image); + $definition = $this->builder->buildASTConstantDefinition($token->image); $definition->setComment($this->_docComment); do { @@ -5369,7 +5385,7 @@ private function _parseConstantDeclarator() $this->consumeComments(); $this->consumeToken(self::T_EQUAL); - $declarator = $this->_builder->buildASTConstantDeclarator($token->image); + $declarator = $this->builder->buildASTConstantDeclarator($token->image); $declarator->setValue($this->_parseStaticValue()); return $this->_setNodePositionsAndReturn($declarator); @@ -5473,7 +5489,7 @@ private function _parseStaticVariableDeclarationOrMemberPrimaryPrefix() */ private function _parseStaticVariableDeclaration(PHP_Depend_Token $token) { - $staticDeclaration = $this->_builder->buildASTStaticVariableDeclaration( + $staticDeclaration = $this->builder->buildASTStaticVariableDeclaration( $token->image ); @@ -5527,7 +5543,7 @@ private function _parseVariableDeclarator() $name = $this->consumeToken(self::T_VARIABLE)->image; $this->consumeComments(); - $declarator = $this->_builder->buildASTVariableDeclarator($name); + $declarator = $this->builder->buildASTVariableDeclarator($name); if ($this->tokenizer->peek() === self::T_EQUAL) { $this->consumeToken(self::T_EQUAL); @@ -5807,7 +5823,7 @@ private function _getNamespaceOrPackageName() */ private function _getNamespaceOrPackage() { - return $this->_builder->buildPackage($this->_getNamespaceOrPackageName()); + return $this->builder->buildPackage($this->_getNamespaceOrPackageName()); } /** @@ -5941,11 +5957,11 @@ private function _parseFieldDeclarationType() $annotations = $this->_parseVarAnnotation($this->_docComment); foreach ($annotations as $annotation) { if (PHP_Depend_Util_Type::isPrimitiveType($annotation) === true) { - return $this->_builder->buildASTPrimitiveType( + return $this->builder->buildASTPrimitiveType( PHP_Depend_Util_Type::getPrimitiveType($annotation) ); } else if (PHP_Depend_Util_Type::isArrayType($annotation) === true) { - return $this->_builder->buildASTTypeArray(); + return $this->builder->buildASTTypeArray(); } } return null; @@ -5963,7 +5979,7 @@ private function _parseFieldDeclarationClassOrInterfaceReference() $annotations = $this->_parseVarAnnotation($this->_docComment); foreach ($annotations as $annotation) { if (PHP_Depend_Util_Type::isScalarType($annotation) === false) { - return $this->_builder->buildASTClassOrInterfaceReference( + return $this->builder->buildASTClassOrInterfaceReference( $annotation ); } @@ -5990,7 +6006,7 @@ private function _prepareCallable(PHP_Depend_Code_AbstractCallable $callable) $throws = $this->_parseThrowsAnnotations($callable->getDocComment()); foreach ($throws as $qualifiedName) { $callable->addExceptionClassReference( - $this->_builder->buildASTClassOrInterfaceReference($qualifiedName) + $this->builder->buildASTClassOrInterfaceReference($qualifiedName) ); } @@ -5998,7 +6014,7 @@ private function _prepareCallable(PHP_Depend_Code_AbstractCallable $callable) $qualifiedName = $this->_parseReturnAnnotation($callable->getDocComment()); if ($qualifiedName !== null) { $callable->setReturnClassReference( - $this->_builder->buildASTClassOrInterfaceReference($qualifiedName) + $this->builder->buildASTClassOrInterfaceReference($qualifiedName) ); } } diff --git a/src/main/php/PHP/Depend/Parser/VersionAllParser.php b/src/main/php/PHP/Depend/Parser/VersionAllParser.php index 11b9c4ca9..f97efbf47 100644 --- a/src/main/php/PHP/Depend/Parser/VersionAllParser.php +++ b/src/main/php/PHP/Depend/Parser/VersionAllParser.php @@ -154,4 +154,60 @@ public function parseFunctionName() $this->tokenizer->getSourceFile() ); } + + /** + * Tests if the given token type is a valid formal parameter in the supported + * PHP version. + * + * @param integer $tokenType Numerical token identifier. + * + * @return boolean + * @since 0.11.0 + */ + protected function isFormalParameterTypeHint($tokenType) + { + switch ($tokenType) { + + case self::T_STRING: + case self::T_CALLABLE: + case self::T_BACKSLASH: + case self::T_NAMESPACE: + return true; + } + return false; + } + + /** + * Parses a formal parameter type hint that is valid in the supported PHP + * version. + * + * @return PHP_Depend_Code_ASTNode + * @since 0.11.0 + */ + protected function parseFormalParameterTypeHint() + { + switch ($this->tokenizer->peek()) { + + case self::T_CALLABLE: + $this->consumeToken(self::T_CALLABLE); + return $this->builder->buildASTTypeCallable(); + + case self::T_STRING: + case self::T_BACKSLASH: + case self::T_NAMESPACE: + $name = $this->parseQualifiedName(); + + if (0 === strcasecmp('callable', $name)) { + return $this->builder->buildASTTypeCallable(); + } + return $this->builder->buildASTClassOrInterfaceReference($name); + + case PHP_Depend_TokenizerI::T_EOF: + throw new PHP_Depend_Parser_TokenStreamEndException($this->tokenizer); + } + throw new PHP_Depend_Parser_UnexpectedTokenException( + $this->tokenizer->next(), + $this->tokenizer->getSourceFile() + ); + } } diff --git a/src/main/php/PHP/Depend/Tokenizer/Internal.php b/src/main/php/PHP/Depend/Tokenizer/Internal.php index 79da7386a..f81222e12 100644 --- a/src/main/php/PHP/Depend/Tokenizer/Internal.php +++ b/src/main/php/PHP/Depend/Tokenizer/Internal.php @@ -125,6 +125,7 @@ class PHP_Depend_Tokenizer_Internal implements PHP_Depend_TokenizerI T_PRIVATE => self::T_PRIVATE, T_REQUIRE => self::T_REQUIRE, T_ABSTRACT => self::T_ABSTRACT, + T_CALLABLE => self::T_CALLABLE, T_ENDWHILE => self::T_ENDWHILE, T_FUNCTION => self::T_FUNCTION, T_INT_CAST => self::T_INT_CAST, diff --git a/src/main/php/PHP/Depend/TokenizerI.php b/src/main/php/PHP/Depend/TokenizerI.php index acd1f6516..0c45a3c29 100644 --- a/src/main/php/PHP/Depend/TokenizerI.php +++ b/src/main/php/PHP/Depend/TokenizerI.php @@ -50,35 +50,42 @@ * Define PHP 5.3 __NAMESPACE__ token constant. */ if (!defined('T_NS_C')) { - define('T_NS_C', 378); + define('T_NS_C', 42001); } /** * Define PHP 5.3 'use' token constant */ if (!defined('T_USE')) { - define('T_USE', 340); + define('T_USE', 42002); } /** * Define PHP 5.3 'namespace' token constant. */ if (!defined('T_NAMESPACE')) { - define('T_NAMESPACE', 377); + define('T_NAMESPACE', 42003); } /** * Define PHP 5.3's '__DIR__' token constant. */ if (!defined('T_DIR')) { - define('T_DIR', 379); + define('T_DIR', 42004); } /** * Define PHP 5.3's 'T_GOTO' token constant. */ if (!defined('T_GOTO')) { - define('T_GOTO', 333); + define('T_GOTO', 42005); +} + +/** + * Define PHP 5.4's 'T_CALLABLE' token constant + */ +if (!defined('T_CALLABLE')) { + define('T_CALLABLE', 42006); } /** diff --git a/src/test/php/PHP/Depend/Builder/DefaultTest.php b/src/test/php/PHP/Depend/Builder/DefaultTest.php index d715b0f02..4a75038a3 100644 --- a/src/test/php/PHP/Depend/Builder/DefaultTest.php +++ b/src/test/php/PHP/Depend/Builder/DefaultTest.php @@ -669,6 +669,20 @@ public function testBuildASTTypeArrayReturnsExpectedType() ); } + /** + * testBuildASTTypeCallableReturnsExpectedType + * + * @return void + * @since 0.11.0 + */ + public function testBuildASTTypeCallableReturnsExpectedType() + { + $this->assertInstanceOf( + PHP_Depend_Code_ASTTypeCallable::CLAZZ, + $this->createBuilder()->buildASTTypeCallable() + ); + } + /** * testBuildASTHeredocReturnsExpectedType * diff --git a/src/test/php/PHP/Depend/Code/ASTTypeCallableTest.php b/src/test/php/PHP/Depend/Code/ASTTypeCallableTest.php new file mode 100644 index 000000000..f8ee84d5e --- /dev/null +++ b/src/test/php/PHP/Depend/Code/ASTTypeCallableTest.php @@ -0,0 +1,139 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Manuel Pichler nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category PHP + * @package PHP_Depend + * @subpackage Code + * @author Manuel Pichler + * @copyright 2008-2011 Manuel Pichler. All rights reserved. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://www.pdepend.org/ + * @since 0.11.0 + */ + +require_once dirname(__FILE__) . '/ASTNodeTest.php'; + +/** + * Test case for the {@link PHP_Depend_Code_ASTTypeCallable} class. + * + * @category PHP + * @package PHP_Depend + * @subpackage Code + * @author Manuel Pichler + * @copyright 2008-2011 Manuel Pichler. All rights reserved. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://www.pdepend.org/ + * @since 0.11.0 + * + * @covers PHP_Depend_Parser + * @covers PHP_Depend_Code_ASTTypeCallable + * @group pdepend + * @group pdepend::ast + * @group unittest + */ +class PHP_Depend_Code_ASTTypeCallableTest extends PHP_Depend_Code_ASTNodeTest +{ + /** + * testCallableTypeIsHandledCaseInsensitive + * + * @return void + */ + public function testCallableTypeIsHandledCaseInsensitive() + { + $this->assertNotNull($this->_getFirstCallableTypeInFunction()); + } + + /** + * testCallableTypeHasExpectedStartLine + * + * @return void + */ + public function testCallableTypeHasExpectedStartLine() + { + $type = $this->_getFirstCallableTypeInFunction(); + $this->assertEquals(2, $type->getStartLine()); + } + + /** + * testCallableTypeHasExpectedEndLine + * + * @return void + */ + public function testCallableTypeHasExpectedEndLine() + { + $type = $this->_getFirstCallableTypeInFunction(); + $this->assertEquals(2, $type->getEndLine()); + } + + /** + * testCallableTypeHasExpectedStartColumn + * + * @return void + */ + public function testCallableTypeHasExpectedStartColumn() + { + $type = $this->_getFirstCallableTypeInFunction(); + $this->assertEquals(49, $type->getStartColumn()); + } + + /** + * testCallableTypeHasExpectedEndColumn + * + * @return void + */ + public function testCallableTypeHasExpectedEndColumn() + { + $type = $this->_getFirstCallableTypeInFunction(); + $this->assertEquals(54, $type->getEndColumn()); + } + + /** + * Returns a node instance for the currently executed test case. + * + * @return PHP_Depend_Code_ASTTypeArray + */ + private function _getFirstCallableTypeInFunction() + { + return $this->getFirstNodeOfTypeInFunction( + $this->getCallingTestMethod(), + PHP_Depend_Code_ASTTypeCallable::CLAZZ + ); + } +} diff --git a/src/test/php/PHP/Depend/Code/AllTests.php b/src/test/php/PHP/Depend/Code/AllTests.php index 2c7a2979d..dd13d4d77 100644 --- a/src/test/php/PHP/Depend/Code/AllTests.php +++ b/src/test/php/PHP/Depend/Code/AllTests.php @@ -120,6 +120,7 @@ require_once dirname(__FILE__) . '/ASTThrowStatementTest.php'; require_once dirname(__FILE__) . '/ASTTryStatementTest.php'; require_once dirname(__FILE__) . '/ASTTypeTest.php'; +require_once dirname(__FILE__) . '/ASTTypeCallableTest.php'; require_once dirname(__FILE__) . '/ASTUnaryExpressionTest.php'; require_once dirname(__FILE__) . '/ASTUnsetStatementTest.php'; require_once dirname(__FILE__) . '/ASTVariableTest.php'; @@ -262,6 +263,7 @@ public static function suite() $suite->addTestSuite('PHP_Depend_Code_ASTThrowStatementTest'); $suite->addTestSuite('PHP_Depend_Code_ASTTryStatementTest'); $suite->addTestSuite('PHP_Depend_Code_ASTTypeTest'); + $suite->addTestSuite('PHP_Depend_Code_ASTTypeCallableTest'); $suite->addTestSuite('PHP_Depend_Code_ASTUnaryExpressionTest'); $suite->addTestSuite('PHP_Depend_Code_ASTUnsetStatementTest'); $suite->addTestSuite('PHP_Depend_Code_ASTVariableTest'); diff --git a/src/test/resources/files/Code/ASTTypeCallable/testCallableTypeHasExpectedEndColumn.php b/src/test/resources/files/Code/ASTTypeCallable/testCallableTypeHasExpectedEndColumn.php new file mode 100644 index 000000000..423f9dd91 --- /dev/null +++ b/src/test/resources/files/Code/ASTTypeCallable/testCallableTypeHasExpectedEndColumn.php @@ -0,0 +1,5 @@ +