title: Eclipse JDT AST parsing returns null when method has a generic type
body: <p>When parsing a method of signature:</p>
  
  <pre><code>&lt;T&gt; T get(int index);
  </code></pre>
  
  <p>called with:</p>
  
  <pre><code>c.&lt;Object&gt;get(1);
  </code></pre>
  
  <p>The MethodInvocation.<a href="http://help.eclipse.org/kepler/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/MethodInvocation.html#resolveMethodBinding()" rel="nofollow noreferrer">resolveMethodBinding()</a> and <a href="http://help.eclipse.org/kepler/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/Expression.html#resolveTypeBinding()" rel="nofollow noreferrer">resolveTypeBinding()</a>, return <code>null</code>.</p>
  
  <p>However, it returns a binding if called with</p>
  
  <pre><code>c.get(1);
  </code></pre>
  
  <p>I need to find a way to have the binding with all scnearios.</p>
  
  <p>The complete case:</p>
  
  <pre><code>public class MyTest {
  
      @Test
      public void test() throws IOException {
          Path path = Paths.get("src/main/java/ab/MyClass.java");
  
          TypeDeclaration typeDeclaration = getTypeDeclaration(path);
          typeDeclaration.accept(new ASTVisitor() {
  
              @Override
              public boolean visit(MethodInvocation node) {
                  System.out.println(node.resolveMethodBinding());
                  System.out.println(node.resolveTypeBinding());
                  return true;
              }
          });
      }
  
      public static TypeDeclaration getTypeDeclaration(Path path) throws IOException {
          ASTParser parser = ASTParser.newParser(AST.JLS9);
          String value = new String(Files.readAllBytes(path), UTF_8);
          parser.setResolveBindings(true);
          parser.setBindingsRecovery(true);
          parser.setSource(value.toCharArray());
          parser.setKind(ASTParser.K_COMPILATION_UNIT);
  
          parser.setCompilerOptions(JavaCore.getOptions());
  
          parser.setUnitName(path.getFileName().toString());
  
          String[] classpathEntries = {};
          String[] sourcepathEntries = { "C:\\test\\src\\main\\java" };
  
          parser.setEnvironment(classpathEntries, sourcepathEntries,
                  new String[] { UTF_8.name() }, true);
  
          final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
  
          return (TypeDeclaration) cu.types().get(0);
      }
  }
  </code></pre>
  
  
  
  <pre><code>public interface SomeInterface {
  
      &lt;T&gt; T get(int index);
  }
  </code></pre>
  
  
  
  <pre><code>public abstract class AbstractClass implements SomeInterface {
  
  }
  </code></pre>
  
  
  
  <pre><code>public class MyClass {
  
      AbstractClass c;
  
      public MyClass() {
          c.&lt;Object&gt;get(1);
      }
  }
  </code></pre>
  
  <p>Similar questions (<a href="https://stackoverflow.com/questions/2017945">2017945</a>, <a href="https://stackoverflow.com/questions/2631981">2631981</a>, <a href="https://stackoverflow.com/questions/12755640">12755640</a>) don't have a relevant answer.</p>