title: Eclipse text editor get incomplete code AST
body: <p>I am wondering is there a way to get the AST of an incomplete code fragment that the user inputs. For example, lets imagine that the code looks something like this:</p>
  
  <pre><code>String str = "This is some string";
  int length = str.length +
  </code></pre>
  
  <p>Can I get the AST of such code? This is not syntactically correct, but I would still need the AST.</p>
  
  <p>Additionally, would I be able to inject such code into the text editor? Ideally, I would add it as a string, but AST format could do as well.</p>
  
  <p><em>Update 1</em>:</p>
  
  <p>To be precise, would I be able to use the ASTParser in some way so I get something like the following AST for the last line:</p>
  
  <pre><code>          =
        /       \
  decl length    +
               /
          str.length
  </code></pre>
  
  <p><em>Partial Answer</em>:</p>
  
  <p>JDT's <em>ASTParser</em> can be used with <strong>setStatementsRecovery</strong> which will yield the following AST:</p>
  
  <pre><code>         =
        /       \
  decl length    str.length
  </code></pre>
  
  <p>It is not exactly the desired solution, but someone may find it useful, like I did.</p>