如何禁用Android Studio代码样式警告“...可以简化为...”(How to disable Android Studio code style warning “… can be sim

编程入门 行业动态 更新时间:2024-10-23 04:41:49
如何禁用Android Studio代码样式警告“...可以简化为...”(How to disable Android Studio code style warning “… can be simplified to …”)

我正在使用productFlavors和buildConfigField在我的Android应用程序中启用/禁用功能:

productFlavors {
    vanilla {
        buildConfigField "boolean", "FEATURE_SAR", "false"
    }
    edge {
        applicationIdSuffix ".edge"
        buildConfigField "boolean", "FEATURE_SAR", "true"
    }
}
 

还没有找到一种方法来禁用Android Studio代码样式警告,说''!BuildConfig.FEATURE_SAR'可以简化为'false'“。

正如你在我的代码中看到的,我尝试了很多方法,但都没有成功。 我找不到可以在Android Studio中禁用此设置的设置。

@Override
@SuppressWarnings("SimplifiableIfStatement") // no effect
@SuppressLint("SimplifiableIfStatement")     // no effect
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Set<Integer> suppressPositions = new HashSet<>();

    //noinspection SimplifiableIfStatement <-- no effect
    if (!BuildConfig.FEATURE_SAR) {
        suppressPositions.add(IDX_SAR);
    }

    SimpleAdapter adapter = ViewUtils.createSimpleAdapter(
        getContext(), MENU_RESOURCES, suppressPositions);
    setListAdapter(adapter);
}
 

当然,有些方法可以通过使用资源来解决这个问题,但由于某些原因,我无法在所有情况下使用资源。 所以问题只是如何禁用这些警告,而不是如何更好地处理Android / Gradle中的配置管理。

I'm using productFlavors and buildConfigField to enable/disable features in my Android app:

productFlavors {
    vanilla {
        buildConfigField "boolean", "FEATURE_SAR", "false"
    }
    edge {
        applicationIdSuffix ".edge"
        buildConfigField "boolean", "FEATURE_SAR", "true"
    }
}
 

Haven't found a way to disable Android Studio code style warning saying "'!BuildConfig.FEATURE_SAR' can be simplified to 'false'".

As you can see in my code, I've tried many ways but none of them works. And I cannot find the setting where I can disable this in Android Studio.

@Override
@SuppressWarnings("SimplifiableIfStatement") // no effect
@SuppressLint("SimplifiableIfStatement")     // no effect
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Set<Integer> suppressPositions = new HashSet<>();

    //noinspection SimplifiableIfStatement <-- no effect
    if (!BuildConfig.FEATURE_SAR) {
        suppressPositions.add(IDX_SAR);
    }

    SimpleAdapter adapter = ViewUtils.createSimpleAdapter(
        getContext(), MENU_RESOURCES, suppressPositions);
    setListAdapter(adapter);
}
 

Of course there are ways to get around this by using resources, but for some reasons I cannot use resources in all cases. So the question is only how to disable these warnings, not how to better handle config management in Android/Gradle.

最满意答案

一般情况下,一旦将光标放入警告中,请按ALT + ENTER。 然后放大警告的上下文菜单。 应该有一个条目“禁用检查”显示一个红色的X,如下所示:

例

In general once you put the cursor into the warning press ALT + ENTER. Then enlarge the context-menu of your warning. There should be a entry "Disable Inspection" displayed with a red X as shown here:

Example

更多推荐

本文发布于:2023-08-07 17:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465096.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   代码   Android   Studio   disable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!