title: Resolve DeclaredType generics of static method call
body: <p>I'm writing an annotation processor which needs to generate code calling a static method such as <code>Collectors.toList()</code> (full signature: <code>public static &lt;I&gt; Collector&lt;I, ?, List&lt;I&gt;&gt; toList()</code>)</p>
  
  <p>Example input:</p>
  
  <pre class="lang-java prettyprint-override"><code>class Pojo&lt;X&gt; {
    public @CollectWith("Collectors.toList()") List&lt;Thing&lt;X&gt;&gt; things;
  }
  </code></pre>
  
  <p>Snippet of code generated from above:</p>
  
  <pre class="lang-java prettyprint-override"><code>Collector&lt;Thing&lt;X&gt;, ?, List&lt;Thing&lt;X&gt;&gt;&gt; thingsCollector = Collectors.toList();
  </code></pre>
  
  <ul>
  <li>The base return type of the method-call is always <code>Collector&lt;T,A,R&gt;</code></li>
  <li>From the calling context, the code knows <code>R</code> (above it is <code>List&lt;Thing&lt;X&gt;&gt;</code>) </li>
  <li>Type-variables <code>T</code> and <code>A</code> (and <code>I</code>) are not known</li>
  </ul>
  
  <p>Pieces in the puzzle</p>
  
  <pre class="lang-java prettyprint-override"><code>// Lookup specified Collector method
  TypeElement collectors = elements.getTypeElement("java.util.stream.Collectors");
  ExecutableElement toListMethod = findMethod(collectors, "toList"); 
  DeclaredType toListMethodReturnType = (DeclaredType)toListMethod.getReturnType(); // java.util.stream.Collector&lt;T,?,java.util.List&lt;T&gt;&gt;
  
  // R is already known.
  DeclaredType R = ... // java.util.List&lt;Thing&lt;X&gt;&gt;
  </code></pre>
  
  <p>Q: Is there any code which resolves the missing type-variables and can compute the <code>DeclaredType</code> of <code>thingsCollector</code> to be <code>Collector&lt;Thing&lt;X&gt;, ?, List&lt;Thing&lt;X&gt;&gt;&gt;</code>.</p>