Changeset 453

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

refactored states (will be moved to their own subdirectory on next commit)

Files:

Legend:

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

    r433 r453  
    66 * @author      Frank Kleine <mikey@stubbles.net> 
    77 * @package     stubbles 
    8  * @subpackage  reflection_annotations_parser 
     8 * @subpackage  reflection_annotations_parser_state 
    99 */ 
    1010/** 
     
    1212 * 
    1313 * @package     stubbles 
    14  * @subpackage  reflection_annotations_parser 
     14 * @subpackage  reflection_annotations_parser_state 
    1515 */ 
    16 abstract class stubAnnotationParserAbstractState extends stubBaseObject 
     16abstract class stubAnnotationAbstractState extends stubBaseObject 
    1717{ 
    1818    /** 
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationAnnotationState.php

    r433 r453  
    66 * @author      Frank Kleine <mikey@stubbles.net> 
    77 * @package     stubbles 
    8  * @subpackage  reflection_annotations_parser 
     8 * @subpackage  reflection_annotations_parser_state 
    99 */ 
    10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParserAbstractState', 
    11                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserState' 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 
     11                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 
    1212); 
    1313/** 
     
    1515 * 
    1616 * @package     stubbles 
    17  * @subpackage  reflection_annotations_parser 
     17 * @subpackage  reflection_annotations_parser_state 
    1818 */ 
    19 class stubAnnotationParserAnnotationState extends stubAnnotationParserAbstractState implements stubAnnotationParserState 
     19class stubAnnotationAnnotationState extends stubAnnotationAbstractState implements stubAnnotationState 
    2020{ 
    2121    /** 
     
    2828        switch ($token) { 
    2929            case "\n": 
    30                 $this->parser->changeState(stubAnnotationParser::STATE_DEFAULT); 
     30                $this->parser->changeState(stubAnnotationState::DOCBLOCK); 
    3131                break; 
    3232             
    3333            case '[': 
    34                 $this->parser->changeState(stubAnnotationParser::STATE_ANNOTATION_TYPE); 
     34                $this->parser->changeState(stubAnnotationState::ANNOTATION_TYPE); 
    3535                break; 
    3636             
    3737            case '(': 
    38                 $this->parser->changeState(stubAnnotationParser::STATE_PARAMS); 
     38                $this->parser->changeState(stubAnnotationState::PARAMS); 
    3939                break; 
    4040        } 
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationDocblockState.php

    r433 r453  
    11<?php 
    22/** 
    3  * Default state (parser is inside the standard docblock) 
     3 * Docblock state 
    44 * 
    55 * @author      Stephan Schmidt <schst@stubbles.net> 
    66 * @author      Frank Kleine <mikey@stubbles.net> 
    77 * @package     stubbles 
    8  * @subpackage  reflection_annotations_parser 
     8 * @subpackage  reflection_annotations_parser_state 
    99 */ 
    10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParserAbstractState', 
    11                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserState' 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 
     11                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 
    1212); 
    1313/** 
    14  * Default state (parser is inside the standard docblock) 
     14 * Docblock state 
    1515 * 
    1616 * @package     stubbles 
    17  * @subpackage  reflection_annotations_parser 
    18  * @todo        do not allow annotations inside text, only at the beginnging of a new line 
     17 * @subpackage  reflection_annotations_parser_state 
    1918 */ 
    20 class stubAnnotationParserDefaultState extends stubAnnotationParserAbstractState implements stubAnnotationParserState 
     19class stubAnnotationDocblockState extends stubAnnotationAbstractState implements stubAnnotationState 
    2120{ 
    2221    /** 
     
    2928    { 
    3029        if ('@' === $token) { 
    31             $this->parser->changeState(stubAnnotationParser::STATE_ANNOTATION_NAME); 
     30            $this->parser->changeState(stubAnnotationState::ANNOTATION_NAME); 
     31            return; 
     32        } 
     33         
     34        // all character except * and space and line breaks 
     35        if (preg_match('/^[^* \n]$/', $token) != false) { 
     36            $this->parser->changeState(stubAnnotationState::TEXT); 
    3237        } 
    3338    } 
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationNameState.php

    r433 r453  
    66 * @author      Frank Kleine <mikey@stubbles.net> 
    77 * @package     stubbles 
    8  * @subpackage  reflection_annotations_parser 
     8 * @subpackage  reflection_annotations_parser_state 
    99 */ 
    10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParserAbstractState', 
    11                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserState' 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 
     11                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 
    1212); 
    1313/** 
     
    1515 * 
    1616 * @package     stubbles 
    17  * @subpackage  reflection_annotations_parser 
     17 * @subpackage  reflection_annotations_parser_state 
    1818 */ 
    19 class stubAnnotationParserAnnotationNameState extends stubAnnotationParserAbstractState implements stubAnnotationParserState 
     19class stubAnnotationNameState extends stubAnnotationAbstractState implements stubAnnotationState 
    2020{ 
    2121    /** 
     
    2626    private $name = ''; 
    2727 
     28    /** 
     29     * returns the name of the annotation 
     30     * 
     31     * @return  string 
     32     */ 
     33    public function getName() 
     34    { 
     35        return $this->name; 
     36    } 
     37     
    2838    /** 
    2939     * mark this state as the currently used state 
     
    4555        switch ($token) { 
    4656            case ' ': 
     57                if (strlen($this->name) == 0) { 
     58                    $this->parser->changeState(stubAnnotationState::DOCBLOCK); 
     59                    break; 
     60                } 
     61                 
    4762                $this->parser->registerAnnotation($this->name); 
    48                 $this->parser->changeState(stubAnnotationParser::STATE_ANNOTATION); 
     63                $this->parser->changeState(stubAnnotationState::ANNOTATION); 
    4964                break; 
    5065             
    5166            case "\n": 
    52                 $this->parser->registerAnnotation($this->name); 
    53                 $this->parser->changeState(stubAnnotationParser::STATE_DEFAULT); 
     67                if (strlen($this->name) > 0) { 
     68                    $this->parser->registerAnnotation($this->name); 
     69                } 
     70                 
     71                $this->parser->changeState(stubAnnotationState::DOCBLOCK); 
    5472                break; 
    5573             
    5674            case '[': 
     75                if (strlen($this->name) == 0) { 
     76                    throw new ReflectionException('Annotation name can not be empty'); 
     77                } 
     78                 
    5779                $this->parser->registerAnnotation($this->name); 
    58                 $this->parser->changeState(stubAnnotationParser::STATE_ANNOTATION_TYPE); 
     80                $this->parser->changeState(stubAnnotationState::ANNOTATION_TYPE); 
    5981                break; 
    6082             
    6183            case '(': 
     84                if (strlen($this->name) == 0) { 
     85                    throw new ReflectionException('Annotation name can not be empty'); 
     86                } 
     87                 
    6288                $this->parser->registerAnnotation($this->name); 
    63                 $this->parser->changeState(stubAnnotationParser::STATE_PARAMS); 
     89                $this->parser->changeState(stubAnnotationState::PARAMS); 
    6490                break; 
    6591             
    6692            default: 
    67                 if (strlen($this->name) == 0 && preg_match('/^[a-zA-Z_]$/', $token) === false) { 
     93                if (strlen($this->name) == 0 && preg_match('/^[a-zA-Z_]$/', $token) == false) { 
    6894                    throw new ReflectionException('Annotation name has to start with a letter or underscore, but starts with ' . $token); 
    69                 } elseif (preg_match('/^[a-zA-Z_0-9]$/', $token) === false) { 
     95                } elseif (preg_match('/^[a-zA-Z_0-9]$/', $token) == false) { 
    7096                    throw new ReflectionException('Annotation name may contain letters, underscores and numbers, but contains ' . $token); 
    7197                } 
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParamNameState.php

    r433 r453  
    66 * @author      Frank Kleine <mikey@stubbles.net> 
    77 * @package     stubbles 
    8  * @subpackage  reflection_annotations_parser 
     8 * @subpackage  reflection_annotations_parser_state 
    99 */ 
    10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParserAbstractState', 
    11                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserState' 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 
     11                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 
    1212); 
    1313/** 
     
    1515 * 
    1616 * @package     stubbles 
    17  * @subpackage  reflection_annotations_parser 
     17 * @subpackage  reflection_annotations_parser_state 
    1818 */ 
    19 class stubAnnotationParserParamNameState extends stubAnnotationParserAbstractState implements stubAnnotationParserState 
     19class stubAnnotationParamNameState extends stubAnnotationAbstractState implements stubAnnotationState 
    2020{ 
    2121    /** 
     
    2525     */ 
    2626    private $name = ''; 
     27 
     28    /** 
     29     * returns the name of the annotation 
     30     * 
     31     * @return  string 
     32     */ 
     33    public function getName() 
     34    { 
     35        return $this->name; 
     36    } 
    2737 
    2838    /** 
     
    4656            case "'": 
    4757            case '"': 
     58                if (strlen($this->name) > 0) { 
     59                    throw new ReflectionException('Annotation parameter name may contain letters, underscores and numbers, but contains ' . $token . '. Probably an equal sign is missing.'); 
     60                } 
     61                 
    4862                $this->parser->registerAnnotationParam('value'); 
    49                 $this->parser->changeState(stubAnnotationParser::STATE_PARAM_VALUE, $token); 
     63                $this->parser->changeState(stubAnnotationState::PARAM_VALUE, $token); 
    5064                break; 
    5165             
    5266            case '=': 
     67                if (strlen($this->name) == 0) { 
     68                    throw new ReflectionException('Annotation parameter name has to start with a letter or underscore, but starts with ='); 
     69                } 
     70                 
    5371                $this->parser->registerAnnotationParam($this->name); 
    54                 $this->parser->changeState(stubAnnotationParser::STATE_PARAM_VALUE); 
     72                $this->parser->changeState(stubAnnotationState::PARAM_VALUE); 
    5573                break; 
    5674             
    5775            case ')': 
    58                 $this->parser->registerSingleAnnotationParam($this->name, false); 
    59                 $this->parser->changeState(stubAnnotationParser::STATE_DEFAULT); 
     76                if (strlen($this->name) > 0) { 
     77                    $this->parser->registerSingleAnnotationParam($this->name, false); 
     78                } 
     79                                 
     80                $this->parser->changeState(stubAnnotationState::DOCBLOCK); 
    6081                break; 
    6182                 
    6283            default: 
    63                 if (strlen($this->name) == 0 && preg_match('/^[a-zA-Z_]$/', $token) === false) { 
     84                if (strlen($this->name) == 0 && preg_match('/^[a-zA-Z_]$/', $token) == false) { 
    6485                    throw new ReflectionException('Annotation parameter name has to start with a letter or underscore, but starts with ' . $token); 
    65                 } elseif (preg_match('/^[a-zA-Z_0-9]$/', $token) === false) { 
     86                } elseif (preg_match('/^[a-zA-Z_0-9]$/', $token) == false) { 
    6687                    throw new ReflectionException('Annotation parameter name may contain letters, underscores and numbers, but contains ' . $token); 
    6788                } 
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParamValueState.php

    r433 r453  
    66 * @author      Frank Kleine <mikey@stubbles.net> 
    77 * @package     stubbles 
    8  * @subpackage  reflection_annotations_parser 
     8 * @subpackage  reflection_annotations_parser_state 
    99 */ 
    10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParserAbstractState', 
    11                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserState' 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 
     11                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 
    1212); 
    1313/** 
     
    1515 * 
    1616 * @package     stubbles 
    17  * @subpackage  reflection_annotations_parser 
     17 * @subpackage  reflection_annotations_parser_state 
    1818 */ 
    19 class stubAnnotationParserParamValueState extends stubAnnotationParserAbstractState implements stubAnnotationParserState 
     19class stubAnnotationParamValueState extends stubAnnotationAbstractState implements stubAnnotationState 
    2020{ 
    2121    /** 
    22      * type of quotation marks used 
     22     * character in which the value is enclosed 
    2323     * 
    2424     * @var  string 
     
    4343     */ 
    4444    private $escapeNext = false; 
     45     
     46    /** 
     47     * returns the value 
     48     * 
     49     * @return  string 
     50     */ 
     51    public function getValue() 
     52    { 
     53        return $this->value; 
     54    } 
     55     
     56    /** 
     57     * checks whether the value is a string or not 
     58     * 
     59     * @return  bool 
     60     */ 
     61    public function isString() 
     62    { 
     63        return $this->isString; 
     64    } 
     65     
     66    /** 
     67     * checks if the next token is escaped 
     68     * 
     69     * @return  bool 
     70     */ 
     71    public function isNextCharacterEscaped() 
     72    { 
     73        return $this->escapeNext; 
     74    } 
     75     
     76    /** 
     77     * returns the character in which the value is enclosed 
     78     * 
     79     * @return  string 
     80     */ 
     81    public function getEnclosed() 
     82    { 
     83        return $this->enclosed; 
     84    } 
    4585 
    4686    /** 
     
    5090    { 
    5191        parent::selected(); 
    52         $this->value    = ''; 
    53         $this->enclosed = null; 
    54         $this->isString = false; 
     92        $this->value      = ''; 
     93        $this->enclosed   = null; 
     94        $this->isString   = false; 
     95        $this->escapeNext = false; 
    5596    } 
    5697 
     
    72113                case "'": 
    73114                case '"': 
    74                     $this->enclosed = $token; 
    75                     $this->isString = true; 
     115                    if (strlen($this->value) > 0) { 
     116                        $this->value .= $token; 
     117                    } else { 
     118                        $this->enclosed = $token; 
     119                        $this->isString = true; 
     120                    } 
     121                     
    76122                    return; 
    77123                 
    78124                case ',': 
    79125                    $this->parser->setAnnotationParamValue($this->value, $this->isString); 
    80                     $this->parser->changeState(stubAnnotationParser::STATE_PARAMS); 
     126                    $this->parser->changeState(stubAnnotationState::PARAMS); 
    81127                    return; 
    82128                 
    83129                case ')': 
    84130                    $this->parser->setAnnotationParamValue($this->value, $this->isString); 
    85                     $this->parser->changeState(stubAnnotationParser::STATE_DEFAULT); 
     131                    $this->parser->changeState(stubAnnotationState::DOCBLOCK); 
    86132                    return; 
    87133            } 
     
    91137                    $this->enclosed = null; 
    92138                    $this->parser->setAnnotationParamValue($this->value, $this->isString); 
    93                     $this->parser->changeState(stubAnnotationParser::STATE_PARAMS); 
     139                    $this->parser->changeState(stubAnnotationState::PARAMS); 
    94140                    return; 
    95141                 
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParamsState.php

    r433 r453  
    66 * @author      Frank Kleine <mikey@stubbles.net> 
    77 * @package     stubbles 
    8  * @subpackage  reflection_annotations_parser 
     8 * @subpackage  reflection_annotations_parser_state 
    99 */ 
    10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParserAbstractState', 
    11                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserState' 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 
     11                      'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 
    1212); 
    1313/** 
     
    1515 * 
    1616 * @package     stubbles 
    17  * @subpackage  reflection_annotations_parser 
     17 * @subpackage  reflection_annotations_parser_state 
    1818 */ 
    19 class stubAnnotationParserParamsState extends stubAnnotationParserAbstractState implements stubAnnotationParserState 
     19class stubAnnotationParamsState extends stubAnnotationAbstractState implements stubAnnotationState 
    2020{ 
    2121    /** 
     
    2828        switch ($token) { 
    2929            case ')': 
    30                 $this->parser->changeState(stubAnnotationParser::STATE_DEFAULT); 
     30                $this->parser->changeState(stubAnnotationState::DOCBLOCK); 
    3131                break; 
    3232             
    3333            case ',': 
    34                 $this->parser->changeState(stubAnnotationParser::STATE_PARAMS); 
    35                 break; 
    36              
    3734            case ' ': 
    3835            case "\n": 
     
    4239                 
    4340            default: 
    44                 $this->parser->changeState(stubAnnotationParser::STATE_PARAM_NAME, $token); 
     41                $this->parser->changeState(stubAnnotationState::PARAM_NAME, $token); 
    4542        } 
    4643    } 
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationState.php

    r433 r453  
    66 * @author      Frank Kleine <mikey@stubbles.net> 
    77 * @package     stubbles 
    8  * @subpackage  reflection_annotations_parser 
     8 * @subpackage  reflection_annotations_parser_state 
    99 */ 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParser'); 
    1011/** 
    1112 * Interface for an annotation parser state 
    1213 * 
    1314 * @package     stubbles 
    14  * @subpackage  reflection_annotations_parser 
     15 * @subpackage  reflection_annotations_parser_state 
    1516 */ 
    16 interface stubAnnotationParserState 
     17interface stubAnnotationState 
    1718{ 
     19    /** 
     20     * parser is inside the standard docblock 
     21     */ 
     22    const DOCBLOCK        = 0; 
     23    /** 
     24     * parser is inside a text within the docblock 
     25     */ 
     26    const TEXT            = 1; 
     27    /** 
     28     * parser is inside an annotation 
     29     */ 
     30    const ANNOTATION      = 2; 
     31    /** 
     32     * parser is inside an annotation name 
     33     */ 
     34    const ANNOTATION_NAME = 3; 
     35    /** 
     36     * parser is inside an annotation type 
     37     */ 
     38    const ANNOTATION_TYPE = 4; 
     39    /** 
     40     * parser is inside the annotation params 
     41     */ 
     42    const PARAMS          = 5; 
     43    /** 
     44     * parser is inside an annotation param name 
     45     */ 
     46    const PARAM_NAME      = 6; 
     47    /** 
     48     * parser is inside an annotation param value 
     49     */ 
     50    const PARAM_VALUE     = 7; 
     51 
    1852    /** 
    1953     * constructor 
  • trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationTypeState.php

    r434 r453  
    66 * @author      Frank Kleine <mikey@stubbles.net> 
    77 * @package     stubbles 
    8  * @subpackage  reflection_annotations_parser 
     8 * @subpackage  reflection_annotations_parser_state 
    99 */ 
    10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParserAbstractState', 
    11                       'net.stubbles.reflection.annotations.parser.stubAnnotationParserState' 
     10stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationAbstractState', 
     11                      'net.stubbles.reflection.annotations.parser.stubAnnotationState' 
    1212); 
    1313/** 
     
    1515 * 
    1616 * @package     stubbles 
    17  * @subpackage  reflection_annotations_parser 
     17 * @subpackage  reflection_annotations_parser_state 
    1818 */ 
    19 class stubAnnotationParserAnnotationTypeState extends stubAnnotationParserAbstractState implements stubAnnotationParserState 
     19class stubAnnotationTypeState extends stubAnnotationAbstractState implements stubAnnotationState 
    2020{ 
    2121    /** 
     
    2525     */ 
    2626    private $type = ''; 
     27 
     28    /** 
     29     * returns the type 
     30     * 
     31     * @return  string 
     32     */ 
     33    public function getType() 
     34    { 
     35        return $this->type; 
     36    } 
    2737 
    2838    /** 
     
    4454    { 
    4555        if (']' === $token) { 
    46             $this->parser->setAnnotationType($this->type); 
    47             $this->parser->changeState(stubAnnotationParser::STATE_ANNOTATION); 
     56            if (strlen($this->type) > 0) { 
     57                $this->parser->setAnnotationType($this->type); 
     58            } 
     59             
     60            $this->parser->changeState(stubAnnotationState::ANNOTATION); 
    4861            return; 
    4962        } 
    5063 
    51         if (strlen($this->type) == 0 && preg_match('/^[a-zA-Z_]$/', $token) === false) { 
     64        if (strlen($this->type) == 0 && preg_match('/^[a-zA-Z_]$/', $token) == false) { 
    5265            throw new ReflectionException('Annotation type has to start with a letter or underscore, but starts with ' . $token); 
    53         } elseif (preg_match('/^[a-zA-Z_0-9\.]$/', $token) === false) { 
     66        } elseif (preg_match('/^[a-zA-Z_0-9\.]$/', $token) == false) { 
    5467            throw new ReflectionException('Annotation type may contain letters, underscores, numbers and dots, but contains ' . $token); 
    5568        }