Changeset 456

Show
Ignore:
Timestamp:
04/02/07 23:58:57 (1 year ago)
Author:
mikey
Message:

refactored stubAnnotationStateParser

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docroot/annotationParser.php

    r433 r456  
    33require_once '../src/main/php/net/stubbles/stubClassLoader.php'; 
    44stubClassLoader::load('net.stubbles.reflection.reflection', 
    5                       'net.stubbles.reflection.annotations.parser.stubAnnotationParser' 
     5                      'net.stubbles.reflection.annotations.parser.stubAnnotationStateParser' 
    66); 
    77/** 
     
    2121 *            two=2) 
    2222 * @WithTypes(true=true, false=false, integer=4562, 
     23 *            null=null, 
    2324 *            negInt=-13, 
    24  *            string='true', 
     25 *            string1='true', 
     26 *            string2='null', 
    2527 *            class=MyTestClass.class) 
    2628 */ 
     
    3133$clazz       = new ReflectionClass('MyTestClass'); 
    3234$docBlock    = $clazz->getDocComment(); 
    33 $parser      = new stubAnnotationParser(); 
     35$parser      = new stubAnnotationStateParser(); 
    3436$annotations = $parser->parse($docBlock); 
    3537echo '<pre>'; 
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationStateParser.php

    r449 r456  
    88 * @subpackage  reflection_annotations_parser 
    99 */ 
    10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParserState', 
    11                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserAbstractState', 
    12                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserDefaultState', 
    13                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserAnnotationState', 
    14                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserAnnotationNameState', 
    15                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserAnnotationTypeState', 
    16                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserAnnotationParamsState', 
    17                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserAnnotationParamNameState', 
    18                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserAnnotationParamValueState' 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParser', 
     11                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationDocblockState', 
     12                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationAnnotationState', 
     13                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationNameState', 
     14                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationParamNameState', 
     15                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationParamsState', 
     16                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationParamValueState', 
     17                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationTextState', 
     18                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationTypeState' 
    1919); 
    2020/** 
     
    2323 * @package     stubbles 
    2424 * @subpackage  reflection_annotations_parser 
    25  * @todo        improve error handling 
    26  * @todo        write unit tests 
     25 * @todo        write unit test 
    2726 */ 
    28 class stubAnnotationStateParser 
     27class stubAnnotationStateParser implements stubAnnotationParser 
    2928{ 
    3029    /** 
    31      * parser is inside the standard docblock 
    32      */ 
    33     const STATE_DEFAULT         = 0; 
    34     /** 
    35      * parser is inside an annotation 
    36      */ 
    37     const STATE_ANNOTATION      = 1; 
    38     /** 
    39      * parser is inside an annotation name 
    40      */ 
    41     const STATE_ANNOTATION_NAME = 2; 
    42     /** 
    43      * parser is inside an annotation type 
    44      */ 
    45     const STATE_ANNOTATION_TYPE = 3; 
    46     /** 
    47      * parser is inside the annotation params 
    48      */ 
    49     const STATE_PARAMS          = 4; 
    50     /** 
    51      * parser is inside an annotation param nane 
    52      */ 
    53     const STATE_PARAM_NAME      = 5; 
    54     /** 
    55      * parser is inside an annotation param value 
    56      */ 
    57     const STATE_PARAM_VALUE     = 6; 
    58     /** 
    5930     * possible states 
    6031     * 
     
    9263    public function __construct() 
    9364    { 
    94         $this->states[self::STATE_DEFAULT]         = new stubAnnotationParserDefaultState($this); 
    95         $this->states[self::STATE_ANNOTATION]      = new stubAnnotationParserAnnotationState($this); 
    96         $this->states[self::STATE_ANNOTATION_NAME] = new stubAnnotationParserAnnotationNameState($this); 
    97         $this->states[self::STATE_ANNOTATION_TYPE] = new stubAnnotationParserAnnotationTypeState($this); 
    98         $this->states[self::STATE_PARAMS]          = new stubAnnotationParserParamsState($this); 
    99         $this->states[self::STATE_PARAM_NAME]      = new stubAnnotationParserParamNameState($this); 
    100         $this->states[self::STATE_PARAM_VALUE]     = new stubAnnotationParserParamValueState($this); 
     65        $this->states[stubAnnotationState::DOCBLOCK]        = new stubAnnotationDocblockState($this); 
     66        $this->states[stubAnnotationState::TEXT]            = new stubAnnotationTextState($this); 
     67        $this->states[stubAnnotationState::ANNOTATION]      = new stubAnnotationAnnotationState($this); 
     68        $this->states[stubAnnotationState::ANNOTATION_NAME] = new stubAnnotationNameState($this); 
     69        $this->states[stubAnnotationState::ANNOTATION_TYPE] = new stubAnnotationTypeState($this); 
     70        $this->states[stubAnnotationState::PARAMS]          = new stubAnnotationParamsState($this); 
     71        $this->states[stubAnnotationState::PARAM_NAME]      = new stubAnnotationParamNameState($this); 
     72        $this->states[stubAnnotationState::PARAM_VALUE]     = new stubAnnotationParamValueState($this); 
    10173    } 
    10274 
     
    12597     * @param   string  $docBlock 
    12698     * @return  array 
     99     * @throws  ReflectionException 
    127100     */ 
    128101    public function parse($docBlock) 
    129102    { 
    130103        $this->annotations = null; 
    131         $this->changeState(self::STATE_DEFAULT); 
     104        $this->changeState(stubAnnotationState::DOCBLOCK); 
    132105        $len = strlen($docBlock); 
    133106        for ($i = 0; $i < $len; $i++) { 
     
    135108        } 
    136109         
     110        if (($this->currentState instanceof stubAnnotationDocblockState) == false 
     111          && ($this->currentState instanceof stubAnnotationTextState) == false) { 
     112            throw new ReflectionException('Annotation parser finished in wrong state, last annotation probably closed incorrectly, last state was ' . $this->currentState->getClassName()); 
     113        } 
     114         
    137115        return $this->annotations; 
    138116    } 
     
    221199        } 
    222200         
     201        if ('null' === $value || 'NULL' == $value) { 
     202            return null; 
     203        } 
     204         
    223205        if (preg_match('/^[+-]?[0-9]+$/', $value) != false) {            
    224206            return (integer) $value;