Disable adding of @Nullable annotation

已回答

Hi,

Is there a way to disable the adding of @Nullable annotations? We use Guava, and don't want the noise we get from the @Nullable annotation every time we add an anonymous Function/Predicate,

e.g. Intellij generates this:

        return new Predicate<String>() {
            @Override
            public boolean apply(@javax.annotation.Nullable String input) {
                return input.isEmpty();
            }
        };



which doesn't compile for us as we don't have annotations.jar in our project (and don't particularly want it), and adds unnecessary noise

Cheers,

Jim
0

Hi,
it looks like http://youtrack.jetbrains.com/issue/IDEA-54779 which was fixed for IDEA 10. What is the IDEA version?
Thanks

0
Avatar
Permanently deleted user

We're on the latest and greatest - 11.1

0
Avatar
Permanently deleted user

Thanks Anna - is there a new YouTrack for that?

0

Actually no, I just fixed it yesterday,

0

How, exactly, was this fixed?  I am using IDEA 12.0.3, and the @Nullable annotation is still added when I do a smart complete for a new Function, Predicate, etc.  There needs to be a way to disable this.  I expected to find a template somewhere that I could modify, but I am not seeing one.

0

The initial issue was fixed:
if you don't have a jar available in the classpath - @Nullable/@NotNull annotations won't be added

0
Avatar
Permanently deleted user

IDEA 12.1.1 still having this problem.

0

Alex, what issue do you see? Please provide more details. Thanks

0
Avatar
Permanently deleted user

I am also having this issue when extracting methods.

0

@...

Try the latest 2020.3. The option to add annotations is togglable there:

0

I managed to solve the problem by switching to "In Modal dialogs" and unchecking the option in a modal dialog.

@... How do you do that? What option is that to have a cog?

IntelliJ IDEA 2020.3 (Community Edition)
Build #IC-203.5981.155, built on November 30, 2020
Runtime version: 11.0.9+11-b1145.21 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.4.0-58-generic

0

Adam Wojszczyk

>How do you do that? What option is that to have a cog?

The usual 'Extract Method' refactoring (Ctrl+Alt+M), only you need to add the annotations library first. You can do so by clicking on the @ symbol in the editor gutter on the left.

0

Same problem here, but I don't have any such checkbox (running 2021.2.3 Ultimate):

I have not intentionally added any Jetbrains libraries to my classpath, but I still get @NotNull annotations generated. They might have accidentally ended up on the classpath when switching between environments and projects.

Is there some way to disable this altogether using a global setting?

0

What do you generate? Please share before/after screenshots with annotations added. 

0

I extract a method, and sometimes it gets generated with @NotNull.

Sorry, no screenshots at the moment - it doesn't happen all the time. But judging by the screenshots above, I thought this was the way to disable them. But I don't see any checkbox. 

0

请先登录再写评论。