From c6cc9dd7c9ba1c97ade04e915033ad691f2ba280 Mon Sep 17 00:00:00 2001 From: Manuel Pichler Date: Tue, 28 Dec 2010 13:09:37 +0100 Subject: [PATCH] - Fixed #189: Invalid Start/End Line/Column for object method invocation. --- PHP/Depend/Parser.php | 36 +++- .../PHP/Depend/Code/ASTMethodPostfixTest.php | 184 ++++++++++++++++-- ...ClassMethodPostfixHasExpectedEndColumn.php | 8 + ...stClassMethodPostfixHasExpectedEndLine.php | 8 + ...assMethodPostfixHasExpectedStartColumn.php | 8 + ...ClassMethodPostfixHasExpectedStartLine.php | 8 + ...bjectMethodPostfixHasExpectedEndColumn.php | 8 + ...tObjectMethodPostfixHasExpectedEndLine.php | 8 + ...ectMethodPostfixHasExpectedStartColumn.php | 8 + ...bjectMethodPostfixHasExpectedStartLine.php | 8 + 10 files changed, 258 insertions(+), 26 deletions(-) create mode 100644 tests/PHP/Depend/_code/Code/ASTMethodPostfix/testClassMethodPostfixHasExpectedEndColumn.php create mode 100644 tests/PHP/Depend/_code/Code/ASTMethodPostfix/testClassMethodPostfixHasExpectedEndLine.php create mode 100644 tests/PHP/Depend/_code/Code/ASTMethodPostfix/testClassMethodPostfixHasExpectedStartColumn.php create mode 100644 tests/PHP/Depend/_code/Code/ASTMethodPostfix/testClassMethodPostfixHasExpectedStartLine.php create mode 100644 tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedEndColumn.php create mode 100644 tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedEndLine.php create mode 100644 tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedStartColumn.php create mode 100644 tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedStartLine.php diff --git a/PHP/Depend/Parser.php b/PHP/Depend/Parser.php index 419866e53..2652f6752 100644 --- a/PHP/Depend/Parser.php +++ b/PHP/Depend/Parser.php @@ -3475,18 +3475,40 @@ private function _parseMethodOrPropertyPostfix(PHP_Depend_Code_ASTNode $node) switch ($this->tokenizer->peek()) { case self::T_PARENTHESIS_OPEN: - $postfix = $this->_builder->buildASTMethodPostfix($node->getImage()); - $postfix->addChild($node); - $postfix->addChild($this->_parseArguments()); - - return $this->_parseOptionalMemberPrimaryPrefix($postfix); + $postfix = $this->_parseMethodPostfix($node); + break; default: $postfix = $this->_builder->buildASTPropertyPostfix($node->getImage()); $postfix->addChild($node); - - return $this->_parseOptionalMemberPrimaryPrefix($postfix); + break; } + return $this->_parseOptionalMemberPrimaryPrefix($postfix); + } + + /** + * Parses a method postfix node instance. + * + * @param PHP_Depend_Code_ASTNode $node Node that represents the image of + * the method postfix node. + * + * @return PHP_Depend_Code_ASTMethodPostfix + * @since 0.11.0 + */ + private function _parseMethodPostfix(PHP_Depend_Code_ASTNode $node) + { + $args = $this->_parseArguments(); + + $postfix = $this->_builder->buildASTMethodPostfix($node->getImage()); + $postfix->addChild($node); + $postfix->addChild($args); + + $postfix->setEndLine($args->getEndLine()); + $postfix->setEndColumn($args->getEndColumn()); + $postfix->setStartLine($node->getStartLine()); + $postfix->setStartColumn($node->getStartColumn()); + + return $postfix; } /** diff --git a/tests/PHP/Depend/Code/ASTMethodPostfixTest.php b/tests/PHP/Depend/Code/ASTMethodPostfixTest.php index da693f6c6..1dd4b9c41 100644 --- a/tests/PHP/Depend/Code/ASTMethodPostfixTest.php +++ b/tests/PHP/Depend/Code/ASTMethodPostfixTest.php @@ -48,9 +48,6 @@ require_once dirname(__FILE__) . '/ASTNodeTest.php'; -require_once 'PHP/Depend/Code/ASTMethodPostfix.php'; -require_once 'PHP/Depend/ConstantsI.php'; - /** * Test case for the {@link PHP_Depend_Code_ASTMethodPostfix} class. * @@ -65,6 +62,142 @@ */ class PHP_Depend_Code_ASTMethodPostfixTest extends PHP_Depend_Code_ASTNodeTest { + /** + * testObjectMethodPostfixHasExpectedStartLine + * + * @return void + * @covers PHP_Depend_Parser + * @covers PHP_Depend_Builder_Default + * @covers PHP_Depend_Code_ASTMethodPostfix + * @group pdepend + * @group pdepend::ast + * @group unittest + */ + public function testObjectMethodPostfixHasExpectedStartLine() + { + $postfix = $this->_getFirstMethodPostfixInFunction(); + self::assertEquals(6, $postfix->getStartLine()); + } + + /** + * testObjectMethodPostfixHasExpectedStartColumn + * + * @return void + * @covers PHP_Depend_Parser + * @covers PHP_Depend_Builder_Default + * @covers PHP_Depend_Code_ASTMethodPostfix + * @group pdepend + * @group pdepend::ast + * @group unittest + */ + public function testObjectMethodPostfixHasExpectedStartColumn() + { + $postfix = $this->_getFirstMethodPostfixInFunction(); + self::assertEquals(13, $postfix->getStartColumn()); + } + + /** + * testObjectMethodPostfixHasExpectedEndLine + * + * @return void + * @covers PHP_Depend_Parser + * @covers PHP_Depend_Builder_Default + * @covers PHP_Depend_Code_ASTMethodPostfix + * @group pdepend + * @group pdepend::ast + * @group unittest + */ + public function testObjectMethodPostfixHasExpectedEndLine() + { + $postfix = $this->_getFirstMethodPostfixInFunction(); + self::assertEquals(7, $postfix->getEndLine()); + } + + /** + * testObjectMethodPostfixHasExpectedEndColumn + * + * @return void + * @covers PHP_Depend_Parser + * @covers PHP_Depend_Builder_Default + * @covers PHP_Depend_Code_ASTMethodPostfix + * @group pdepend + * @group pdepend::ast + * @group unittest + */ + public function testObjectMethodPostfixHasExpectedEndColumn() + { + $postfix = $this->_getFirstMethodPostfixInFunction(); + self::assertEquals(17, $postfix->getEndColumn()); + } + + /** + * testClassMethodPostfixHasExpectedStartLine + * + * @return void + * @covers PHP_Depend_Parser + * @covers PHP_Depend_Builder_Default + * @covers PHP_Depend_Code_ASTMethodPostfix + * @group pdepend + * @group pdepend::ast + * @group unittest + */ + public function testClassMethodPostfixHasExpectedStartLine() + { + $postfix = $this->_getFirstMethodPostfixInFunction(); + self::assertEquals(6, $postfix->getStartLine()); + } + + /** + * testClassMethodPostfixHasExpectedStartColumn + * + * @return void + * @covers PHP_Depend_Parser + * @covers PHP_Depend_Builder_Default + * @covers PHP_Depend_Code_ASTMethodPostfix + * @group pdepend + * @group pdepend::ast + * @group unittest + */ + public function testClassMethodPostfixHasExpectedStartColumn() + { + $postfix = $this->_getFirstMethodPostfixInFunction(); + self::assertEquals(13, $postfix->getStartColumn()); + } + + /** + * testClassMethodPostfixHasExpectedEndLine + * + * @return void + * @covers PHP_Depend_Parser + * @covers PHP_Depend_Builder_Default + * @covers PHP_Depend_Code_ASTMethodPostfix + * @group pdepend + * @group pdepend::ast + * @group unittest + */ + public function testClassMethodPostfixHasExpectedEndLine() + { + $postfix = $this->_getFirstMethodPostfixInFunction(); + self::assertEquals(7, $postfix->getEndLine()); + } + + /** + * testClassMethodPostfixHasExpectedEndColumn + * + * @return void + * @covers PHP_Depend_Parser + * @covers PHP_Depend_Builder_Default + * @covers PHP_Depend_Code_ASTMethodPostfix + * @group pdepend + * @group pdepend::ast + * @group unittest + */ + public function testClassMethodPostfixHasExpectedEndColumn() + { + $postfix = $this->_getFirstMethodPostfixInFunction(); + self::assertEquals(17, $postfix->getEndColumn()); + } + /** * testAcceptInvokesVisitOnGivenVisitor * @@ -129,7 +262,7 @@ public function testMethodPostfixStructureForSimpleInvocation() PHP_Depend_Code_ASTArguments::CLAZZ ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -153,7 +286,7 @@ public function testMethodPostfixStructureForVariableInvocation() PHP_Depend_Code_ASTArguments::CLAZZ ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -178,7 +311,7 @@ public function testMethodPostfixStructureForVariableVariableInvocation() PHP_Depend_Code_ASTArguments::CLAZZ ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -203,7 +336,7 @@ public function testMethodPostfixStructureForCompoundVariableInvocation() PHP_Depend_Code_ASTArguments::CLAZZ ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -227,7 +360,7 @@ public function testMethodPostfixStructureForSimpleStaticInvocation() PHP_Depend_Code_ASTArguments::CLAZZ ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -251,7 +384,7 @@ public function testMethodPostfixStructureForVariableStaticInvocation() PHP_Depend_Code_ASTArguments::CLAZZ ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -276,7 +409,7 @@ public function testMethodPostfixStructureForVariableVariableStaticInvocation() PHP_Depend_Code_ASTArguments::CLAZZ ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -301,7 +434,7 @@ public function testMethodPostfixStructureForCompoundVariableStaticInvocation() PHP_Depend_Code_ASTArguments::CLAZZ, ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -328,7 +461,7 @@ public function testMethodPostfixStructureForVariableCompoundVariableStaticInvoc PHP_Depend_Code_ASTArguments::CLAZZ, ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -356,7 +489,7 @@ public function testMethodPostfixStructureForStaticInvocationWithConsecutiveInvo PHP_Depend_Code_ASTArguments::CLAZZ ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -380,7 +513,7 @@ public function testMethodPostfixStructureForStaticInvocationOnVariable() PHP_Depend_Code_ASTArguments::CLAZZ ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -404,7 +537,7 @@ public function testMethodPostfixStructureForSelfInvocation() PHP_Depend_Code_ASTArguments::CLAZZ, ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -428,7 +561,7 @@ public function testMethodPostfixStructureForParentInvocation() PHP_Depend_Code_ASTArguments::CLAZZ, ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -452,7 +585,7 @@ public function testMethodPostfixGraphForStaticReferenceInvocation() PHP_Depend_Code_ASTArguments::CLAZZ, ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -482,7 +615,7 @@ public function testMethodPostfixGraphForVariableArrayElementInvocation() PHP_Depend_Code_ASTArguments::CLAZZ, ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); } /** @@ -512,7 +645,20 @@ public function testMethodPostfixGraphForPropertyArrayElementInvocation() PHP_Depend_Code_ASTArguments::CLAZZ, ); - $this->assertGraphEquals($prefix, $expected); + self::assertGraphEquals($prefix, $expected); + } + + /** + * Returns a node instance for the currently executed test case. + * + * @return PHP_Depend_Code_ASTMethodPostfix + */ + private function _getFirstMethodPostfixInFunction() + { + return $this->getFirstNodeOfTypeInFunction( + self::getCallingTestMethod(), + PHP_Depend_Code_ASTMethodPostfix::CLAZZ + ); } /** diff --git a/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testClassMethodPostfixHasExpectedEndColumn.php b/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testClassMethodPostfixHasExpectedEndColumn.php new file mode 100644 index 000000000..73ce80686 --- /dev/null +++ b/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testClassMethodPostfixHasExpectedEndColumn.php @@ -0,0 +1,8 @@ + + foo( + ); +} \ No newline at end of file diff --git a/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedEndLine.php b/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedEndLine.php new file mode 100644 index 000000000..d310a5cb4 --- /dev/null +++ b/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedEndLine.php @@ -0,0 +1,8 @@ + + foo( + ); +} \ No newline at end of file diff --git a/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedStartColumn.php b/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedStartColumn.php new file mode 100644 index 000000000..a848fd934 --- /dev/null +++ b/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedStartColumn.php @@ -0,0 +1,8 @@ + + foo( + ); +} \ No newline at end of file diff --git a/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedStartLine.php b/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedStartLine.php new file mode 100644 index 000000000..18c12f215 --- /dev/null +++ b/tests/PHP/Depend/_code/Code/ASTMethodPostfix/testObjectMethodPostfixHasExpectedStartLine.php @@ -0,0 +1,8 @@ + + foo( + ); +} \ No newline at end of file