title: Automatically generating Java source code
body: <p>I'm looking for a way to automatically generate source code for new methods within an existing Java source code file, based on the fields defined within the class.</p>
  
  <p>In essence, I'm looking to execute the following steps:</p>
  
  <ol>
  <li>Read and parse <code>SomeClass.java</code></li>
  <li>Iterate through all fields defined in the source code</li>
  <li>Add source code method <code>someMethod()</code></li>
  <li>Save <code>SomeClass.java</code> (Ideally, preserving the formatting of the existing code)</li>
  </ol>
  
  <p>What tools and techniques are best suited to accomplish this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I don't want to generate code at runtime; I want to augment existing Java <em>source code</em></p>