Changeset 490
- Timestamp:
- 04/13/07 00:37:22 (1 year ago)
- Files:
-
- trunk/docroot/annotationParserTest.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationDocblockState.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationNameState.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationTypeState.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationNameStateTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationTypeStateTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docroot/annotationParserTest.php
r489 r490 143 143 } 144 144 145 $annotationType = self::findAnnotationClass($annotationName, true); 146 if (!is_a($annotation, $annotationType)) { 147 throw new ReflectionException('The annotation: ' . $annotationName . ' is not an instance of ' . $annotationType . '.'); 145 if (self::$annotations[$hash][$annotationName]['type'] != $annotationName) { 146 $annotationType = self::findAnnotationClass($annotationName, true); 147 if (!is_a($annotation, $annotationType)) { 148 throw new ReflectionException('The annotation: ' . $annotationName . ' is not an instance of ' . $annotationType . '.'); 149 } 148 150 } 149 151 … … 155 157 foreach (self::$annotations[$hash][$annotationName]['params'] as $name => $value) { 156 158 if ($refClass->hasMethod('set' . ucfirst($name)) == true) { 157 $refMethod = $refClass->getMethod('set' . ucfirst($name)); 158 if ($refMethod->isPublic() == false || $refMethod->isStatic() == true) { 159 throw new ReflectionException('Annotation value for "' . $name . '" can not be set: setter with this name is static or not public.'); 160 } 161 162 $refMethod->invoke($annotation, $value); 159 $refClass->getMethod('set' . ucfirst($name))->invoke($annotation, $value); 163 160 } elseif ($refClass->hasProperty($name) == true) { 164 $refProperty = $refClass->getProperty($name); 165 if ($refProperty->isPublic() == false || $refProperty->isStatic() == true) { 166 throw new ReflectionException('Annotation value for "' . $name . '" can not be set: property with this name is static or not public.'); 167 } 168 169 $refProperty->setValue($annotation, $value); 161 $refClass->getProperty($name)->setValue($annotation, $value); 170 162 } else { 171 163 throw new ReflectionException('Annotation value for "' . $name . '" can not be set: no public setter and no public property exists with this name.'); trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationDocblockState.php
r454 r490 33 33 34 34 // all character except * and space and line breaks 35 if ( preg_match('/^[^* \n]$/', $token) != false) {35 if (' ' !== $token && '*' !== $token && "\n" !== $token) { 36 36 $this->parser->changeState(stubAnnotationState::TEXT); 37 37 } trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationNameState.php
r488 r490 59 59 } 60 60 61 $this->checkName(); 61 62 $this->parser->registerAnnotation($this->name); 62 63 $this->parser->changeState(stubAnnotationState::ANNOTATION); … … 66 67 if ("\n" === $token) { 67 68 if (strlen($this->name) > 0) { 69 $this->checkName(); 68 70 $this->parser->registerAnnotation($this->name); 69 71 } … … 78 80 } 79 81 82 $this->checkName(); 80 83 $this->parser->registerAnnotation($this->name); 81 84 $this->parser->changeState(stubAnnotationState::ANNOTATION_TYPE); … … 88 91 } 89 92 93 $this->checkName(); 90 94 $this->parser->registerAnnotation($this->name); 91 95 $this->parser->changeState(stubAnnotationState::PARAMS); … … 93 97 } 94 98 95 if (strlen($this->name) == 0 && preg_match('/^[a-zA-Z_]$/', $token) == false) { 96 throw new ReflectionException('Annotation name has to start with a letter or underscore, but starts with ' . $token); 97 } elseif (preg_match('/^[a-zA-Z_0-9]$/', $token) == false) { 98 throw new ReflectionException('Annotation name may contain letters, underscores and numbers, but contains ' . $token); 99 $this->name .= $token; 100 } 101 102 /** 103 * check if the name is valid 104 * 105 * @throws ReflectionException 106 */ 107 protected function checkName() 108 { 109 if (preg_match('/^[a-zA-Z_]{1}[a-zA-Z_0-9]*$/', $this->name) == false) { 110 throw new ReflectionException('Annotation parameter name may contain letters, underscores and numbers, but contains an invalid character.'); 99 111 } 100 101 $this->name .= $token;102 112 } 103 113 } trunk/src/main/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationTypeState.php
r454 r490 55 55 if (']' === $token) { 56 56 if (strlen($this->type) > 0) { 57 if (preg_match('/^[a-zA-Z_]{1}[a-zA-Z_0-9]*$/', $this->type) == false) { 58 throw new ReflectionException('Annotation type may contain letters, underscores and numbers, but contains an invalid character.'); 59 } 60 57 61 $this->parser->setAnnotationType($this->type); 58 62 } … … 62 66 } 63 67 64 if (strlen($this->type) == 0 && preg_match('/^[a-zA-Z_]$/', $token) == false) {65 throw new ReflectionException('Annotation type has to start with a letter or underscore, but starts with ' . $token);66 } elseif (preg_match('/^[a-zA-Z_0-9\.]$/', $token) == false) {67 throw new ReflectionException('Annotation type may contain letters, underscores, numbers and dots, but contains ' . $token);68 }69 70 68 $this->type .= $token; 71 69 } trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationNameStateTestCase.php
r454 r490 97 97 $this->annotationNameState->process('('); 98 98 } 99 100 /** 101 * test processing an illegal character on start of the annotation name 102 */ 103 public function testProcessIllegalCharacterOnStart() 104 { 105 $this->expectException('ReflectionException'); 106 $this->annotationNameState->process('1'); 107 } 108 99 109 100 /** 110 101 * test processing other characters … … 116 107 $this->annotationNameState->process('_'); 117 108 $this->assertEqual($this->annotationNameState->getName(), 'a1_'); 118 109 } 110 111 /** 112 * test processing illegal characters 113 */ 114 public function testProcessIllegalCharactersFollowedBySpace() 115 { 116 $this->annotationNameState->process('a'); 117 $this->annotationNameState->process('1'); 118 $this->annotationNameState->process('_'); 119 119 $this->expectException('ReflectionException'); 120 120 $this->annotationNameState->process(')'); 121 $this->annotationNameState->process(' '); 122 } 123 124 /** 125 * test processing illegal characters 126 */ 127 public function testProcessIllegalCharactersFollowedByLineBreak() 128 { 129 $this->annotationNameState->process('a'); 130 $this->annotationNameState->process('1'); 131 $this->annotationNameState->process('_'); 132 $this->expectException('ReflectionException'); 133 $this->annotationNameState->process(')'); 134 $this->annotationNameState->process("\n"); 135 } 136 137 /** 138 * test processing illegal characters 139 */ 140 public function testProcessIllegalCharactersFollowedByTypeParenthesis() 141 { 142 $this->annotationNameState->process('a'); 143 $this->annotationNameState->process('1'); 144 $this->annotationNameState->process('_'); 145 $this->expectException('ReflectionException'); 146 $this->annotationNameState->process(')'); 147 $this->annotationNameState->process('['); 148 } 149 150 /** 151 * test processing illegal characters 152 */ 153 public function testProcessIllegalCharactersFollowedByValueParenthesis() 154 { 155 $this->annotationNameState->process('a'); 156 $this->annotationNameState->process('1'); 157 $this->annotationNameState->process('_'); 158 $this->expectException('ReflectionException'); 159 $this->annotationNameState->process(')'); 160 $this->annotationNameState->process('('); 121 161 } 122 162 } trunk/src/test/php/net/stubbles/reflection/annotations/parser/state/stubAnnotationTypeStateTestCase.php
r454 r490 54 54 55 55 /** 56 * test processing an illegal character on start of the annotation name57 */58 public function testProcessIllegalCharacterOnStart()59 {60 $this->expectException('ReflectionException');61 $this->annotationTypeState->process('1');62 }63 64 /**65 56 * test processing other characters 66 57 */ … … 74 65 $this->expectException('ReflectionException'); 75 66 $this->annotationTypeState->process(')'); 67 $this->annotationTypeState->process(']'); 76 68 } 77 69 }
