예제 #1
0
 /**
  * Parses class modifiers (abstract, final) and class type (class, interface).
  *
  * @param \TokenReflection\Stream\StreamBase $tokenStream Token substream
  * @param \TokenReflection\ReflectionClass $class Defining class
  * @return \TokenReflection\ReflectionClass
  * @throws \TokenReflection\Exception\ParseException If the modifiers value cannot be determined.
  */
 private function parseModifiers(Stream $tokenStream, ReflectionClass $class)
 {
     while (true) {
         switch ($tokenStream->getType()) {
             case T_PUBLIC:
             case T_VAR:
                 $this->modifiers |= InternalReflectionProperty::IS_PUBLIC;
                 break;
             case T_PROTECTED:
                 $this->modifiers |= InternalReflectionProperty::IS_PROTECTED;
                 break;
             case T_PRIVATE:
                 $this->modifiers |= InternalReflectionProperty::IS_PRIVATE;
                 break;
             case T_STATIC:
                 $this->modifiers |= InternalReflectionProperty::IS_STATIC;
                 break;
             default:
                 break 2;
         }
         $tokenStream->skipWhitespaces(true);
     }
     if (InternalReflectionProperty::IS_STATIC === $this->modifiers) {
         $this->modifiers |= InternalReflectionProperty::IS_PUBLIC;
     } elseif (0 === $this->modifiers) {
         $parentProperties = $class->getOwnProperties();
         if (empty($parentProperties)) {
             throw new Exception\ParseException($this, $tokenStream, 'No access level defined and no previous defining class property present.', Exception\ParseException::LOGICAL_ERROR);
         }
         $sibling = array_pop($parentProperties);
         if ($sibling->isPublic()) {
             $this->modifiers = InternalReflectionProperty::IS_PUBLIC;
         } elseif ($sibling->isPrivate()) {
             $this->modifiers = InternalReflectionProperty::IS_PRIVATE;
         } elseif ($sibling->isProtected()) {
             $this->modifiers = InternalReflectionProperty::IS_PROTECTED;
         } else {
             throw new Exception\ParseException($this, $tokenStream, sprintf('Property sibling "%s" has no access level defined.', $sibling->getName()), Exception\Parse::PARSE_ELEMENT_ERROR);
         }
         if ($sibling->isStatic()) {
             $this->modifiers |= InternalReflectionProperty::IS_STATIC;
         }
     }
     return $this;
 }