Changeset 834
- Timestamp:
- 08/14/07 23:19:24 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotationFactory.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/reflection/stubReflectionClass.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/reflection/stubReflectionFunction.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/reflection/stubReflectionMethod.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/reflection/stubReflectionObject.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/reflection/stubReflectionProperty.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryTestCase.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotationFactory.php
r772 r834 46 46 * @param int $target the target for which the annotation should be created 47 47 * @param string $targetName the name of the target (property, class, method or function name) 48 * @param string $fileName the file where the target resides 48 49 * @return stubAnnotation 49 50 * @throws ReflectionException 50 51 */ 51 public static function create($comment, $annotationName, $target, $targetName )52 public static function create($comment, $annotationName, $target, $targetName, $fileName) 52 53 { 53 if (stubAnnotationCache::has($target, $ targetName, $annotationName)) {54 return $cachedAnnotation = stubAnnotationCache::get($target, $ targetName, $annotationName);54 if (stubAnnotationCache::has($target, $fileName . '::' . $targetName, $annotationName)) { 55 return $cachedAnnotation = stubAnnotationCache::get($target, $fileName . '::' . $targetName, $annotationName); 55 56 } 56 57 57 $hash = md5($ comment . $target . $targetName);58 $hash = md5($fileName . $comment . $target . $targetName); 58 59 if (isset(self::$annotations[$hash]) == false) { 59 60 if (null == self::$parser) { … … 89 90 self::build($annotation, self::$annotations[$hash][$annotationName]['params']); 90 91 $annotation->setAnnotationName($annotationName); 91 stubAnnotationCache::put($target, $ targetName, $annotationName, $annotation);92 stubAnnotationCache::put($target, $fileName . '::' . $targetName, $annotationName, $annotation); 92 93 return $annotation; 93 94 } … … 131 132 * Checks whether the given docblock has the requested annotation 132 133 * 133 * @param string $comment the docblock comment that contains the annotation data 134 * @param string $annotationName name of the annotation to check for 134 * @param string $comment the docblock comment that contains the annotation data 135 * @param string $annotationName name of the annotation to check for 136 * @param int $target the target for which the annotation should be created 137 * @param string $targetName the name of the target (property, class, method or function name) 138 * @param string $fileName the file where the target resides 135 139 * @return bool 136 140 */ 137 public static function has($comment, $annotationName, $target, $targetName )141 public static function has($comment, $annotationName, $target, $targetName, $fileName) 138 142 { 139 143 $annotation = null; 140 144 try { 141 $annotation = self::create($comment, $annotationName, $target, $targetName );145 $annotation = self::create($comment, $annotationName, $target, $targetName, $fileName); 142 146 } catch (ReflectionException $e) { 143 147 } trunk/src/main/php/net/stubbles/reflection/stubReflectionClass.php
r795 r834 64 64 public function hasAnnotation($annotationName) 65 65 { 66 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_CLASS, $this->className );66 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_CLASS, $this->className, $this->getFileName()); 67 67 } 68 68 … … 76 76 public function getAnnotation($annotationName) 77 77 { 78 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_CLASS, $this->className );78 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_CLASS, $this->className, $this->getFileName()); 79 79 } 80 80 trunk/src/main/php/net/stubbles/reflection/stubReflectionFunction.php
r432 r834 52 52 public function hasAnnotation($annotationName) 53 53 { 54 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_FUNCTION, $this->functionName );54 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_FUNCTION, $this->functionName, $this->getFileName()); 55 55 } 56 56 … … 64 64 public function getAnnotation($annotationName) 65 65 { 66 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_FUNCTION, $this->functionName );66 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_FUNCTION, $this->functionName, $this->getFileName()); 67 67 } 68 68 trunk/src/main/php/net/stubbles/reflection/stubReflectionMethod.php
r432 r834 61 61 public function hasAnnotation($annotationName) 62 62 { 63 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_METHOD, $this->className.'::'.$this->methodName );63 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_METHOD, $this->className.'::'.$this->methodName, $this->getFileName()); 64 64 } 65 65 … … 73 73 public function getAnnotation($annotationName) 74 74 { 75 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_METHOD, $this->className.'::'.$this->methodName );75 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_METHOD, $this->className.'::'.$this->methodName, $this->getFileName()); 76 76 } 77 77 trunk/src/main/php/net/stubbles/reflection/stubReflectionObject.php
r795 r834 63 63 public function hasAnnotation($annotationName) 64 64 { 65 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_CLASS, $this->className );65 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_CLASS, $this->className, $this->getFileName()); 66 66 } 67 67 … … 75 75 public function getAnnotation($annotationName) 76 76 { 77 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_CLASS, $this->className );77 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_CLASS, $this->className, $this->getFileName()); 78 78 } 79 79 trunk/src/main/php/net/stubbles/reflection/stubReflectionProperty.php
r432 r834 62 62 public function hasAnnotation($annotationName) 63 63 { 64 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_PROPERTY, $this->className.'::'.$this->propertyName );64 return stubAnnotationFactory::has($this->docComment, $annotationName, stubAnnotation::TARGET_PROPERTY, $this->className.'::'.$this->propertyName, $this->getDeclaringClass()->getFileName()); 65 65 } 66 66 … … 74 74 public function getAnnotation($annotationName) 75 75 { 76 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_PROPERTY, $this->className.'::'.$this->propertyName );76 return stubAnnotationFactory::create($this->docComment, $annotationName, stubAnnotation::TARGET_PROPERTY, $this->className.'::'.$this->propertyName, $this->getDeclaringClass()->getFileName()); 77 77 } 78 78 trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryTestCase.php
r702 r834 130 130 public function testHas() 131 131 { 132 $this->assertFalse(stubAnnotationFactory::has($this->comment, 'ExampleAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass')); 133 $this->assertFalse(stubAnnotationFactory::has($this->comment, 'StubAnno', stubAnnotation::TARGET_CLASS, 'MyClass')); 134 135 $this->assertTrue(stubAnnotationFactory::has($this->commentComplex, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass')); 136 $this->assertTrue(stubAnnotationFactory::has($this->commentComplex, 'AnotherAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass')); 137 $this->assertTrue(stubAnnotationFactory::has($this->commentComplex, 'EmptyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass')); 138 139 $this->assertFalse(stubAnnotationFactory::has($this->commentComplex, 'EmptyAnnotation', stubAnnotation::TARGET_FUNCTION, 'MyFunction')); 132 $this->assertFalse(stubAnnotationFactory::has($this->comment, 'ExampleAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__)); 133 $this->assertFalse(stubAnnotationFactory::has($this->comment, 'StubAnno', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__)); 134 135 $this->assertTrue(stubAnnotationFactory::has($this->commentComplex, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__)); 136 $this->assertTrue(stubAnnotationFactory::has($this->commentComplex, 'AnotherAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__)); 137 $this->assertTrue(stubAnnotationFactory::has($this->commentComplex, 'EmptyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__)); 138 139 $this->assertFalse(stubAnnotationFactory::has($this->commentComplex, 'EmptyAnnotation', stubAnnotation::TARGET_FUNCTION, 'MyFunction', __FILE__)); 140 } 141 142 /** 143 * test that bug #77 will never occur again 144 * 145 * @link http://stubbles.net/ticket/77 146 */ 147 public function testBug77() 148 { 149 // clear the cache from both annotations first 150 stubAnnotationCache::put(stubAnnotation::TARGET_CLASS, __FILE__ . '1' . '::' . 'MyClass', 'MyAnnotation', null); 151 stubAnnotationCache::put(stubAnnotation::TARGET_CLASS, __FILE__ . '2' . '::' . 'MyClass', 'MyAnnotation', null); 152 153 $myAnnotation1 = stubAnnotationFactory::create($this->commentComplex, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__ . '1'); 154 $this->assertTrue(stubAnnotationCache::has(stubAnnotation::TARGET_CLASS, __FILE__ . '1' . '::' . 'MyClass', 'MyAnnotation')); 155 $this->assertFalse(stubAnnotationCache::has(stubAnnotation::TARGET_CLASS, __FILE__ . '2' . '::' . 'MyClass', 'MyAnnotation')); 156 $myAnnotation2 = stubAnnotationFactory::create($this->commentComplex, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__ . '2'); 157 $this->assertTrue(stubAnnotationCache::has(stubAnnotation::TARGET_CLASS, __FILE__ . '1' . '::' . 'MyClass', 'MyAnnotation')); 158 $this->assertTrue(stubAnnotationCache::has(stubAnnotation::TARGET_CLASS, __FILE__ . '2' . '::' . 'MyClass', 'MyAnnotation')); 140 159 } 141 160 … … 145 164 public function testCreate() 146 165 { 147 $myAnnotation = stubAnnotationFactory::create($this->commentComplex, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass' );166 $myAnnotation = stubAnnotationFactory::create($this->commentComplex, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 148 167 $this->assertIsA($myAnnotation, 'MyAnnotation'); 149 168 $this->assertEqual('bar', $myAnnotation->foo); … … 151 170 $this->assertEqual('tomato', $myAnnotation->veggie); 152 171 153 $anotherAnnotation = stubAnnotationFactory::create($this->commentComplex, 'AnotherAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass' );172 $anotherAnnotation = stubAnnotationFactory::create($this->commentComplex, 'AnotherAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 154 173 $this->assertIsA($anotherAnnotation, 'AnotherAnnotation'); 155 174 $this->assertEqual('true', $anotherAnnotation->value); 156 175 157 $emptyAnnotation = stubAnnotationFactory::create($this->commentComplex, 'EmptyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass' );176 $emptyAnnotation = stubAnnotationFactory::create($this->commentComplex, 'EmptyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 158 177 $this->assertIsA($emptyAnnotation, 'EmptyAnnotation'); 159 178 160 $castedAnnotation = stubAnnotationFactory::create($this->commentComplex, 'CastedAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass' );179 $castedAnnotation = stubAnnotationFactory::create($this->commentComplex, 'CastedAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 161 180 $this->assertIsA($castedAnnotation, 'AnotherAnnotation'); 162 181 $this->assertFalse($castedAnnotation->value); 163 182 164 183 $this->expectException('ReflectionException'); 165 stubAnnotationFactory::create($this->commentComplex, 'NonExisting', stubAnnotation::TARGET_CLASS, 'MyClass' );166 167 $myAnnotation = stubAnnotationFactory::create($this->commentCommentWithClass, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass' );184 stubAnnotationFactory::create($this->commentComplex, 'NonExisting', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 185 186 $myAnnotation = stubAnnotationFactory::create($this->commentCommentWithClass, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 168 187 $this->assertIsA($myAnnotation, 'MyAnnotation'); 169 188 $this->assertIsA($myAnnotation->foo, 'stubReflectionClass');
