Modify

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 gaben)

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 gaben, 17 months ago

Description: modified (diff)

comment:2 by stoecker, 17 months ago

Hmm, you mean in the sources? Actually I would say it is

  • static imports
  • others sorted by name

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 ;-)

comment:3 by gaben, 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:

  1. all static imports
  2. <empty line>
  3. java.*
  4. <empty line>
  5. javax.*
  6. <empty line>
  7. org.openstreetmap.gui.jmapviewer.*
  8. <empty line>
  9. org.openstreetmap.josm
  10. <empty line>
  11. rest of the imports ungrouped

I don't know where to put jakarta.

comment:4 by GerdP, 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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain team.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from team to the specified user.
Next status will be 'needinfo'. The owner will be changed from team to gaben.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. The specified ticket will be cross-referenced with this ticket.
The owner will be changed from team to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.