/**
  * Assign queued hooks to functions and update the node stack on leaving a node.
  *
  * We can now access the function/method reflectors, so we can assign any queued
  * hooks to them. The reflector for a node isn't created until the node is left.
  *
  * @param \PHPParser_Node $node
  */
 public function leaveNode(\PHPParser_Node $node)
 {
     parent::leaveNode($node);
     switch ($node->getType()) {
         case 'Stmt_Class':
             $class = end($this->classes);
             if (!empty($this->method_uses_queue)) {
                 /** @var Reflection\ClassReflector\MethodReflector $method */
                 foreach ($class->getMethods() as $method) {
                     if (isset($this->method_uses_queue[$method->getName()])) {
                         if (isset($this->method_uses_queue[$method->getName()]['methods'])) {
                             /*
                              * For methods used in a class, set the class on the method call.
                              * That allows us to later get the correct class name for $this, self, parent.
                              */
                             foreach ($this->method_uses_queue[$method->getName()]['methods'] as $method_call) {
                                 /** @var Method_Call_Reflector $method_call */
                                 $method_call->set_class($class);
                             }
                         }
                         $method->uses = $this->method_uses_queue[$method->getName()];
                     }
                 }
             }
             $this->method_uses_queue = array();
             array_pop($this->location);
             break;
         case 'Stmt_Function':
             end($this->functions)->uses = array_pop($this->location)->uses;
             break;
         case 'Stmt_ClassMethod':
             $method = array_pop($this->location);
             /*
              * Store the list of elements used by this method in the queue. We'll
              * assign them to the method upon leaving the class (see above).
              */
             if (!empty($method->uses)) {
                 $this->method_uses_queue[$method->name] = $method->uses;
             }
             break;
     }
 }