title: scala.meta parent of parent of Defn.Object
body: <p>Let it be the following hierarchy:</p>
  <pre><code>object X extends Y{
  ...
  }
  trait Y extends Z {
  ...
  }
  trait Z {
    def run(): Unit
  }
  </code></pre>
  <p>I parse the scala file containing the <code>X</code> and</p>
  <p>I want to know if its parent or grandparent is <code>Z</code>.</p>
  <p>I can check for parent as follows:
  Given that <code>x: Defn.Object</code> is the <code>X</code> class I parsed,</p>
  <pre><code>x
  .children.collect { case c: Template =&gt; c }
  .flatMap(p =&gt; p.children.collectFirst { case c: Init =&gt; c }
  </code></pre>
  <p>will give <code>Y</code>.</p>
  <p><strong>Question:</strong> Any idea how I can get the parent of the parent of <code>X</code> (which is <code>Z</code> in the above example) ?</p>
  <p>Loading <code>Y</code> (the same way I loaded <code>X</code>) and finding it's parent doesn't seem like a good idea, since the above is part of a scan procedure where among all files under <code>src/main/scala</code> I'm trying to find all classes which extend <code>Z</code> and implement <code>run</code>, so I don't see an easy and performant way to create a graph with all intermediate classes so as to load them in the right order and check for their parents.</p>