Eclipse 5 years later – common formatter quest

It was 5 years ago when I compared IntelliJ IDEA and Eclipse IDE in a series of blog posts (links to all installments at the bottom of that post). I needed to migrate from IDEA to Eclipse, tried it for couple of months and then found out that I actually can go on with IDEA. More than that, couple of years later many other developers used IDEA – some in its free Community edition, others invested into the Ultimate (comparison here).

Today I have different needs – I just want to “develop” formatter for our project that would conform to what we already use in IDEA. I don’t know about any automatic solution. So I’ll install Eclipse, tune its formatter until reformat of the sources produces no differences in my local version of the project and then I’ll just add that formatter into the project for convenience of our Eclipse developers.

Importing Maven project in Eclipse

I went to their download page, downloaded, started the executable and followed the wizard. There were no surprises here, Eclipse Mars.2 started. With File/Import… I imported our Maven project – sure that wizard is overwhelming with all the options, but I handled. Eclipse went on with installing some Maven plugin support. This is unknown for IDEA users – but it’s more a problem of Maven model that doesn’t offer everything for IDE integration, especially when it comes to plugins. It also means that plugins without additional helper for Eclipse are still not properly supported anyway. In any case, it means that Eclipse will invade your POM with some org.eclipse.m2e plugins. Is it bad? Maybe not, Gradle builds also tend to support IDEs explicitly.

Eclipse definitely needed to restart after this step (but you can say no).

SVN support

We use Subversion to manage our sources. I remembered that this was not built-in – and it still is not. Eclipse still has this universal platform feeling, I’m surprised it knows Java and Maven out of the box.

But let’s say Subversion is not that essential. I wasn’t sure how to add this – so I googled. Subversive is the plugin you may try. How do I install it? Help/Install New Software… does the trick. I don’t know why it does not offer some reasonable default in Work with input – this chooses the software repository which is not clear to me at all from that “work with”. I chose an URL ending with releases/mars, typed “subv…” in the next filter field and – waited without any spinner or other notification.

Eventually it indeed found some Subversive plugin…s – many of them actually. I chose Subversive SVN Team Provider, which was the right thing to do. Confirm, OK, license, you know the drill… restart.

But this still does not give you any SVN options, I don’t remember how IDEA detects SVN on the project and just offers it, but I definitely don’t remember any of torturing like this. Let’s try Subversive documentation – I have no problem reading. Or watching Getting started video linked therein. 🙂

And here we go – perspectives! I wonder how other IDEs can do it without reshuffling your whole screen. Whatever, Eclipse == perspectives, let’s live with it. But why should I add repository when the URL to it is already somewhere in the .svn directory in the root of the project? Switching to SVN Repository Exploring perspective, Eclipse asked for SVN connector. Oh, so much flexibility. Let’s use SVN Kit 1.8.11, ok, ok, license, ok. Restart again? No, not this time, let’s wait until it installs more and do it at once. This was wrong decision this time.

I followed the video to add the SVN repository, but it failed not having the connector. Were I not writing this as I go, I’d probably remember I have installed one. 🙂 But I wasn’t sure, maybe I cancelled it, so let’s try SVN Kit, sounds good. It failed with “See error log for details.” Ok, I give up, let’s try Native JavaHL 1.8.14 (also by Polarion). This one works. Restart needed. Oh, … this time I rather really restarted as my mistake dawned on me.

I checked the list of installed software, but SVN plugins don’t seem to be there – this is rather confusing. But if you go to Windows/Preferences, in the tree choose Team/SVN, then tab SVN Connector – there you can find the connectors you can use. Sure I had both of them there. My fault, happy ending.

So I added SVN repository, but as the Getting started video went on, I knew I’m in trouble. It doesn’t say how to associate existing SVN project on my disk with a repo. I found the answer (stackoverflow of course). Where should I right click so that Team menu shows enabled Share project…? In Package explorer of course. I added one project, hooray! Now it shows SVN information next to it. But I noticed there is Share projects…, I don’t want to do it one by one, right? Especially when Eclipse does not show the projects in the natural directory structure (this sucks). I selected it all my projects but Team menu didn’t offer any Share at all now!

Ok, this would throw me out of balance at 20, but now I know that what can go wrong goes wrong. That only project associated with SVN already – I had to deselect to let Eclipse understand what I want. Strictly speaking there is some logic in eliminating that menu item, but as a user I think otherwise. So now we are SVN ready after all!

I updated the project (not using other perspective), no information whether it did something or not – IDEA shows you updated files without getting into your way. Should have used synchronize, I know…

Oh, and it’s lunch time, perfect – I really need a break.

Quick Diff

This one is for free with IDEA, with Eclipse we have to turn it on. It’s that thing showing you changes in a sidebar (or gutter).

Windows/Preferences, filter for “quick” and there you see it under General/Editors/Text Editors. Well it says enabled, but you want to check Show differences in overview ruler too. In my case I want to change colours to IDEA-ish yellow/green/red. (Who came with these Sun/enterprise violetish colours for everything in Eclipse?) What to use as reference source? Well, with IDEA there is no sense for “version on disk” option. I chose SVN Working Copy Base in hope it does what I think it does (shows my actual outgoing changes that are to be committed).

Outgoing changes contain unmanaged files!

Ah yeah, I recall something like this. This is the most stupid aspect of SVN integration – it does not respect how SVN work. After seeing my outgoing changes in Team Synchronizing perspective (probably my least favourite and most confusing one for me) I was really afraid to click on Team/Commit… But as the three dots indicate, there is one more dialog before any damage is done – and only managed files are checked by default. So commit looks good, but disrespect of outgoing changes to the SVN underlying principles is terrible. Eclipse users will tell you to add files to ignore, but that is just workaround – you can then see in the repository all the files people needed to ignore for the sake of stupid team synchronization. Just don’t auto-add unmanaged files, show some respect!

Eclipse Code Style options

With quick diff ready I can finally start tuning my formatter. There are some good news and some bad news. Well, these are no news actually, nothing has changed since 2011. Code Style in IDEA is something you can set up for many languages in IDEA. It also includes imports. In Eclipse when you filter for “format” in Preferences you see Formatter under Java/Code Style and more options for XML/XML Files/Editor. These are completely separated parts and you cannot save them as one bunch. For Imports you have Java/Code Style/Organize Imports.

In my case it doesn’t make sense to use project specific settings. What I change now will become workspace specific, which is OK with me – but only because I don’t want to use Eclipse for any other projects with different settings (that would probably either kill me or I’d have to put them into separate workspaces).

And then we have Java/Code Style/Clean Up configuration (this is what Source/) and Java/Editor/Save Actions to configure and put into project(s) as well. Plenty of stuff you need to take care of separately.

Line wrapping and joining

One of the most important thing we do with our code in terms of readability is line wrapping – and one thing I expect from any formatter is an option that respects my line breaks. Eclipse offers “Never join lines” on Line Wrapping and Comment tab. It seems you have to combine them with “Wrap where necessary” option for most options on Line Wrapping tab, but it still does not allow you to split line arbitrarily – it joins the lines back on reformat, to be precise.

Sometimes I want to say “wrap it HERE” and keep it that way. In IDEA I can wrap before = in assignment or after – and it respects it. I don’t know about any specific line-break/wrapping option for this specific case. Eclipse respects the wrap after, but not the one before – it re-joins the lines in the latter case. Sure I don’t mind, I prefer the break after = as well. But obviously, Eclipse will not respect my line breaks that much as IDEA.

Just to be absolutely clear, I don’t mind when a standalone { is joined to the previous line when rules say so. There are good cases when control structures should be reformatted even when wrapped – but these are cases revolving mostly around parentheses, braces or brackets.

When I investigated around “Never join lines” behaviour I also noticed that people complain about Eclipse Mars formatter when compared to Luna one. Do they rewrite them all the time or do they just make them better? Do they have good tests for them? I don’t know. Sure, formatters are beasts and we all want different things from them.

Exporting Eclipse settings

Let’s say you select top right corner link Configure Project Specific Settings… in particular settings (e.g. Organize Imports). This opens dialog Project Specific Configuration – but do I know what is the scope of it when I select my top-level project? Actually – I don’t even see my top level project (parent POM in our case), only subset of my open projects based on I don’t know what criteria. That is ridiculous.

I ended up exporting settings using Export All… button – but you have to do it separately for whatever section you want. In our case it’s Clean Up, Formatter, Organize Imports and Save Actions. I simply don’t know how to do it better. I’ll add these XML exported configs into SVN, but everybody has to import them manually.

IDEA with its project (where project is really a project in common sense) and modules (which may be Maven “project”, but in fact just a part of the main project) makes much more sense. Also, in IDEA when you copy the code style into the project you feel sure we’re talking about all of the code style. If I add it to our SVN everybody can use it.

You can also export Code Style as XML – but a single one. Or you can export all of IDE settings and choose (to a degree) what portions you want to import. While this is also manual solution you need to do it once with a single exported config.

(This situation is still not that bad as with keybinds where after all these years you still can’t create your own new Scheme in a normal fashion inside the Eclipse IDE.)


Maybe the way of Go language, where formatting is part of the standard toolchain, is the best way – although if it means joining lines anywhere I definitely wouldn’t like it either.

I can bash IDEA formatter a bit too. For me it’s perfectly logical to prefer annotations for fields and methods on separate line, but NOT wrapping them when they are on the same line. Just keep the damn lines a bit different when I want it this way! Something like soft format with prefered way how to do the new code. This is currently not possible all the way. I can set IDEA formatter in such a way that it keeps annotations on separate lines and respects them at the same line as well – but all the new code has annotations by default on the same line.

This concept combining “how I prefer it” with “what I want to keep preserved even if it’s not the way I’d do it” is generally not the way formatters work now. I believe it would be a great way how they should work. This can partially be solved by formatting only changed lines, but that has its own drawbacks – especially when the indentation is not unified yet.


From IntelliJ IDEA to Eclipse (2)

This is hardly a guide, but it may still be useful – or just please random Idea users – whatever. 🙂 This is sort of continuation of my previous rant and I expect more to come when I find out how to do some stuff in Eclipse. All my pros about Eclipse still applies (EMF, plugins, all these corporation doing their own plugins for easier development – there are reasons for this), let’s now see what I really miss or what is different.

If you want to try IntelliJ IDEA (just out of curiosity, if you’re Eclipse users) you can read migration article here. IBM offers their thorough guide for migration to Eclipse here. The biggest terminology mismatch is about workspace, projects and modules – it’s explained in both guides. I didn’t open our Java Simon project in Eclipse yet – maybe then I’d understand it better. Right now I have one workspace with more projects in the “project” sense of the word. In Idea I open one project in one window – as always. So for me project is project. But then I didn’t try to force Eclipse to compile part of the project with one JDK and other with different – maybe then I’d need to break modules to Eclipse projects. However, while it is terminology mess obviously, it’s not the most important thing.

After spending some time with Eclipse you might wanna change editor colours and syntax highlighting. Shame is that there is no obvious way how to save the colour scheme but you should be OK with changing just a few things so it’s less blue/grey only. Quick Diff colours are the first candidates, then maybe comments and Java syntax. Then you may feel more like home and also I just simply see better. Exploration of the Preferences is one of those recommended things to learn about what you can tweak. IF you find it in the first place though – I google a lot regarding how to set this and that in Eclipse. This surely applies for the migration to Idea too.

Formatter in Eclipse may be better configurable (I don’t know, but it seems so from the flood of options) but the overall results are often worse (because of all those options). Ultimately you’ll get what you want though – but settings for XML doesn’t seem to be part of the formatter after all (correct me if I’m wrong). In Idea you have Code Style, you can use global settings or settings for a project and all file types are under Code Style (no formatter bits scattered in the settings tree). While there seems to be no export from GUI in Idea (like in Eclipse) it’s easy to locate code style profile XML files on disk (Idea’s config/codestyles directory somewhere in your homedir) and share them.

There are many concept differences between both IDEs but I don’t care about them that much – as I can hardly do something about them. I can compare editors though. There are some conceptual differences between editors itself too, but in the end it’s about what this one completes and that one doesn’t, etc. As I work more and more with Eclipse, I’m surprised it doesn’t have some (basic?) things. Of course you can always tell him “do this and this”, but Idea often just knows. Now this is not the same as “my Ctrl+Space does it all while you have tons of shortcuts for it”. Yes, sometimes you have to tell Idea “do this” with proper shortcut. But I don’t have to suggest enum type name to complete for instance!

Eclipse doesn’t skip over closing braces/parenthesis if you move the cursor there, but skips nicely right after they are autoinserted. This might be better than Idea’s way actually. I like that Idea gets me out of parentheses, but in many cases I could figure this myself – and often I have real problem to insert new end parenthesis before you open it (so what! I do it from back to start sometimes! :-)). Little note to parentheses highlighting – Idea shows the pair when you’re out, Eclipse when you’re in. Whatever. Idea is better visible – as nearly always.

Recently I discovered Idea’s “Complete Statement” feature (Ctrl+Shift+Enter) – see video here. Not only I found it’s something I missed for years (but just don’t check every missing feature, right?) but it’s also the best way how to emulate “o” command from vi editor (add next line and go to insert mode). These features are missing in Eclipse – at least out of the box.

I mentioned automatic symbol highlighting (or none at all) in my first post – if Eclipse has highlighing on demand it’s not easy to find because none of my colleagues doesn’t know about it. I checked some introduction video for IDEA Community Edition (must see – because every time I learn something new – or forgotten) and I was shocked by automatic highlighting there. I had to open Idea and check how they screwed it, broke it or whatever. Feature is described here. But Idea didn’t let me down. Even with automatic highlighting on you can still stick it with Ctrl+Shift+F7. So you can have best of both worlds – of course on Idea. (At least when we’re talking about highlighting.)

I’ll focus more on keyboard shortcuts in the next episode – how they relate in Idea and Eclipse, what you can and can not expect, etc. Today it’s time to slowly wrap up the article – but we can’t not to mention perspectives, right? 😉

First go about debugging (more to come later!). When you have a warning on a line (light bulb in the gutter), try toggle the breakpoint on that line. Can you see it? I can’t. Luckily I have good colleagues. “You have to go to Debug perspective…” “Ah, different perspective! Of course…” “…and then switch that tab there to Breakpoints and… see? Now you don’t have it on that line. And now you have it there. Easy.” (But yeah, even they were chuckling a bit.)

Eclipse isn’t bad at all of course, I still recall my colleague’s (kinda ironic): “What do you want? It’s for free!” But then, even “smaller” Idea is – and while it lacks a lot of Java EE support, it’s still “Develop with pleasure”. As a final note – when you find yourself stuck with maximized code window (Ctrl+M in Eclipse – and I use it a lot) fighting the Project Explorer that is not docked properly and you don’t know why… just switch from Team Synchronizing to Java perspective. Maybe you’ll get used to it sooner than me.

You can actually say: If something is wrong, it’s probably your (Eclipse) perspective. 🙂

Don’t miss other posts on this topic:
Eclipse vs IntelliJ IDEA
Why to synchronize with SVN in Eclipse?
From IntelliJ IDEA to Eclipse (3)
From IntelliJ IDEA to Eclipse (4)
From IntelliJ IDEA to Eclipse (5)