You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change Java coding formatting to standard formatting #770
I've noticed that my code formatting differs from your standard format. Could you please share the Eclipse code format? Otherwise there's a risk we'll get more conflicts/noise when diffing/merging.
That is indeed a problem but here we only use IntelliJ or NetBeans. Probably it would be wise to switch to a more standard format instead of this trouble (?)
We often have dual IDE projects (Eclipse/IntelliJ). So far we've found no way to import code format from IntelliJ into Eclipse. It is, however, possible to import from Eclipse into IntelliJ. There seems to be a some non-official solution for NetBeas as well.
FWIW I always wondered about the "strange" GraphHopper formatting (e.g. with curly brackets).
Meaning why not using the standards, i.e. what Intellij / AS and other IDEs share by default.
The "strange" formatting came in the early days where I found brakets where open and close are in the same column more readable especially for beginners and then it stays as changing this is a bit harder as it breaks pull requests etc
But yes, let us change this now to a more standard thing
I have decided to move to standard Java code formatting provided by IntelliJ and provide some compatible Netbeans settings. All without the Eclipse plugin for now (but nothing decided). The move will happen soonish (after a bigger feature merge into master)
If you're playing with IntelliJ this keymap can be handy.
The Ctrl+Alt+L (Reformat code) on whole folders / modules combined with Ctrl+Alt+O(Optimize imports) helped me organize Mapsforge + VTM repositories. 😄
Currently trying to make NetBeans config to match these IntelliJ default settings. I find some formatting defaults a bit strange e.g. arrays it puts the opening bracket on a new line, and netbeans gets confused by this ... maybe I'll still use netbeans as default config (as one can encode this in the pom.xml) and IntelliJ picks it up correctly anyway now ;) ... but NetBeans does also strange things converting all else { if } clauses into else if {} which might be identical but is really ugly. Oh, yeah ;)
Ok, this procedure is good enough IMO: I'm using now a NetBeans config in the pom.xml which comes very close to the default IntelliJ formatter but improves things a bit.
So the automated configured formatter of IntelliJ should work now although my configuration still forces the style before the change, somehow. Restarting and clearing caches and removing the ~/.Idea-XY folder didn't help. So if you have problems with IntelliJ formatting. Go to File->Settings->Editor->Code Style and deselect 'detect and use existing file indents for editing'. Let me know if you had this problem too.
Interesting that I stumbled over limitations in both IDEs. Generally speaking one can say that NetBeans applies the better defaults and IntelliJ is more fine grained configurable. And formatting is faster with NetBeans.
So now we are using the following simple settings:
Java indent is 4 spaces
Unix line endings (should be handled via git)
Line width is 100 characters (wide enough?)
The rest is left to Java coding standards but disable “auto-format on save” to prevent unnecessary format changes.
Currently we do not care about import section that much, avoid changing it
So if you have problems with IntelliJ formatting. Go to File->Settings->Editor->Code Style and deselect 'detect and use existing file indents for editing'.
I think Ctrl+Alt+L (Reformat code) overcomes that?
Something missing?
You wrote a well defined summary (could be posted in contribution guide too).
Activity
karussell commentedon Aug 17, 2016
That is indeed a problem but here we only use IntelliJ or NetBeans. Probably it would be wise to switch to a more standard format instead of this trouble (?)
highsource commentedon Aug 17, 2016
Or I'd switch to IntelliJ. As far as I know there's no way to import IntelliJ format into Eclipse.
karussell commentedon Aug 17, 2016
I'm really open to switch the format to some more common format as we have e.g. a different setting on the map matching project which is ugly.
karussell commentedon Aug 17, 2016
I'm currently looking how other Java projects are doing this. Of course we can use some post-processing via maven, but I would not rely on this.
karussell commentedon Aug 17, 2016
E.g. ElasticSearch simply relies on some textual guidlines: https://github.com/elastic/elasticsearch/blob/master/CONTRIBUTING.md#contributing-to-the-elasticsearch-codebase
highsource commentedon Aug 17, 2016
We often have dual IDE projects (Eclipse/IntelliJ). So far we've found no way to import code format from IntelliJ into Eclipse. It is, however, possible to import from Eclipse into IntelliJ. There seems to be a some non-official solution for NetBeas as well.
devemux86 commentedon Aug 17, 2016
FWIW I always wondered about the "strange" GraphHopper formatting (e.g. with curly brackets).
Meaning why not using the standards, i.e. what Intellij / AS and other IDEs share by default.
karussell commentedon Aug 17, 2016
The "strange" formatting came in the early days where I found brakets where open and close are in the same column more readable especially for beginners and then it stays as changing this is a bit harder as it breaks pull requests etc
But yes, let us change this now to a more standard thing
Still IntelliJ and NetBeans all have still different default settings so we need to define and share these settings somehow to make reformatting in different IDEs possible. Additionally we could run checkstyle. Maybe one could use @highsource suggestion and use an eclipse format (although I would hate to rely on Eclipse somewhere ;)), e.g. libgdx is doing exactly this https://github.com/libgdx/libgdx/wiki/Contributing#eclipse-formatter
Or just some plan textual guides es ElasticSearch is doing.
@oblonski do you know how we could solve this?
devemux86 commentedon Aug 17, 2016
I'd vote for that, seems indeed more convenient.
FYI in Mapsforge and VTM we use the default Intellij / Android Studio format settings.
karussell commentedon Aug 19, 2016
I have decided to move to standard Java code formatting provided by IntelliJ and provide some compatible Netbeans settings. All without the Eclipse plugin for now (but nothing decided). The move will happen soonish (after a bigger feature merge into master)
Let me know your experiences/ideas etc!
devemux86 commentedon Aug 19, 2016
@karussell 👍
1 remaining item
karussell commentedon Sep 12, 2016
IntelliJ is just too clever. I was fighting with it and did not understand what was going on until I read this here
devemux86 commentedon Sep 12, 2016
If you're playing with IntelliJ this keymap can be handy.
The
Ctrl+Alt+L(Reformat code) on whole folders / modules combined withCtrl+Alt+O(Optimize imports) helped me organize Mapsforge + VTM repositories. 😄karussell commentedon Sep 12, 2016
Yeah, thanks.
Currently trying to make NetBeans config to match these IntelliJ default settings. I find some formatting defaults a bit strange e.g. arrays it puts the opening bracket on a new line, and netbeans gets confused by this ... maybe I'll still use netbeans as default config (as one can encode this in the pom.xml) and IntelliJ picks it up correctly anyway now ;) ... but NetBeans does also strange things converting all
else { if }clauses intoelse if {}which might be identical but is really ugly. Oh, yeah ;)karussell commentedon Sep 12, 2016
Ok, this procedure is good enough IMO: I'm using now a NetBeans config in the pom.xml which comes very close to the default IntelliJ formatter but improves things a bit.
So the automated configured formatter of IntelliJ should work now although my configuration still forces the style before the change, somehow. Restarting and clearing caches and removing the ~/.Idea-XY folder didn't help. So if you have problems with IntelliJ formatting. Go to
File->Settings->Editor->Code Styleand deselect 'detect and use existing file indents for editing'. Let me know if you had this problem too.Interesting that I stumbled over limitations in both IDEs. Generally speaking one can say that NetBeans applies the better defaults and IntelliJ is more fine grained configurable. And formatting is faster with NetBeans.
So now we are using the following simple settings:
Something missing?
use IntelliJ default formatting, slightly corrected manually and via …
devemux86 commentedon Sep 13, 2016
I think
Ctrl+Alt+L(Reformat code) overcomes that?You wrote a well defined summary (could be posted in contribution guide too).
karussell commentedon Sep 13, 2016
This works only if autodetected style is disabled.
TODOs:
define code formatting in contributing, #770
karussell commentedon Sep 13, 2016
Ok, fixed this and closing here for now.
note important change regarding code formatting #770
highsource commentedon Sep 20, 2016
I've started an Eclispe Code Styla Formatter for Graphhopper:
GraphHopper.Formatter.zip
This is based on Eclipse Built-In settings and this comment.
karussell commentedon Sep 20, 2016
@highsource thanks - helpful! Maybe we should link in the contribution guide to this for Eclipse users?
improve test speed via import only once
put code formatting into the root of pom.xml, related to graphhopper/…