Every time I extract method, this line is generated "for me":
@org.jetbrains.annotations.NotNull
around the method. 1. I don't have this on my class path, so it does not compile 2. even if I have, I don't want to include jetbrains annotations in my project. Even if I have more suitable (maybe) javax.validation.constraints.NotNull
annotation on class path, intellij does not use that one.
questions:
The @NotNull annotation is, actually, an explicit contract declaring that: A method should not return null. Variables (fields, local variables, and parameters) cannot hold a null value.
Select a code fragment you want to extract to a method. Press Ctrl+Alt+M or from the main menu, select Refactor | Extract | Method. In the dialog that opens, configure a method options, such as visibility, parameters, and so on. You can also change a name of the method if you need.
Java annotations are pieces of metadata that provide information about the code they are used with, and can instruct the IDE how to process this code. In Java, there is a set of built-in annotations. On top of that, IntelliJ IDEA provides a collection of annotations that are available as a separate project.
The extract method dialog has a Generate annotations
check box. When disabled it does not generate the nullability annotations. The state of this check box is remembered between invocations, so disabling it once is enough.
If this check box does not appear, annotations for the extracted method should not be generated.
It is possible to customize the annotation used in the settings of the Java | Probable bugs | Constant conditions & exceptions
inspection. The configuration dialog looks this:
Use the check mark button, to mark the selected annotation as the one that should be used for code generation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With