title: How to turn off the Eclipse code formatter for certain sections of Java code?
body: <p>I've got some Java code with SQL statements written as Java strings (please no OR/M flamewars, the embedded SQL is what it is - not my decision).</p>
  
  <p>I've broken the SQL statements semantically into several concatenated strings over several lines of code for ease of maintenance. So instead of something like:</p>
  
  <pre><code>String query = "SELECT FOO, BAR, BAZ FROM ABC WHERE BAR &gt; 4";
  </code></pre>
  
  <p>I have something like:</p>
  
  <pre><code>String query =
      "SELECT FOO, BAR, BAZ" +
      "  FROM ABC          " +
      " WHERE BAR &gt; 4      ";
  </code></pre>
  
  <p>This style makes the SQL much easier to read and maintain (IMHO), especially for larger queries. For example, I can put my editor into "overwrite" mode and modify the text in-place fairly easily.</p>
  
  <p><strong>Note that this issue generalizes beyond the particular example of SQL. Any code that is written with any vertical formatting, particularly tabular constructs, is susceptible to destruction by a pretty printer.</strong></p>
  
  <p>Now, some project members use the Eclipse editor and the semantic formatting is often destroyed when they format an entire source file.</p>
  
  <p><strong>Is there a way to instruct Eclipse to ignore certain lines of source with respect to formatting?</strong></p>
  
  <p>I'm looking for something like a special comment that toggles the Eclipse formatter. Ideally, such a comment could be configurable to be whatever we choose, and other formatters could be programmed to respect it as well:</p>
  
  <pre><code>// STOP-ECLIPSE-FORMATTING
  String query =
      "SELECT FOO, BAR, BAZ" +
      "  FROM ABC          " +
      " WHERE BAR &gt; 4      ";
  // START-ECLIPSE-FORMATTING
  </code></pre>
  
  <p>Obviously, one "solution" is to have our team members standardize on some external formatter like <a href="http://www.triemax.com/products/jalopy/" rel="noreferrer">Jalopy</a> or <a href="http://www.jindent.com/" rel="noreferrer">JIndent</a>, but that's not what this question is about (also, not my decision on this project): I'm specifically looking for a way to avoid the Eclipse formatter on an ad-hoc basis.</p>
  
  <p>Ideally, a solution will allow me to insert instructions for the Eclipse formatter <strong>without requiring team members using Eclipse to do any IDE reconfiguration</strong> (other than possibly choosing a formatter agnostic command comment: <code>STOP-ECLIPSE-FORMATTING</code> &rarr; <code>STOP-FORMATTING</code>).</p>