/**
  * Parses the token substream and prepares namespace reflections from the file.
  *
  * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream
  * @param \TokenReflection\IReflection       $parent      Parent reflection object
  *
  * @return \TokenReflection\ReflectionFile
  */
 protected function parseStream(Stream $tokenStream, IReflection $parent = null)
 {
     $this->name = $tokenStream->getFileName();
     if (1 >= $tokenStream->count()) {
         // No PHP content
         $this->docComment = new ReflectionAnnotation($this, null);
         return $this;
     }
     $docCommentPosition = null;
     if (!$tokenStream->is(T_OPEN_TAG)) {
         $this->namespaces[] = new ReflectionFileNamespace($tokenStream, $this->broker, $this);
     } else {
         $tokenStream->skipWhitespaces();
         while (null !== ($type = $tokenStream->getType())) {
             switch ($type) {
                 case T_DOC_COMMENT:
                     if (null === $docCommentPosition) {
                         $docCommentPosition = $tokenStream->key();
                     }
                 case T_WHITESPACE:
                 case T_COMMENT:
                     break;
                 case T_DECLARE:
                     // Intentionally twice call of skipWhitespaces()
                     $tokenStream->skipWhitespaces()->findMatchingBracket()->skipWhitespaces()->skipWhitespaces();
                     break;
                 case T_NAMESPACE:
                     $docCommentPosition = $docCommentPosition ?: -1;
                     break 2;
                 default:
                     $docCommentPosition = $docCommentPosition ?: -1;
                     $this->namespaces[] = new ReflectionFileNamespace($tokenStream, $this->broker, $this);
                     break 2;
             }
             $tokenStream->skipWhitespaces();
         }
         while (null !== ($type = $tokenStream->getType())) {
             if (T_NAMESPACE === $type) {
                 $this->namespaces[] = new ReflectionFileNamespace($tokenStream, $this->broker, $this);
             } else {
                 $tokenStream->skipWhitespaces();
             }
         }
     }
     if (null !== $docCommentPosition && !empty($this->namespaces) && $docCommentPosition === $this->namespaces[0]->getStartPosition()) {
         $docCommentPosition = null;
     }
     $this->docComment = new ReflectionAnnotation($this, null !== $docCommentPosition ? $tokenStream->getTokenValue($docCommentPosition) : null);
     return $this;
 }
 /**
  * Returns the processed file name.
  *
  * @return string
  */
 public function getFileName()
 {
     return $this->stream->getFileName();
 }
示例#3
0
 /**
  * Parses the token substream.
  *
  * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream
  * @param \TokenReflection\IReflection $parent Parent reflection object
  */
 protected final function parseStream(Stream $tokenStream, IReflection $parent = null)
 {
     $this->fileName = $tokenStream->getFileName();
     $this->processParent($parent, $tokenStream)->parseStartLine($tokenStream)->parseDocComment($tokenStream, $parent)->parse($tokenStream, $parent)->parseChildren($tokenStream, $parent)->parseEndLine($tokenStream);
 }