Nick Cardoso
Nick Cardoso

Reputation: 21753

Suppress Inspections for specific Debug class in Android Studio

One of the developers in my team likes to leave Logs in the code constantly. We recently switched to using a debug class to allow us to switch these flows / batches of messages on and off like follows

public class Dbg {
    public static final boolean LOG_FLOW_DEEPLINKS = false;
    public static final boolean LOG_FLOW_IMAGES = true;
    public static final boolean LOG_FLOW_BLOGGER = false;
}

and used like

if (Dbg.LOG_FLOW_DEEPLINKS || Dbg.LOG_FLOW_IMAGES ) Log.v(TAG, ...);

This is good because it gets compiled out completely, the problem is Android Studio is highlighting every one of the usage statements for simplification to (bool).

We want to keep the "...can be simplified to ..." inspections as they help the junior developers, but the amount of things highlighted is distracting. Is there a way through annotations (or other means) to suppress the inspections relating to Dbg across the whole project?

Ive looked here but it wasnt much help as it doesn't tell me what annotations are available

Upvotes: 2

Views: 76

Answers (1)

PhilLab
PhilLab

Reputation: 5007

Boolean.parseBoolean() will do the trick:

public class Dbg {
    public static final boolean LOG_FLOW_DEEPLINKS = Boolean.parseBoolean("false");
    public static final boolean LOG_FLOW_IMAGES = Boolean.parseBoolean("true");
    public static final boolean LOG_FLOW_BLOGGER = Boolean.parseBoolean("false");
}

BTW: This is also done in the automatically generated <yourPackage>.BuildConfig.java file so it is an "official" way to solve the warnings

Upvotes: 1

Related Questions