Eclipse 3.6 allows you to turn off formatting by placing a special comment, like
// @formatter:off
...
// @formatter:on
The on/off features have to be turned "on" in Eclipse preferences: Java > Code Style > Formatter. Click on Edit, Off/On Tags, enable Enable Off/On tags.
It's also possible to change the magic strings in the preferences — check out the Eclipse 3.6 docs here.
More Information
Java
>
Code Style
>
Formatter
>
Edit
>
Off/On Tags
This preference allows you to define one tag to disable and one tag to enable the formatter (see the Off/On Tags tab in your formatter profile):
You also need to enable the flags from Java Formatting
It's obvious why you'd want to disable this: To force IntelliJ to include each and every import individually. It makes it easier for people to figure out exactly where classes you're using come from.
Click on the Settings "wrench" icon on the toolbar, open "Imports" under "Code Style", and check the "Use single class import" selection. You can also completely remove entries under "Packages to use import with *
", or specify a threshold value that only uses the "*
" when the individual classes from a package exceeds that threshold.
Update: in IDEA 13 "Use single class import" does not prevent wildcard imports. The solution is to go to Preferences
(⌘ + , on macOS / Ctrl + Alt + S on Windows and Linux) > Editor > Code Style > Java > Imports tab
set Class count to use import with '*'
and Names count to use static import with '*'
to a higher value. Any value over 99 seems to work fine.
Best Answer
Since version 13 it's possible to wrap the code with
IntelliJ IDEA v.2018+:
IntelliJ IDEA v.2016+:
IntelliJ IDEA v.14+:
You can change the formatter control markers, as long as they're in comments.
Ensure formatter markers in comments are enabled, as shown in the following figure: