Changeset 1081
- Timestamp:
- 11/28/07 14:20:13 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/stubReflectionProperty.php
r1016 r1081 21 21 { 22 22 /** 23 * docbloc comment for this property24 *25 * @var string26 */27 protected $docComment;28 29 /**30 23 * Name of the class 31 24 * … … 33 26 */ 34 27 protected $className; 35 28 /** 29 * reflection instance for class declaring this property 30 * 31 * @var stubBaseReflectionClass 32 */ 33 protected $refClass; 36 34 /** 37 35 * Name of the property … … 44 42 * constructor 45 43 * 46 * @param string $classNamename of class to reflect47 * @param string $propertyName name of property to reflect44 * @param string|stubBaseReflectionClass $class name of class to reflect 45 * @param string $propertyName name of property to reflect 48 46 */ 49 public function __construct($class Name, $propertyName)47 public function __construct($class, $propertyName) 50 48 { 51 parent::__construct($className, $propertyName); 52 $this->className = $className; 49 if ($class instanceof stubBaseReflectionClass) { 50 $this->refClass = $class; 51 $this->className = $class->getName(); 52 } else { 53 $this->className = $class; 54 } 55 53 56 $this->propertyName = $propertyName; 54 $this->docComment = $this->getDocComment();57 parent::__construct($this->className, $propertyName); 55 58 } 56 59 … … 63 66 public function hasAnnotation($annotationName) 64 67 { 65 return stubAnnotationFactory::has($this-> docComment, $annotationName, stubAnnotation::TARGET_PROPERTY, $this->className.'::'.$this->propertyName, $this->getDeclaringClass()->getFileName());68 return stubAnnotationFactory::has($this->getDocComment(), $annotationName, stubAnnotation::TARGET_PROPERTY, $this->className . '::' . $this->propertyName, $this->getDeclaringClass()->getFileName()); 66 69 } 67 70 … … 75 78 public function getAnnotation($annotationName) 76 79 { 77 return stubAnnotationFactory::create($this-> docComment, $annotationName, stubAnnotation::TARGET_PROPERTY, $this->className.'::'.$this->propertyName, $this->getDeclaringClass()->getFileName());80 return stubAnnotationFactory::create($this->getDocComment(), $annotationName, stubAnnotation::TARGET_PROPERTY, $this->className . '::' . $this->propertyName, $this->getDeclaringClass()->getFileName()); 78 81 } 79 82 … … 114 117 * returns the class that declares this parameter 115 118 * 116 * @return stub ReflectionClass119 * @return stubBaseReflectionClass 117 120 */ 118 121 public function getDeclaringClass() 119 122 { 120 $refClass = parent::getDeclaringClass(); 123 $refClass = parent::getDeclaringClass(); 124 if ($refClass->getName() === $this->className) { 125 if (null === $this->refClass) { 126 $this->refClass = new stubReflectionClass($refClass->getName()); 127 } 128 129 return $this->refClass; 130 } 131 121 132 $stubRefClass = new stubReflectionClass($refClass->getName()); 122 133 return $stubRefClass; trunk/src/test/php/net/stubbles/reflection/stubReflectionPropertyTestCase.php
r697 r1081 1 1 <?php 2 2 /** 3 * Test for stubReflectionProperty.3 * Test for net::stubbles::reflection::stubReflectionProperty. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 8 8 */ 9 9 stubClassLoader::load('net.stubbles.reflection.stubReflectionProperty'); 10 class stubTestProperty 10 /** 11 * class for testing purposes 12 * 13 * @package stubbles 14 * @subpackage reflection_test 15 */ 16 class stubTestProperty1 11 17 { 12 18 public $property; … … 14 20 } 15 21 /** 16 * Test for stubReflectionProperty. 22 * another class for testing purposes 23 * 24 * @package stubbles 25 * @subpackage reflection_test 26 */ 27 class stubTestProperty2 extends stubTestProperty1 { } 28 /** 29 * Test for net::stubbles::reflection::stubReflectionProperty. 17 30 * 18 31 * @package stubbles … … 33 46 public function setUp() 34 47 { 35 $this->stubRefProperty = new stubReflectionProperty('stubTestProperty ', 'property');48 $this->stubRefProperty = new stubReflectionProperty('stubTestProperty1', 'property'); 36 49 } 37 50 … … 42 55 { 43 56 $this->assertTrue($this->stubRefProperty->equals($this->stubRefProperty)); 44 $stubRefProperty1 = new stubReflectionProperty('stubTestProperty ', 'property');45 $stubRefProperty2 = new stubReflectionProperty('stubTestProperty ', 'anotherProperty');57 $stubRefProperty1 = new stubReflectionProperty('stubTestProperty1', 'property'); 58 $stubRefProperty2 = new stubReflectionProperty('stubTestProperty1', 'anotherProperty'); 46 59 $this->assertTrue($this->stubRefProperty->equals($stubRefProperty1)); 47 60 $this->assertTrue($stubRefProperty1->equals($this->stubRefProperty)); … … 56 69 public function testToString() 57 70 { 58 $this->assertEqual((string) $this->stubRefProperty, "net.stubbles.reflection.stubReflectionProperty[stubTestProperty ::property] {\n}\n");71 $this->assertEqual((string) $this->stubRefProperty, "net.stubbles.reflection.stubReflectionProperty[stubTestProperty1::property] {\n}\n"); 59 72 } 60 73 … … 66 79 $declaringClass = $this->stubRefProperty->getDeclaringClass(); 67 80 $this->assertIsA($declaringClass, 'stubReflectionClass'); 68 $this->assertEqual($declaringClass->getName(), 'stubTestProperty'); 81 $this->assertEqual($declaringClass->getName(), 'stubTestProperty1'); 82 83 $refClass1 = new stubReflectionClass('stubTestProperty1'); 84 $stubRefProperty1 = new stubReflectionProperty($refClass1, 'property'); 85 $this->assertReference($stubRefProperty1->getDeclaringClass(), $refClass1); 86 87 $refClass2 = new stubReflectionClass('stubTestProperty2'); 88 $stubRefProperty2 = new stubReflectionProperty($refClass2, 'property'); 89 $this->assertEqual($stubRefProperty2->getDeclaringClass()->getName(), 'stubTestProperty1'); 69 90 } 70 91 }
