Changeset 1079

Show
Ignore:
Timestamp:
11/28/07 13:23:38 (8 months ago)
Author:
mikey
Message:

implemented refactoring #111 for net::stubbles::reflection::stubReflectionMethod

Files:

Legend:

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

    r1078 r1079  
    3030    protected $className; 
    3131    /** 
     32     * declaring class 
     33     * 
     34     * @var  stubBaseReflectionClass 
     35     */ 
     36    protected $refClass; 
     37    /** 
    3238     * name of the reflected method 
    3339     * 
     
    3541     */ 
    3642    protected $methodName; 
    37     /** 
    38      * docblock comment for this method 
    39      * 
    40      * @var  string 
    41      */ 
    42     protected $docComment; 
    4343 
    4444    /** 
     
    5050    public function __construct($className, $methodName) 
    5151    { 
    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         
    5359        $this->methodName = $methodName; 
    54         parent::__construct($className, $methodName); 
    55         $this->docComment = $this->getDocComment(); 
     60        parent::__construct($this->className , $methodName); 
    5661    } 
    5762 
     
    6469    public function hasAnnotation($annotationName) 
    6570    { 
    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()); 
    6772    } 
    6873 
     
    7681    public function getAnnotation($annotationName) 
    7782    { 
    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()); 
    7984    } 
    8085 
     
    115120     * returns the class that declares this method 
    116121     * 
    117      * @return  stubReflectionClass 
     122     * @return  stubBaseReflectionClass 
    118123     */ 
    119124    public function getDeclaringClass() 
    120125    { 
    121         $refClass     = parent::getDeclaringClass(); 
     126        $refClass = parent::getDeclaringClass(); 
     127        if ($refClass->getName() === $this->className && null !== $this->refClass) { 
     128            return $this->refClass; 
     129        } 
     130         
    122131        $stubRefClass = new stubReflectionClass($refClass->getName()); 
    123132        return $stubRefClass; 
     
    157166    public function getReturnType() 
    158167    { 
    159         $returnPart = strstr($this->docComment, '@return'); 
     168        $returnPart = strstr($this->getDocComment(), '@return'); 
    160169        if (false === $returnPart) { 
    161170            return null; 
  • trunk/src/test/php/net/stubbles/reflection/stubReflectionMethodTestCase.php

    r941 r1079  
    11<?php 
    22/** 
    3  * Test for stubReflectionMethod. 
     3 * Test for net::stubbles::reflection::stubReflectionMethod. 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    88 */ 
    99stubClassLoader::load('net.stubbles.reflection.stubReflectionMethod'); 
     10/** 
     11 * class to be used for the test 
     12 * 
     13 * @package     stubbles 
     14 * @subpackage  reflection_test 
     15 */ 
    1016class stubTest 
    1117{ 
     
    3036    } 
    3137} 
     38/** 
     39 * another class to be used for the test 
     40 * 
     41 * @package     stubbles 
     42 * @subpackage  reflection_test 
     43 */ 
    3244class stubTest2 extends stubTest 
    3345{ 
     
    4456} 
    4557/** 
    46  * Test for stubReflectionMethod. 
     58 * Test for net::stubbles::reflection::stubReflectionMethod. 
    4759 * 
    4860 * @package     stubbles 
     
    215227        $this->assertEqual($refClass->getName(), 'stubTest'); 
    216228    } 
     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    } 
    217245} 
    218246?>