JetBrains / java-annotations

Annotations for JVM-based languages.
Apache License 2.0
404 stars 47 forks source link

[Feature Request] Is it possible add when field for @Nullable #55

Closed kaansonmezoz closed 3 years ago

kaansonmezoz commented 3 years ago

Hello,

Is it possible add when field for @Nullable annotation ?

IDE has already helped me if I miss null checks, but It would be even better If I understood when that null case happened. That way, I can understand when those fields, methods can be null and it will be more informative 🙂

Possible Usage:

public class Car {
   @Nullable(when = "Car is in maintenance'")
   private Engine engine;
}

When the pop-up appears if I miss null check, it can also state when it could be null 🙂

amaembo commented 3 years ago

Nullable has value parameter for this purpose. See https://github.com/JetBrains/java-annotations/blob/7c97da5186dba8c2aca812467cd61600271c55d5/common/src/main/java/org/jetbrains/annotations/Nullable.java#L42