i remember there being a way of marking a section of code in eclipse (special comment or annotation?) which made the autoformatter ignore that section. Or I may have drempt this...
Used mainly when I have strings which wrap onto several lines and i don't want the autoformatter to rearrange this.
Since eclipse 3.5 (or 3.6) this is possible: - Go to project properties -- Java Code Style -- Formatter -- Edit... - choose the tab marked "Off/On Tags", - include the tags in comments in your source code, like
/* @formatter:on */
You can wrap the code you don't want auto-formatted between these special comments:
normal code /* @formatter:off */ strangely laid out code /* @formatter:on */ normal code
Here's a basic usage example that makes a json string (slightly) more readable:
public class SomeTest { @Test public void can_deserialize_json() { /* @formatter:off */ String json = "" + "{" + " \"id\" : 123," + " \"address1\" : blah," + " \"shippingInfo\" : {" + " \"trackingUrl\" : null," + " \"price\" : 350" + " }," + " \"errorMessage\" : null" + "}"; /* @formatter:on */ MyClass.deserializeJson(json); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With