protected function resolveUnqualified($name) {
    if ($this->parent instanceof NamespaceNode) {
      return '\\' . $name;
    }
    if ($this->parent instanceof UseDeclarationNode) {
      return '\\' . $name;
    }
    $namespace = $this->getNamespace();
    $use_declarations = array();
    if ($namespace) {
      $use_declarations = $namespace->getBody()->getUseDeclarations();
    }
    else {
      /** @var \Pharborist\RootNode $root_node */
      $root_node = $this->closest(Filter::isInstanceOf('\Pharborist\RootNode'));
      if ($root_node) {
        $use_declarations = $root_node->getUseDeclarations();
      }
    }
    if ($this->parent instanceof FunctionCallNode) {
      /** @var UseDeclarationNode $use_declaration */
      foreach ($use_declarations as $use_declaration) {
        if ($use_declaration->isFunction() && $use_declaration->getBoundedName() === $name) {
          return '\\' . $use_declaration->getName()->getPath();
        }
      }
      return $this->getParentPath() . $name;
    }
    elseif ($this->parent instanceof ConstantNode) {
      /** @var UseDeclarationNode $use_declaration */
      foreach ($use_declarations as $use_declaration) {
        if ($use_declaration->isConst() && $use_declaration->getBoundedName() === $name) {
          return '\\' . $use_declaration->getName()->getPath();
        }
      }
      return $this->getParentPath() . $name;
    }
    else {
      // Name is a class reference.
      /** @var UseDeclarationNode $use_declaration */
      foreach ($use_declarations as $use_declaration) {
        if ($use_declaration->isClass() && $use_declaration->getBoundedName() === $name) {
          return '\\' . $use_declaration->getName()->getPath();
        }
      }
      // No use declaration so class name refers to class in current namespace.
      return $this->getParentPath() . $name;
    }
  }