Reputation: 14458
For projects heavily used of Java annotations, is there any suggestion on the annotation order? So as to uniform the code style in the team.
Upvotes: 19
Views: 6872
Reputation: 82589
I'm going to say there's not. I could be proven wrong on this.
My reasoning is there are hundreds of projects that have annotations, in addition to the ones baked into Java, and the ones baked into our IDEs (specifically Eclipse but I'm sure others have them too.)
So, with all these libraries potentially competitng for "whose on top" I doubt they would agree on a standard.
I would encourage your team to sit down and make decisions about what's best for you guys.
Factors I would consider:
Upvotes: 12
Reputation: 39434
Not an exact science but I try to arrange annotations from a "wide scope" at the top to a "narrow scope" at the bottom. Here's an example:
@RadioDomain
@Entity
@Table(name = "receiver")
@ReceiverConstraintCheck
@SuppressWarnings("PMD.ShortVariable")
public class Receiver {
// ...
}
Upvotes: 4
Reputation: 70929
If you must impose an order, alphabetical?
Without some sort of knowledge about the annotations you are using, it's hard to suggest a rational ordering. Perhaps a better ordering would suit you and your team better; and if so, if you document what's the agreed order, the only thing left is to verify it follows the team agreed ordering.
After talking to your whole team, you might find you don't need to order them after all.
Upvotes: 4