17

A co-worker on IntelliJ IDEA (working on another project) showed me the amazing @NotNull annotation. I've read messages here on SO about how starting to add @NotNull everywhere saved lots of time and headaches (and IntelliJ 10 can even add automatically @NotNull to old code when it detects that null would wreak havoc).

Since I read my first "Probable @NotNull violation" message (in real-time, in the IDE, even on a partial .java file that doesn't compile yet) my jaw dropped and I got hooked.

So I was wondering: is there anything that needs to be known if we want to start using @NotNull in a project where developers are using both Eclipse and IntelliJ?

I know IntelliJ ships with the annotations.jar. Is this compatible with Eclipse?

Craig P. Motlin
  • 26,452
  • 17
  • 99
  • 126
Gugussee
  • 1,673
  • 3
  • 16
  • 26
  • @duffymo: I know, I know... But I'd still to know how we could use both Eclipse and IntelliJ and still use @NotNull. In a way it's not an issue if Eclipse doesn't warn in real-time about @NotNull probable violations as long as the devs using Eclipse can still use the annotations in their project. It would be great if anyone having experience with this could comment :) But, yup... IntelliJ rocks quite a lot :) – Gugussee Jan 07 '11 at 14:36
  • 4
    There's nothing more frustrating that looking at code developed by someone using Eclipse in IntelliJ. Warning everywhere. – sblundy Jan 07 '11 at 14:52

5 Answers5

6

There is also the possibility to store the annotations outside of the source. Settings > Code Style > Code generation > Use external annotations. The annotations are then stored in an annotations.xml file instead of in the source. That way Eclipse users never have to see the annotations. The location of the annotations.xml can be configured and it is probably best to store the file with the project in version control.

See

http://www.jetbrains.com/idea/webhelp/using-external-annotations.html http://blogs.jetbrains.com/idea/2008/02/external-annotations/

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
  • I remember reading about that at least one year ago but never tried it. Do you know if it mixes well with VCSes and DVCes like Mercurial? I'm kinda concerned for I very often need to jump to another branch, rollback, apply "daggy fixes", etc. – Gugussee Jan 13 '11 at 08:48
4

You can use annotations.jar with Eclipse, but you probably won't get any benefits... See this SO post.

Community
  • 1
  • 1
darioo
  • 46,442
  • 10
  • 75
  • 103
2

You could support both IDEs with FindBugs's @NonNull and related IDE plugins.

Andy Thomas
  • 84,978
  • 11
  • 107
  • 151
1

Findbugs has similar functionality, but the integration is a pale shadow of IntelliJ's built in power.

sblundy
  • 60,628
  • 22
  • 121
  • 123
1

I'd ask why one team doesn't use a common IDE. Why not standardize on one or the other? (You know which one I'd recommend that you go with.)

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • 11
    Because it'll probably end up as Eclipse and no IntelliJ user wants that. – sblundy Jan 07 '11 at 15:05
  • 5
    I've actually seen one company where the people wanted both the Java project development environment *and* the final product to be entirely portable. Their reasoning was that if some devs could work on Windows/Eclipse, others on Linux/Eclipse, others on Mac/IntelliJ, etc. and deployed on, say, both Linux (for example locally) and Solaris (say in preprod and prod), then it meant the project was more likely to be well-designed/architectured/set-up/etc. I think it makes sense. – Gugussee Jan 07 '11 at 15:09
  • I can tell you coming from Mercurial / IntelliJ and having to work in a CVS / Eclipse environment is really sad :( That said a few developers did revolt and set up their own VCS server without telling anyone (do not repeat ;) and only commit to CVS once in a while. – Gugussee Jan 07 '11 at 15:11
  • 1
    SVN/IntelliJ for me. I used Eclipse for a long time and was grateful to have something so good while working for an employer that wouldn't spend for tools. But I haven't gone back since I was first exposed to IntelliJ five years ago. It's simply the best. – duffymo Jan 07 '11 at 15:22