Changeset 896

Show
Ignore:
Timestamp:
09/06/07 16:33:08 (1 year ago)
Author:
mikey
Message:

added possibility to use enums as annotation values

Files:

Legend:

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

    r678 r896  
    211211        } 
    212212 
     213        $matches = array(); 
     214        if (preg_match('/^([a-zA-Z_]{1}[a-zA-Z\.0-9_]*)::\$([a-zA-Z_]{1}[a-zA-Z0-9_]*)/', $value, $matches) != false) { 
     215            stubClassLoader::load('net.stubbles.lang.stubEnum'); 
     216            try { 
     217                return stubEnum::forName(new stubReflectionClass($matches[1]), $matches[2]); 
     218            } catch (Exception $e) { 
     219                echo $e->getMessage(); 
     220                return null; 
     221            } 
     222        } 
     223         
    213224        if (defined($value) == true) { 
    214225            return constant($value); 
  • trunk/src/test/php/net/stubbles/reflection/annotations/parser/stubAnnotationStateParserTestCase.php

    r502 r896  
    88 * @subpackage  reflection_annotations_parser_test 
    99 */ 
    10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationStateParser'); 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationStateParser', 
     11                      'net.stubbles.lang.stubEnum' 
     12); 
    1113define('ANNOTATION_TEST_CONSTANT', 'baz'); 
    1214/** 
     
    2224 * @SingleValue(42) 
    2325 * @Constant(foo=ANNOTATION_TEST_CONSTANT) 
     26 * @Constant2(foo=MyTestClass::TEST_CONSTANT) 
     27 * @Enum(foo=MyTestClass::$FOO) 
    2428 * @SingleStringValue('This is a string with chars like = or ,') 
    2529 * @WithEscaped(foo='This string contains \' and \\, which is possible using escaping...') 
     
    3539 *            class=MyTestClass.class) 
    3640 */ 
    37 class MyTestClass { } 
     41class MyTestClass extends stubEnum 
     42
     43    const TEST_CONSTANT = 'baz'; 
     44    public static $FOO; 
     45     
     46    public static function __static() 
     47    { 
     48        self::$FOO = new self('FOO'); 
     49    } 
     50
     51MyTestClass::__static(); 
    3852/** 
    3953 * Test for net.stubbles.reflection.annotations.parser.stubAnnotationStateParser. 
     
    7993        $this->assertEqual($annotations['Constant']['type'], 'Constant'); 
    8094        $this->assertEqual($annotations['Constant']['params'], array('foo' => ANNOTATION_TEST_CONSTANT)); 
     95        $this->assertTrue(isset($annotations['Constant2'])); 
     96        $this->assertEqual($annotations['Constant2']['type'], 'Constant2'); 
     97        $this->assertEqual($annotations['Constant2']['params'], array('foo' => MyTestClass::TEST_CONSTANT)); 
     98        $this->assertTrue(isset($annotations['Enum'])); 
     99        $this->assertEqual($annotations['Enum']['type'], 'Enum'); 
     100        $this->assertEqual($annotations['Enum']['params'], array('foo' => MyTestClass::$FOO)); 
    81101        $this->assertTrue(isset($annotations['SingleStringValue'])); 
    82102        $this->assertEqual($annotations['SingleStringValue']['type'], 'SingleStringValue');