/**
  * Copies annotations if the @copydoc tag is present.
  *
  * @throws \TokenReflection\Exception\RuntimeException When stuck in an infinite loop when resolving the @copydoc tag.
  */
 private function copyAnnotation()
 {
     self::$copydocStack[] = $this->reflection;
     $broker = $this->reflection->getBroker();
     $parentNames = $this->annotations['copydoc'];
     unset($this->annotations['copydoc']);
     foreach ($parentNames as $parentName) {
         try {
             if ($this->reflection instanceof ReflectionClass) {
                 $parent = $broker->getClass($parentName);
                 if ($parent instanceof Dummy\ReflectionClass) {
                     // The class to copy from is not usable
                     return;
                 }
             } elseif ($this->reflection instanceof ReflectionFunction) {
                 $parent = $broker->getFunction(rtrim($parentName, '()'));
             } elseif ($this->reflection instanceof ReflectionConstant && null === $this->reflection->getDeclaringClassName()) {
                 $parent = $broker->getConstant($parentName);
             } elseif ($this->reflection instanceof ReflectionMethod || $this->reflection instanceof ReflectionProperty || $this->reflection instanceof ReflectionConstant) {
                 if (false !== strpos($parentName, '::')) {
                     list($className, $parentName) = explode('::', $parentName, 2);
                     $class = $broker->getClass($className);
                 } else {
                     $class = $this->reflection->getDeclaringClass();
                 }
                 if ($class instanceof Dummy\ReflectionClass) {
                     // The source element class is not usable
                     return;
                 }
                 if ($this->reflection instanceof ReflectionMethod) {
                     $parent = $class->getMethod(rtrim($parentName, '()'));
                 } elseif ($this->reflection instanceof ReflectionConstant) {
                     $parent = $class->getConstantReflection($parentName);
                 } else {
                     $parent = $class->getProperty(ltrim($parentName, '$'));
                 }
             }
             if (!empty($parent)) {
                 // Don't get into an infinite recursion loop
                 if (in_array($parent, self::$copydocStack, true)) {
                     throw new Exception\RuntimeException('Infinite loop detected when copying annotations using the @copydoc tag.', Exception\RuntimeException::INVALID_ARGUMENT, $this->reflection);
                 }
                 self::$copydocStack[] = $parent;
                 // We can get into an infinite loop here (e.g. when two methods @copydoc from each other)
                 foreach ($parent->getAnnotations() as $name => $value) {
                     // Add annotations that are not already present
                     if (empty($this->annotations[$name])) {
                         $this->annotations[$name] = $value;
                     }
                 }
                 array_pop(self::$copydocStack);
             }
         } catch (Exception\BaseException $e) {
             // Ignoring links to non existent elements, ...
         }
     }
     array_pop(self::$copydocStack);
 }