I would like to suppress the "Unused declaration" inpection in IntelliJ (2021.1, also tested on 2020.2) for all fields matching a certain pattern. I was able to suppress the warning for methods using the "Code patterns", but fields don't seem to be affected.
Due to project size, I really need to do that with a pattern to avoid adding annotations to every relevant field.
Here is my test class:
public class TestInspection {
public static final String SUPPRESSED_NAME = "test";
public static final String CONSTANT_NAME = "importantConstant";
public void testSuppressedMethod() {
}
public void testMethod() {
}
}
And here are the warnings:
I would like to remove the first warning (Field 'SUPPRESSED_NAME')
Does anyone have any ideas?
Yes, you can annotate the field with @SupressWarnings("unused")
@SuppressWarnings("unused")
public static final String SUPPRESSED_NAME = "test";
As stated in What is the list of valid @SuppressWarnings warning names in Java? you need to check what types of suppressions are available to you based on your environment.