I have a this code somewhere in my Android project:
public boolean isLoadInProgress(boolean privateLoad, boolean publicLoad) {
if (privateLoad && privateLoadInProgress) {
return true;
}
if (publicLoad && publicLoadInProgress) {
return true;
}
return false;
}
I get a lint warning at the second if statement: 'if' statement could be simplified. That's obviously because I could write as well:
return publicLoad && publicLoadInProgress;
However, I would like to keep it this way for readability. I know that there is some inline comment annotation for switching off the lint warning at that place, but I can't find it in the Android Lint documentation. Can you tell me what this annotation/comment was?
To suppress a lint warning with an annotation, add a @SuppressLint("id") annotation on the class, method or variable declaration closest to the warning instance you want to disable.
Current projectPosition your cursor on the if statement and press Alt + Enter . Then choose Simplify > Disable inspection.
android.annotation.SuppressLint. Indicates that Lint should ignore the specified warnings for the annotated element.
If you want to create a new baseline, manually delete the file and run lint again to recreate it. Then, run lint from the IDE (Analyze > Inspect Code) or from the command line as follows. The output prints the location of the lint-baseline. xml file.
The simple code comment for disabling the warning is:
//noinspection SimplifiableIfStatement
This on top of the if-statement should switch off the warning only at that place.
In the example, this would be:
public boolean isLoadInProgress(boolean privateLoad, boolean publicLoad) {
if (privateLoad && privateLoadInProgress) {
return true;
}
//noinspection SimplifiableIfStatement
if (publicLoad && publicLoadInProgress) {
return true;
}
return false;
}
It's not an Android Lint error. You can use:
@SuppressWarnings("RedundantIfStatement")
public static boolean isLoadInProgress(boolean privateLoad, boolean publicLoad) {
if (privateLoad && privateLoadInProgress) {
return true;
}
if (publicLoad && publicLoadInProgress) {
return true;
}
return false;
}
At the highlighted if
, you can use the alt-enter shortcut to open the context menu and select Simplify > Suppress for method
(keeping the scope as small as possible).
You can add @SuppressWarnings("SimplifiableIfStatement")
above your method.
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