How to configure line wrapping for imports in eclipse - eclipse

The eclipse and checkstyle guys of you will surely now this problem: After organizing imports in eclipse with CTRL-SHIFT-o, each import will be on a separate line, without line-wraps.
If you configured checkstyle to warn if you have lines greater than 80 characters, it will probably warn about your imports. Normally I insert newlines at appropriate positions in
the statement and everything is okay. But the next time someone uses the organize imports function of eclipse every import is on one line again.
The auto-linewrap of the eclipse formatter does not work with imports.
So I wonder if there is another way of telling eclipse to linewrap huge import statements?
Or is there a plugin to do this?

Why not defining an exception for the LineLength Checkstyle rule (with the ignorePattern property) ?
That way, any line beginning with import would not raise that warning.
If that is not possible, you will need to define a custom code formatter (see this SO answer)

Related

Stop NetBeans "fixing" imports

How do I stop Netbeans (8.2) automatically "fixing" imports, on every keystroke?
For example,
deleting an import statement halfway through typing the statement [presumably because 'import x' isn't used when you are trying to type 'import x.y' ].
Removing all the imports when I type a ", /*. {, or anything that makes the rest of the program syntactically invalid [presumably because it is "not using" the imports.
It is annoying to have to 'fix-imports' on almost every keystroke, but awful when fix-imports gets it wrong (eg. a program that using java.awt.* and java.util.List, but not java.awt.List)
To be honset I don't get your question exactly. What you describe seems not to be the default behaviour of NetBeans.
From your question it seems that you're writing your imports on your own. This is not necessary. When you want to use an non imported class just use the autocompletion (Ctrl+Space) or organize imports (Ctrl+Shift+i).
I've never had any of the issues that you describe. You might have installed some additional plugins.
The particular plugin that seemed to be causing the problem is
https://github.com/rsmz/AutoSaveModified
It saves every 1 second but that causes imports to be fixed every 1 second.

How do you organize imports in Eclipse with Pydev?

I'm looking for ways to sort and to remove unused imports. Cmd+Shift+O just adds used modules.
(Apologies if this is a duplicate, I really can't find anything non-Java.)
Another two steps method is :
Cmd+Shift+O to sort the existing imports (and may be pull some new ones)
Run Pylint or PyFlakes to spot unused imports
This way you will avoid the trap of PyDev not finding imports.
I don't know a simple way to do this. My approach is two step:
Delete all imports (or comment them out)
Cmd+Shift+O to build a new set of imports
But PyDev can't always figure out which modules you need (especially when you use aliases), so this isn't foolproof. Always make sure you can revert your changes.

How to format AspectJ *.aj files with eclipse

Am I missing something or is it currently not possible to format AspectJ (*.aj) with eclipse built-in formatter?
I'm using eclipse kepler with AJDT-plugin and the formater doesn't do anything with those files. Currently I'm formatting manually.
Thanks in advance
You should be able to use the formatter. There are certain constructs that are not handled well or are just ignored. I can't quite recall, but I believe declare statements are ignored. So, it may be that your file does not contain any formattable code.
Also, check your error log to make sure there are no exceptions being thrown.

Eclipse formatter is not strict?

I use this to set my maximum line width to 80:
org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.lineSplit=80
Let's face it, Eclipse's formatter is not strict.
It has a very high success rate, and format things very nicely indeed, but it is not 100% strict, sometimes it leaves lines > 80 characters and so it is useless for a project that just lints and refuses code not strictly matching the 80 columns limit and requires Eclipse code auto-formatting.
These 2 things, Eclipse-based formatting and lint, can only really work together when the success rate is 100%. If not, even changing the code by hand triggers a "reformat/reflow" on save and the check-in bombs and refuses the commit.
I cannot disable the formatting on the client and I cannot circumvent the linting.
Is there any way at all to just make the wonderful Eclipse formatter 100% strict? Something like "considerTheLimitSeriously=true"?
Notice: it's eminently "unstrict" in lines with method signatures, but not only.
Sorry, there's no way to make the formatter 100% strict when it comes to line splitting. According to JLS 3.8. Identifiers:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
So it's possible that some lines cannot be split without causing a compile error.
The best you can do is set the formatting as strict as possible, then look at specific lines in your code to see where this is failing. On the Eclipse main menu go to Window > Preferences, then go to the Java > Code Style > Formatter tab, then click Edit. There you'll find a Line Wrapping tab where you can customize the line wrapping rules.

Why is Groovy Eclipse's Organize imports putting the package declaration below imports, making my file uncompileable?

Why does the organize imports function in the Groovy Eclipse plug-in put imports above the package declaration and make the file uncompileable? Is there a work-around?
The current version of the plug-in gets confused when there are imbalanced parentheses. The editor itself also becomes less helpful for finding and fixing that kind of error. The solution I found was to open the file in another programming editor (such as emacs) to find the unbalanced pair.