Opened 17 months ago
Last modified 16 months ago
#23747 new enhancement
Java import order preference
| Reported by: | gaben | Owned by: | team |
|---|---|---|---|
| Priority: | trivial | Milestone: | |
| Component: | Wiki content | Version: | |
| Keywords: | Cc: |
Description (last modified by )
This is a long standing question of mine. What is the import order preference?
There are:
- static imports
- java.*
- javax.*
- org.openstreetmap.*
- jakarta.*
- org.apache.commons.*
- other utility classes mostly in tests
Once we settle on something, I'd like to document it on the DevelopersGuide/StyleGuide. Reason is that, every time I create a new dev env, I forgot what was the import order setting.
Attachments (0)
Change History (4)
comment:1 by , 17 months ago
| Description: | modified (diff) |
|---|
comment:2 by , 17 months ago
comment:3 by , 17 months ago
Yep, in the sources.
Hmm, if'd like to separate major groups by an empty line, I need to specify all the groups which could break the ordering if I don't specify all of them (at least in IntelliJ). The order so far:
- all static imports
- <empty line>
- java.*
- <empty line>
- javax.*
- <empty line>
- org.openstreetmap.gui.jmapviewer.*
- <empty line>
- org.openstreetmap.josm
- <empty line>
- rest of the imports ungrouped
I don't know where to put jakarta.
comment:4 by , 16 months ago
I must say I never really cared because Eclipse adds new imports with its own logic. Sometimes patches contain changes which also reorder the imports and I am sure I didn't do this manually, but maybe I pressed the "Format" or the "Organize Imports" shortcut accidentially.
In short, if you want to establish rules please provide rules for Eclipse and other IDEs.



Hmm, you mean in the sources? Actually I would say it is
Major groups (java, josm, others) are usually separated by an empty line.
Everything else is probably either historic or wrong or maybe also personal style (i.e. having org.openstreetmap above org.apache, simply because it is more important ;-)