[2.0][DDC-366] Fixed. Fully qualified names were borked in the lexer as well. Tests didnt catch it because of unfortunate namespace constellations. Fixed now.
This commit is contained in:
parent
b274a69ec2
commit
7badced187
@ -84,6 +84,17 @@ class AnnotationReader
|
|||||||
$this->_parser->setDefaultAnnotationNamespace($defaultNamespace);
|
$this->_parser->setDefaultAnnotationNamespace($defaultNamespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets an alias for an annotation namespace.
|
||||||
|
*
|
||||||
|
* @param $namespace
|
||||||
|
* @param $alias
|
||||||
|
*/
|
||||||
|
public function setAnnotationNamespaceAlias($namespace, $alias)
|
||||||
|
{
|
||||||
|
$this->_parser->setAnnotationNamespaceAlias($namespace, $alias);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the annotations applied to a class.
|
* Gets the annotations applied to a class.
|
||||||
*
|
*
|
||||||
|
@ -57,7 +57,7 @@ class Lexer extends \Doctrine\Common\Lexer
|
|||||||
protected function getCatchablePatterns()
|
protected function getCatchablePatterns()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'[a-z_][a-z0-9_\\\]*',
|
'[a-z_][a-z0-9_:]*',
|
||||||
'(?:[0-9]+(?:[\.][0-9]+)*)(?:e[+-]?[0-9]+)?',
|
'(?:[0-9]+(?:[\.][0-9]+)*)(?:e[+-]?[0-9]+)?',
|
||||||
'"(?:[^"]|"")*"'
|
'"(?:[^"]|"")*"'
|
||||||
);
|
);
|
||||||
|
@ -213,10 +213,12 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation ::= "@" AnnotationName ["(" [Values] ")"]
|
* Annotation ::= "@" AnnotationName ["(" [Values] ")"]
|
||||||
* AnnotationName ::= QualifiedName | SimpleName
|
* AnnotationName ::= QualifiedName | SimpleName | AliasedName
|
||||||
* QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName
|
* QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName
|
||||||
|
* AliasedName ::= Alias ":" SimpleName
|
||||||
* NameSpacePart ::= identifier
|
* NameSpacePart ::= identifier
|
||||||
* SimpleName ::= identifier
|
* SimpleName ::= identifier
|
||||||
|
* Alias ::= identifier
|
||||||
*
|
*
|
||||||
* @return mixed False if it is not a valid Annotation; instance of Annotation subclass otherwise.
|
* @return mixed False if it is not a valid Annotation; instance of Annotation subclass otherwise.
|
||||||
*/
|
*/
|
||||||
@ -228,7 +230,7 @@ class Parser
|
|||||||
$this->match(Lexer::T_AT);
|
$this->match(Lexer::T_AT);
|
||||||
$this->match(Lexer::T_IDENTIFIER);
|
$this->match(Lexer::T_IDENTIFIER);
|
||||||
$nameParts[] = $this->_lexer->token['value'];
|
$nameParts[] = $this->_lexer->token['value'];
|
||||||
|
|
||||||
while ($this->_lexer->isNextToken(Lexer::T_NAMESPACE_SEPARATOR)) {
|
while ($this->_lexer->isNextToken(Lexer::T_NAMESPACE_SEPARATOR)) {
|
||||||
$this->match(Lexer::T_NAMESPACE_SEPARATOR);
|
$this->match(Lexer::T_NAMESPACE_SEPARATOR);
|
||||||
$this->match(Lexer::T_IDENTIFIER);
|
$this->match(Lexer::T_IDENTIFIER);
|
||||||
@ -237,9 +239,12 @@ class Parser
|
|||||||
|
|
||||||
// Effectively pick the name of class (append default NS if none, grab from NS alias, etc)
|
// Effectively pick the name of class (append default NS if none, grab from NS alias, etc)
|
||||||
if (count($nameParts) == 1) {
|
if (count($nameParts) == 1) {
|
||||||
$name = $this->_defaultAnnotationNamespace . $nameParts[0];
|
if (strpos($nameParts[0], ':')) {
|
||||||
} else if (count($nameParts) == 2 && isset($this->_namespaceAliases[$nameParts[0]])) {
|
list ($alias, $simpleName) = explode(':', $nameParts[0]);
|
||||||
$name = $this->_namespaceAliases[$nameParts[0]] . $nameParts[1];
|
$name = $this->_namespaceAliases[$alias] . $simpleName;
|
||||||
|
} else {
|
||||||
|
$name = $this->_defaultAnnotationNamespace . $nameParts[0];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$name = implode('\\', $nameParts);
|
$name = implode('\\', $nameParts);
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,29 @@ DOCBLOCK;
|
|||||||
$parser = $this->createTestParser();
|
$parser = $this->createTestParser();
|
||||||
$parser->parse("@Name(foo='bar')");
|
$parser->parse("@Name(foo='bar')");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group parse
|
||||||
|
*/
|
||||||
|
public function testAnnotationNamespaceAlias()
|
||||||
|
{
|
||||||
|
$parser = new Parser;
|
||||||
|
$parser->setAnnotationNamespaceAlias('Doctrine\Tests\Common\Annotations\\', 'alias');
|
||||||
|
$docblock = <<<DOCBLOCK
|
||||||
|
/**
|
||||||
|
* Some nifty class.
|
||||||
|
*
|
||||||
|
* @author Mr.X
|
||||||
|
* @alias:Name(foo="stuff")
|
||||||
|
*/
|
||||||
|
DOCBLOCK;
|
||||||
|
|
||||||
|
$result = $parser->parse($docblock);
|
||||||
|
$this->assertEquals(1, count($result));
|
||||||
|
$annot = $result['Doctrine\Tests\Common\Annotations\Name'];
|
||||||
|
$this->assertTrue($annot instanceof Name);
|
||||||
|
$this->assertEquals("stuff", $annot->foo);
|
||||||
|
}
|
||||||
|
|
||||||
public function createTestParser()
|
public function createTestParser()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user