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:
how to turn it off entirely?
how to customize, which annotation to use?
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.
I ran into the same problem and was able to fix it by follow these steps :
Go to Settings > Editor > Inspections >
Find Java > Probable Bugs > Nullability Problems > #NotNull/#Nullable Problems
Click Configure Annotations button and check these items
Related
I would like to exclude a specific line (or minimum sized unit) from IntelliJ's clean-up code option. We need to workaround this problem with type inference of exceptions which was fixed in Java 9 but we are stuck in Java 8.
The workaround being cleaned by IntelliJ is given by Oracle in the link:
- return g(f("Hi", MyException.class));
+ return g(this.<String, MyException>f("Hi", MyException.class));
This fix is cleaned up by intellij if you tick clean-up code.
We can push with 'clean-up code' unticked but it has many contributors so someone will eventually tick and undo the fix.
You can define formatter markers: Preferences | Editor | Code Style | Enable formatter markers.
Check Example of using formatting markers
Solved, critically in the code as we do not push changes to our individual IntelliJ configurations.
Alt + Enter on the greyed out generic (the warning)
highlight Remove all type arguments and press right arrow
Suppress for ...
For 'method' an annotation #SuppressWarnings will appear - this is my personal preference.
CLion 2016.2 helpfully detects potential errors in the file you're editing, which can be seen in the validation bar to the right of the code.
That's just a single file though, is there a way (like a tool window) to get a list of all such warnings in the whole project, or specific parts of it?
Bonus points if it also lists warnings and errors from the compiler, though that's less important, because the compiler output already includes any it found.
Yes, it is possible. The feature you are looking for is called the Inspector.
Do: Find Action... | Inspect Code. It will show a pop-up that will allow you to select the scope: file, whole project, custom, and the Inspection profile (you can choose the type of errors you want to see):
After clicking OK, this is an example of the output, that you can navigate with the mouse or with keyboard shortcuts:
In version 2017.2, I have it under Code | Inspect Code....
You can also right click a folder in Project view and select Inspect Code... there to be able to check only that folder.
I am using Intellij IDEA 15.03 on a Mac. One of the first things I do after installing Intellij on a new machine is customize the appearance of the code. This question, in particular, is about the customization of the TODO defaults.
In Editor > Color & Fonts > General, I have the following setting:
This definition, along with some other customizations, is saved under a separate Scheme, say S.
Additionally, under Editor > Inspections, the settings are as shown below:
In my code, however, the white-on-red look that I set up is not showing up, and every TODO comment is simply shown as a warning with the standard yellowed background. The severity setting seems to be overwriting my scheme setting. How do I get the setting shown in the first picture here?
Here is a sample from my code, as is being currently displayed by Intellij IDEA:
You can get the highlighting you want by disabling the "TODO Comment" inspection. The inspection is disabled by default, so you must have enabled it yourself.
As the description shown on your screenshot says, the inspection is intended to be used in batch mode (when you run Analyze | Inspect Code manually), and not for on-the-fly editor highlighting.
I am trying to exclude a particular file in my project from being compiled.
According to the Intellij IDEA documentation you do this by "marking the file as plain text".
However, the context menu in the project view where this functionality is supposedly located has no such action. I am using version 13.02 of Intellij. Here is what my context menu looks like:
Under File > Settings > Build, Execution, Deployment > Compiler > Excludes, add an entry.
Any attempts to run a path specified here will result in a ClassNotFoundException, and a very important class indicator as well.
Just to compound on Makoto's answer (would comment but don't have reputation), it looks like this feature does not apply to classes (.java) or assets (images)...for these types of files, it looks like you will need to actually go to the compiler and explicitly state that the file(s) should be excluded.
However, for .htm, .xml, or really anything that isn't a class or asset you will find and can use the 'Mark as plain text' option.
Edit: It looks like you can also go to the 'Messages Make' error / warnings view and Exclude from there, a little less work IMHO.
The answer that #Makoto has given is pretty much the way to go, but in case that you are like me and you get easily both distracted and frustrated looking for that menu, you could use this shortcut:
press ctrl + shift + a , and in the input box that appears type excludes, and select the first item that appears.
It really annoys me that IntelliJ highlights certain 'errors' (that don't prevent successful compilation) the same way that real errors are highlighted. For example, a magic number is not really an error, but it will be flagged in exactly the same way as an incompatible type error.
How can I change this?
Go to Settings -> Inspections. Then you need to search through the long list for the offending inspection, which you can get the name of by hovering on the warning marker in the margin. You can change the severity of the inspection, whether it's an error, warning, etc. or just disable it altogether.
Edit: if you search for "magic" in Settings, you get the following, which should be helpful:
Whenever you see an inspection warning/error you can place the caret on it and press Alt+Enter (a light bulb also appears that tells you that). A menu will appear with suggested quick fixes. You may need to open a submenu by pressing Right, and you'll find "Edit inspection settings" there. Having invoked that, you may proceed as in hvgotcodes's answer :), it's just a faster way of getting to those settings.
As Michael Calvin said you can use the SuppressWarnings annotation. For example:
#SuppressWarnings("OptionalUsedAsFieldOrParameterType")
See https://github.com/JetBrains/intellij-community/blob/master/plugins/InspectionGadgets/src/inspectionDescriptions/OptionalUsedAsFieldOrParameterType.html
Usually searching the internet for the exact description leads me to this.
Not directly relevant to the OP, but may be of use to future Googlers
I got to this question while trying to figure out how to disable IntelliJ IDEA's warnings about Guava functionalities that have been replaced by Java 8 features. I'm not able to use the Java 8 versions of these features in my case because of a library we're using that was built with Guava (despite being a Java 8 project). So to solve that, I added a SuppressWarnings annotation before any class using Guava:
#SuppressWarnings(Guava)
public final class...