Changeset 834

Show
Ignore:
Timestamp:
08/14/07 23:19:24 (1 year ago)
Author:
mikey
Message:

fixed bug #77

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotationFactory.php

    r772 r834  
    4646     * @param   int             $target           the target for which the annotation should be created 
    4747     * @param   string          $targetName       the name of the target (property, class, method or function name) 
     48     * @param   string          $fileName         the file where the target resides 
    4849     * @return  stubAnnotation 
    4950     * @throws  ReflectionException 
    5051     */ 
    51     public static function create($comment, $annotationName, $target, $targetName
     52    public static function create($comment, $annotationName, $target, $targetName, $fileName
    5253    { 
    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); 
    5556        } 
    5657 
    57         $hash = md5($comment . $target . $targetName); 
     58        $hash = md5($fileName . $comment . $target . $targetName); 
    5859        if (isset(self::$annotations[$hash]) == false) { 
    5960            if (null == self::$parser) { 
     
    8990        self::build($annotation, self::$annotations[$hash][$annotationName]['params']); 
    9091        $annotation->setAnnotationName($annotationName); 
    91         stubAnnotationCache::put($target, $targetName, $annotationName, $annotation); 
     92        stubAnnotationCache::put($target, $fileName . '::' . $targetName, $annotationName, $annotation); 
    9293        return $annotation; 
    9394    } 
     
    131132     * Checks whether the given docblock has the requested annotation 
    132133     * 
    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 
    135139     * @return  bool 
    136140     */ 
    137     public static function has($comment, $annotationName, $target, $targetName
     141    public static function has($comment, $annotationName, $target, $targetName, $fileName
    138142    { 
    139143        $annotation = null; 
    140144        try { 
    141             $annotation = self::create($comment, $annotationName, $target, $targetName); 
     145            $annotation = self::create($comment, $annotationName, $target, $targetName, $fileName); 
    142146        } catch (ReflectionException $e) { 
    143147        } 
  • trunk/src/main/php/net/stubbles/reflection/stubReflectionClass.php

    r795 r834  
    6464    public function hasAnnotation($annotationName) 
    6565    { 
    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()); 
    6767    } 
    6868 
     
    7676    public function getAnnotation($annotationName) 
    7777    { 
    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()); 
    7979    } 
    8080 
  • trunk/src/main/php/net/stubbles/reflection/stubReflectionFunction.php

    r432 r834  
    5252    public function hasAnnotation($annotationName) 
    5353    { 
    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()); 
    5555    } 
    5656     
     
    6464    public function getAnnotation($annotationName) 
    6565    { 
    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()); 
    6767    } 
    6868     
  • trunk/src/main/php/net/stubbles/reflection/stubReflectionMethod.php

    r432 r834  
    6161    public function hasAnnotation($annotationName) 
    6262    { 
    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()); 
    6464    } 
    6565     
     
    7373    public function getAnnotation($annotationName) 
    7474    { 
    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()); 
    7676    } 
    7777     
  • trunk/src/main/php/net/stubbles/reflection/stubReflectionObject.php

    r795 r834  
    6363    public function hasAnnotation($annotationName) 
    6464    { 
    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()); 
    6666    } 
    6767 
     
    7575    public function getAnnotation($annotationName) 
    7676    { 
    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()); 
    7878    } 
    7979 
  • trunk/src/main/php/net/stubbles/reflection/stubReflectionProperty.php

    r432 r834  
    6262    public function hasAnnotation($annotationName) 
    6363    { 
    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()); 
    6565    } 
    6666     
     
    7474    public function getAnnotation($annotationName) 
    7575    { 
    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()); 
    7777    } 
    7878     
  • trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryTestCase.php

    r702 r834  
    130130    public function testHas() 
    131131    { 
    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')); 
    140159    } 
    141160 
     
    145164    public function testCreate() 
    146165    { 
    147         $myAnnotation = stubAnnotationFactory::create($this->commentComplex, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass'); 
     166        $myAnnotation = stubAnnotationFactory::create($this->commentComplex, 'MyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 
    148167        $this->assertIsA($myAnnotation, 'MyAnnotation'); 
    149168        $this->assertEqual('bar', $myAnnotation->foo); 
     
    151170        $this->assertEqual('tomato', $myAnnotation->veggie); 
    152171 
    153         $anotherAnnotation = stubAnnotationFactory::create($this->commentComplex, 'AnotherAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass'); 
     172        $anotherAnnotation = stubAnnotationFactory::create($this->commentComplex, 'AnotherAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 
    154173        $this->assertIsA($anotherAnnotation, 'AnotherAnnotation'); 
    155174        $this->assertEqual('true', $anotherAnnotation->value); 
    156175 
    157         $emptyAnnotation = stubAnnotationFactory::create($this->commentComplex, 'EmptyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass'); 
     176        $emptyAnnotation = stubAnnotationFactory::create($this->commentComplex, 'EmptyAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 
    158177        $this->assertIsA($emptyAnnotation, 'EmptyAnnotation'); 
    159178 
    160         $castedAnnotation = stubAnnotationFactory::create($this->commentComplex, 'CastedAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass'); 
     179        $castedAnnotation = stubAnnotationFactory::create($this->commentComplex, 'CastedAnnotation', stubAnnotation::TARGET_CLASS, 'MyClass', __FILE__); 
    161180        $this->assertIsA($castedAnnotation, 'AnotherAnnotation'); 
    162181        $this->assertFalse($castedAnnotation->value); 
    163182 
    164183        $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__); 
    168187        $this->assertIsA($myAnnotation, 'MyAnnotation'); 
    169188        $this->assertIsA($myAnnotation->foo, 'stubReflectionClass');