Changeset 1079
- Timestamp:
- 11/28/07 13:23:38 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/stubReflectionMethod.php
r1078 r1079 30 30 protected $className; 31 31 /** 32 * declaring class 33 * 34 * @var stubBaseReflectionClass 35 */ 36 protected $refClass; 37 /** 32 38 * name of the reflected method 33 39 * … … 35 41 */ 36 42 protected $methodName; 37 /**38 * docblock comment for this method39 *40 * @var string41 */42 protected $docComment;43 43 44 44 /** … … 50 50 public function __construct($className, $methodName) 51 51 { 52 $this->className = $className; 52 if ($className instanceof stubBaseReflectionClass) { 53 $this->refClass = $className; 54 $this->className = $this->refClass->getName(); 55 } else { 56 $this->className = $className; 57 } 58 53 59 $this->methodName = $methodName; 54 parent::__construct($className, $methodName); 55 $this->docComment = $this->getDocComment(); 60 parent::__construct($this->className , $methodName); 56 61 } 57 62 … … 64 69 public function hasAnnotation($annotationName) 65 70 { 66 return stubAnnotationFactory::has($this-> docComment, $annotationName, stubAnnotation::TARGET_METHOD, $this->className . '::' . $this->methodName . '()', $this->getFileName());71 return stubAnnotationFactory::has($this->getDocComment(), $annotationName, stubAnnotation::TARGET_METHOD, $this->className . '::' . $this->methodName . '()', $this->getFileName()); 67 72 } 68 73 … … 76 81 public function getAnnotation($annotationName) 77 82 { 78 return stubAnnotationFactory::create($this-> docComment, $annotationName, stubAnnotation::TARGET_METHOD, $this->className . '::' . $this->methodName . '()', $this->getFileName());83 return stubAnnotationFactory::create($this->getDocComment(), $annotationName, stubAnnotation::TARGET_METHOD, $this->className . '::' . $this->methodName . '()', $this->getFileName()); 79 84 } 80 85 … … 115 120 * returns the class that declares this method 116 121 * 117 * @return stub ReflectionClass122 * @return stubBaseReflectionClass 118 123 */ 119 124 public function getDeclaringClass() 120 125 { 121 $refClass = parent::getDeclaringClass(); 126 $refClass = parent::getDeclaringClass(); 127 if ($refClass->getName() === $this->className && null !== $this->refClass) { 128 return $this->refClass; 129 } 130 122 131 $stubRefClass = new stubReflectionClass($refClass->getName()); 123 132 return $stubRefClass; … … 157 166 public function getReturnType() 158 167 { 159 $returnPart = strstr($this-> docComment, '@return');168 $returnPart = strstr($this->getDocComment(), '@return'); 160 169 if (false === $returnPart) { 161 170 return null; trunk/src/test/php/net/stubbles/reflection/stubReflectionMethodTestCase.php
r941 r1079 1 1 <?php 2 2 /** 3 * Test for stubReflectionMethod.3 * Test for net::stubbles::reflection::stubReflectionMethod. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 8 8 */ 9 9 stubClassLoader::load('net.stubbles.reflection.stubReflectionMethod'); 10 /** 11 * class to be used for the test 12 * 13 * @package stubbles 14 * @subpackage reflection_test 15 */ 10 16 class stubTest 11 17 { … … 30 36 } 31 37 } 38 /** 39 * another class to be used for the test 40 * 41 * @package stubbles 42 * @subpackage reflection_test 43 */ 32 44 class stubTest2 extends stubTest 33 45 { … … 44 56 } 45 57 /** 46 * Test for stubReflectionMethod.58 * Test for net::stubbles::reflection::stubReflectionMethod. 47 59 * 48 60 * @package stubbles … … 215 227 $this->assertEqual($refClass->getName(), 'stubTest'); 216 228 } 229 230 public function testInstantiationWithReflectionClass() 231 { 232 $refClass1 = new stubReflectionClass('stubTest'); 233 $refClass2 = new stubReflectionClass('stubTest2'); 234 $stubRefMethod1 = new stubReflectionMethod($refClass1, 'methodWithoutParams'); 235 $this->assertReference($stubRefMethod1->getDeclaringClass(), $refClass1); 236 $stubRefMethod2 = new stubReflectionMethod($refClass1, 'methodWithParams'); 237 $this->assertReference($stubRefMethod2->getDeclaringClass(), $refClass1); 238 $stubRefMethod3 = new stubReflectionMethod($refClass2, 'methodWithoutParams'); 239 $this->assertEqual($stubRefMethod3->getDeclaringClass()->getName(), 'stubTest'); 240 $stubRefMethod4 = new stubReflectionMethod($refClass2, 'methodWithParams'); 241 $this->assertEqual($stubRefMethod4->getDeclaringClass()->getName(), 'stubTest'); 242 $stubRefMethod5 = new stubReflectionMethod($refClass2, 'methodWithParams2'); 243 $this->assertReference($stubRefMethod5->getDeclaringClass(), $refClass2); 244 } 217 245 } 218 246 ?>
