Changeset 453
- Timestamp:
- 04/02/07 23:40:33 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationAbstractState.php (moved) (moved from trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParserAbstractState.php) (2 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationAnnotationState.php (moved) (moved from trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParserAnnotationState.php) (3 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationDocblockState.php (moved) (moved from trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParserDefaultState.php) (2 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationNameState.php (moved) (moved from trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParserAnnotationNameState.php) (4 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParamNameState.php (moved) (moved from trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParserAnnotationParamNameState.php) (4 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParamValueState.php (moved) (moved from trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParserAnnotationParamValueState.php) (6 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParamsState.php (moved) (moved from trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParserAnnotationParamsState.php) (4 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationState.php (moved) (moved from trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParserState.php) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationTypeState.php (moved) (moved from trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParserAnnotationTypeState.php) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationAbstractState.php
r433 r453 6 6 * @author Frank Kleine <mikey@stubbles.net> 7 7 * @package stubbles 8 * @subpackage reflection_annotations_parser 8 * @subpackage reflection_annotations_parser_state 9 9 */ 10 10 /** … … 12 12 * 13 13 * @package stubbles 14 * @subpackage reflection_annotations_parser 14 * @subpackage reflection_annotations_parser_state 15 15 */ 16 abstract class stubAnnotation ParserAbstractState extends stubBaseObject16 abstract class stubAnnotationAbstractState extends stubBaseObject 17 17 { 18 18 /** trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationAnnotationState.php
r433 r453 6 6 * @author Frank Kleine <mikey@stubbles.net> 7 7 * @package stubbles 8 * @subpackage reflection_annotations_parser 8 * @subpackage reflection_annotations_parser_state 9 9 */ 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.st ubAnnotationParserAbstractState',11 'net.stubbles.reflection.annotations.parser.st ubAnnotationParserState'10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 11 'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 12 12 ); 13 13 /** … … 15 15 * 16 16 * @package stubbles 17 * @subpackage reflection_annotations_parser 17 * @subpackage reflection_annotations_parser_state 18 18 */ 19 class stubAnnotation ParserAnnotationState extends stubAnnotationParserAbstractState implements stubAnnotationParserState19 class stubAnnotationAnnotationState extends stubAnnotationAbstractState implements stubAnnotationState 20 20 { 21 21 /** … … 28 28 switch ($token) { 29 29 case "\n": 30 $this->parser->changeState(stubAnnotation Parser::STATE_DEFAULT);30 $this->parser->changeState(stubAnnotationState::DOCBLOCK); 31 31 break; 32 32 33 33 case '[': 34 $this->parser->changeState(stubAnnotation Parser::STATE_ANNOTATION_TYPE);34 $this->parser->changeState(stubAnnotationState::ANNOTATION_TYPE); 35 35 break; 36 36 37 37 case '(': 38 $this->parser->changeState(stubAnnotation Parser::STATE_PARAMS);38 $this->parser->changeState(stubAnnotationState::PARAMS); 39 39 break; 40 40 } trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationDocblockState.php
r433 r453 1 1 <?php 2 2 /** 3 * D efault state (parser is inside the standard docblock)3 * Docblock state 4 4 * 5 5 * @author Stephan Schmidt <schst@stubbles.net> 6 6 * @author Frank Kleine <mikey@stubbles.net> 7 7 * @package stubbles 8 * @subpackage reflection_annotations_parser 8 * @subpackage reflection_annotations_parser_state 9 9 */ 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.st ubAnnotationParserAbstractState',11 'net.stubbles.reflection.annotations.parser.st ubAnnotationParserState'10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 11 'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 12 12 ); 13 13 /** 14 * D efault state (parser is inside the standard docblock)14 * Docblock state 15 15 * 16 16 * @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 19 18 */ 20 class stubAnnotation ParserDefaultState extends stubAnnotationParserAbstractState implements stubAnnotationParserState19 class stubAnnotationDocblockState extends stubAnnotationAbstractState implements stubAnnotationState 21 20 { 22 21 /** … … 29 28 { 30 29 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); 32 37 } 33 38 } trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationNameState.php
r433 r453 6 6 * @author Frank Kleine <mikey@stubbles.net> 7 7 * @package stubbles 8 * @subpackage reflection_annotations_parser 8 * @subpackage reflection_annotations_parser_state 9 9 */ 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.st ubAnnotationParserAbstractState',11 'net.stubbles.reflection.annotations.parser.st ubAnnotationParserState'10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 11 'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 12 12 ); 13 13 /** … … 15 15 * 16 16 * @package stubbles 17 * @subpackage reflection_annotations_parser 17 * @subpackage reflection_annotations_parser_state 18 18 */ 19 class stubAnnotation ParserAnnotationNameState extends stubAnnotationParserAbstractState implements stubAnnotationParserState19 class stubAnnotationNameState extends stubAnnotationAbstractState implements stubAnnotationState 20 20 { 21 21 /** … … 26 26 private $name = ''; 27 27 28 /** 29 * returns the name of the annotation 30 * 31 * @return string 32 */ 33 public function getName() 34 { 35 return $this->name; 36 } 37 28 38 /** 29 39 * mark this state as the currently used state … … 45 55 switch ($token) { 46 56 case ' ': 57 if (strlen($this->name) == 0) { 58 $this->parser->changeState(stubAnnotationState::DOCBLOCK); 59 break; 60 } 61 47 62 $this->parser->registerAnnotation($this->name); 48 $this->parser->changeState(stubAnnotation Parser::STATE_ANNOTATION);63 $this->parser->changeState(stubAnnotationState::ANNOTATION); 49 64 break; 50 65 51 66 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); 54 72 break; 55 73 56 74 case '[': 75 if (strlen($this->name) == 0) { 76 throw new ReflectionException('Annotation name can not be empty'); 77 } 78 57 79 $this->parser->registerAnnotation($this->name); 58 $this->parser->changeState(stubAnnotation Parser::STATE_ANNOTATION_TYPE);80 $this->parser->changeState(stubAnnotationState::ANNOTATION_TYPE); 59 81 break; 60 82 61 83 case '(': 84 if (strlen($this->name) == 0) { 85 throw new ReflectionException('Annotation name can not be empty'); 86 } 87 62 88 $this->parser->registerAnnotation($this->name); 63 $this->parser->changeState(stubAnnotation Parser::STATE_PARAMS);89 $this->parser->changeState(stubAnnotationState::PARAMS); 64 90 break; 65 91 66 92 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) { 68 94 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) { 70 96 throw new ReflectionException('Annotation name may contain letters, underscores and numbers, but contains ' . $token); 71 97 } trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParamNameState.php
r433 r453 6 6 * @author Frank Kleine <mikey@stubbles.net> 7 7 * @package stubbles 8 * @subpackage reflection_annotations_parser 8 * @subpackage reflection_annotations_parser_state 9 9 */ 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.st ubAnnotationParserAbstractState',11 'net.stubbles.reflection.annotations.parser.st ubAnnotationParserState'10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 11 'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 12 12 ); 13 13 /** … … 15 15 * 16 16 * @package stubbles 17 * @subpackage reflection_annotations_parser 17 * @subpackage reflection_annotations_parser_state 18 18 */ 19 class stubAnnotationPar serParamNameState extends stubAnnotationParserAbstractState implements stubAnnotationParserState19 class stubAnnotationParamNameState extends stubAnnotationAbstractState implements stubAnnotationState 20 20 { 21 21 /** … … 25 25 */ 26 26 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 } 27 37 28 38 /** … … 46 56 case "'": 47 57 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 48 62 $this->parser->registerAnnotationParam('value'); 49 $this->parser->changeState(stubAnnotation Parser::STATE_PARAM_VALUE, $token);63 $this->parser->changeState(stubAnnotationState::PARAM_VALUE, $token); 50 64 break; 51 65 52 66 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 53 71 $this->parser->registerAnnotationParam($this->name); 54 $this->parser->changeState(stubAnnotation Parser::STATE_PARAM_VALUE);72 $this->parser->changeState(stubAnnotationState::PARAM_VALUE); 55 73 break; 56 74 57 75 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); 60 81 break; 61 82 62 83 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) { 64 85 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) { 66 87 throw new ReflectionException('Annotation parameter name may contain letters, underscores and numbers, but contains ' . $token); 67 88 } trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParamValueState.php
r433 r453 6 6 * @author Frank Kleine <mikey@stubbles.net> 7 7 * @package stubbles 8 * @subpackage reflection_annotations_parser 8 * @subpackage reflection_annotations_parser_state 9 9 */ 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.st ubAnnotationParserAbstractState',11 'net.stubbles.reflection.annotations.parser.st ubAnnotationParserState'10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 11 'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 12 12 ); 13 13 /** … … 15 15 * 16 16 * @package stubbles 17 * @subpackage reflection_annotations_parser 17 * @subpackage reflection_annotations_parser_state 18 18 */ 19 class stubAnnotationPar serParamValueState extends stubAnnotationParserAbstractState implements stubAnnotationParserState19 class stubAnnotationParamValueState extends stubAnnotationAbstractState implements stubAnnotationState 20 20 { 21 21 /** 22 * type of quotation marks used22 * character in which the value is enclosed 23 23 * 24 24 * @var string … … 43 43 */ 44 44 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 } 45 85 46 86 /** … … 50 90 { 51 91 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; 55 96 } 56 97 … … 72 113 case "'": 73 114 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 76 122 return; 77 123 78 124 case ',': 79 125 $this->parser->setAnnotationParamValue($this->value, $this->isString); 80 $this->parser->changeState(stubAnnotation Parser::STATE_PARAMS);126 $this->parser->changeState(stubAnnotationState::PARAMS); 81 127 return; 82 128 83 129 case ')': 84 130 $this->parser->setAnnotationParamValue($this->value, $this->isString); 85 $this->parser->changeState(stubAnnotation Parser::STATE_DEFAULT);131 $this->parser->changeState(stubAnnotationState::DOCBLOCK); 86 132 return; 87 133 } … … 91 137 $this->enclosed = null; 92 138 $this->parser->setAnnotationParamValue($this->value, $this->isString); 93 $this->parser->changeState(stubAnnotation Parser::STATE_PARAMS);139 $this->parser->changeState(stubAnnotationState::PARAMS); 94 140 return; 95 141 trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationParamsState.php
r433 r453 6 6 * @author Frank Kleine <mikey@stubbles.net> 7 7 * @package stubbles 8 * @subpackage reflection_annotations_parser 8 * @subpackage reflection_annotations_parser_state 9 9 */ 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.st ubAnnotationParserAbstractState',11 'net.stubbles.reflection.annotations.parser.st ubAnnotationParserState'10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.state.stubAnnotationAbstractState', 11 'net.stubbles.reflection.annotations.parser.state.stubAnnotationState' 12 12 ); 13 13 /** … … 15 15 * 16 16 * @package stubbles 17 * @subpackage reflection_annotations_parser 17 * @subpackage reflection_annotations_parser_state 18 18 */ 19 class stubAnnotationPar serParamsState extends stubAnnotationParserAbstractState implements stubAnnotationParserState19 class stubAnnotationParamsState extends stubAnnotationAbstractState implements stubAnnotationState 20 20 { 21 21 /** … … 28 28 switch ($token) { 29 29 case ')': 30 $this->parser->changeState(stubAnnotation Parser::STATE_DEFAULT);30 $this->parser->changeState(stubAnnotationState::DOCBLOCK); 31 31 break; 32 32 33 33 case ',': 34 $this->parser->changeState(stubAnnotationParser::STATE_PARAMS);35 break;36 37 34 case ' ': 38 35 case "\n": … … 42 39 43 40 default: 44 $this->parser->changeState(stubAnnotation Parser::STATE_PARAM_NAME, $token);41 $this->parser->changeState(stubAnnotationState::PARAM_NAME, $token); 45 42 } 46 43 } trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationState.php
r433 r453 6 6 * @author Frank Kleine <mikey@stubbles.net> 7 7 * @package stubbles 8 * @subpackage reflection_annotations_parser 8 * @subpackage reflection_annotations_parser_state 9 9 */ 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationParser'); 10 11 /** 11 12 * Interface for an annotation parser state 12 13 * 13 14 * @package stubbles 14 * @subpackage reflection_annotations_parser 15 * @subpackage reflection_annotations_parser_state 15 16 */ 16 interface stubAnnotation ParserState17 interface stubAnnotationState 17 18 { 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 18 52 /** 19 53 * constructor trunk/src/main/php/net/stubbles/reflection/annotations/parser/stubAnnotationTypeState.php
r434 r453 6 6 * @author Frank Kleine <mikey@stubbles.net> 7 7 * @package stubbles 8 * @subpackage reflection_annotations_parser 8 * @subpackage reflection_annotations_parser_state 9 9 */ 10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotation ParserAbstractState',11 'net.stubbles.reflection.annotations.parser.stubAnnotation ParserState'10 stubClassLoader::load('net.stubbles.reflection.annotations.parser.stubAnnotationAbstractState', 11 'net.stubbles.reflection.annotations.parser.stubAnnotationState' 12 12 ); 13 13 /** … … 15 15 * 16 16 * @package stubbles 17 * @subpackage reflection_annotations_parser 17 * @subpackage reflection_annotations_parser_state 18 18 */ 19 class stubAnnotation ParserAnnotationTypeState extends stubAnnotationParserAbstractState implements stubAnnotationParserState19 class stubAnnotationTypeState extends stubAnnotationAbstractState implements stubAnnotationState 20 20 { 21 21 /** … … 25 25 */ 26 26 private $type = ''; 27 28 /** 29 * returns the type 30 * 31 * @return string 32 */ 33 public function getType() 34 { 35 return $this->type; 36 } 27 37 28 38 /** … … 44 54 { 45 55 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); 48 61 return; 49 62 } 50 63 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) { 52 65 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) { 54 67 throw new ReflectionException('Annotation type may contain letters, underscores, numbers and dots, but contains ' . $token); 55 68 }
