Bug 506375 - [null] Allow NonNullByDefault in external library annotation (EEA)
Summary: [null] Allow NonNullByDefault in external library annotation (EEA)
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-21 23:24 EDT by Michael Vorburger CLA
Modified: 2017-10-03 10:37 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Vorburger CLA 2016-10-21 23:24:50 EDT
I believe there would be value in allowing to externally annotate (EEA) a package of a library with @NonNullByDefault.

If this is already possible today and I'm not getting it, could you elaborate how one does this?  I've tried the Ctrl-1 on the package name and keyword declaration in a Some.class, as well as on the package-info.class, and neither do anything.

For example, the Google Guava authors seem to assume @NonNull for most of their code (and they do use @Nullable occasionally), so instead of annotating method after method return value with @NonNull, it would be cool if I could externally annotate their package.  (FYI The Guava packages do have a javax.annotation.ParametersAreNonnullByDefault which one could "interpret" as a secondary annotation for @NonNullByDefault, if though that's not exactly the same semantics.)
Comment 1 Stephan Herrmann CLA 2016-10-23 16:49:43 EDT
Not supported.

I initially assumed, that eea should spell out each annotation individually (which could still be generated by some tool, of course).

I see some room for improvement now, but I'm reluctant to increase the number of lookups needed to read one class.

So, as a compromise I could see a per-class @NNBD stored in an .eea file.
Comment 2 Michael Vorburger CLA 2017-10-03 10:37:36 EDT
> which could still be generated by some tool, of course

Yeah, if JDT core will not add this, then that's another solution to this problem (as it IS a PITA to manually annotate something like Guava or even the JDK...) - a tool which reads e.g. *.java sources, sees a package-info.java with a @NonNullByDefault package, then scans the classpath to find that package, and creates the full EEA for every field and every method in class of that package.

If I have the time, perhaps I'll build this feature into https://github.com/lastnpe/external-annotations-esperanto, some day..

> So, as a compromise I could see a per-class @NNBD stored in an .eea file.

That could be useful as well.