예제 #1
0
 /**
  * Find the appropriate docblock.
  *
  * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream
  * @param \TokenReflection\IReflection $parent Parent reflection
  * @return \TokenReflection\ReflectionElement
  */
 protected function parseDocComment(Stream $tokenStream, IReflection $parent)
 {
     if ($this instanceof ReflectionParameter) {
         $this->docComment = new ReflectionAnnotation($this);
         return $this;
     }
     $position = $tokenStream->key();
     if ($tokenStream->is(T_DOC_COMMENT, $position - 1)) {
         $value = $tokenStream->getTokenValue($position - 1);
         if (self::DOCBLOCK_TEMPLATE_END !== $value) {
             $this->docComment = new ReflectionAnnotation($this, $value);
             $this->startPosition--;
         }
     } elseif ($tokenStream->is(T_DOC_COMMENT, $position - 2)) {
         $value = $tokenStream->getTokenValue($position - 2);
         if (self::DOCBLOCK_TEMPLATE_END !== $value) {
             $this->docComment = new ReflectionAnnotation($this, $value);
             $this->startPosition -= 2;
         }
     } elseif ($tokenStream->is(T_COMMENT, $position - 1) && preg_match('~^' . preg_quote(self::DOCBLOCK_TEMPLATE_START, '~') . '~', $tokenStream->getTokenValue($position - 1))) {
         $this->docComment = new ReflectionAnnotation($this, $tokenStream->getTokenValue($position - 1));
         $this->startPosition--;
     } elseif ($tokenStream->is(T_COMMENT, $position - 2) && preg_match('~^' . preg_quote(self::DOCBLOCK_TEMPLATE_START, '~') . '~', $tokenStream->getTokenValue($position - 2))) {
         $this->docComment = new ReflectionAnnotation($this, $tokenStream->getTokenValue($position - 2));
         $this->startPosition -= 2;
     }
     if (null === $this->docComment) {
         $this->docComment = new ReflectionAnnotation($this);
     }
     if ($parent instanceof ReflectionElement) {
         $this->docComment->setTemplates($parent->getDocblockTemplates());
     }
     return $this;
 }