如何禁止Eclipse 3.5的死代码警告 [英] How do I suppress Eclipse 3.5's warnings of dead code

查看:154
本文介绍了如何禁止Eclipse 3.5的死代码警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用检测电子邮件地址类别,该类使用静态最终布尔配置匹配行为。自从我升级到Eclipse 3.5之后,我收到有关死代码的警告,因为Eclipse通知不能达到一个分支:

  private static final boolean ALLOW_DOMAIN_LITERALS = false; 
private static final String domain = ALLOW_DOMAIN_LITERALS? rfc2822Domain:rfc1035DomainName;

令人高兴的是:

  private static final String domain; 
static {
if(ALLOW_DOMAIN_LITERALS){
domain = rfc2822Domain;
} else {
domain = rfc1035DomainName;
}
}

因为它似乎认可常见的 if(DEBUG) pattern,但是三元运算符似乎没有计数。



既然我不喜欢分类太多只是为了让Eclipse快乐,我宁愿在顶部放一个 @SuppressWarnings ,而不是改变代码。不幸的是,我找不到匹配的一个,除了强力all。是否有一个值用于死码检测?

解决方案

更新:从Adam的评论: / p>

在Eclipse 3.6和更新的Eclipse版本 @SuppressWarnings(unused)现在可以用来压制死代码警告。请参阅 Christopher Stock的答案



另请参见 Eclipse 4.4(Luna)帮助对于@SuppressWarnings。



原始答案:



所有SuppressWarnings值Eclipse 3.5知道列在这个页面。似乎没有任何价值只能抑制新的死码检测。但是您可以在声明之前使用 @SuppressWarnings(all),因此它将仅会抑制警告该行不适用于整个类:

  private static final boolean ALLOW_DOMAIN_LITERALS = false; 
@SuppressWarnings(all)
private static final String domain = ALLOW_DOMAIN_LITERALS? rfc2822Domain:rfc1035DomainName;

因为死码检查是一个新的,您还可以建议在 Eclipse bug数据库,以支持三元操作。


I use a class for detecting email addresses which uses static final booleans to configure the matching behavior. Since I upgraded to Eclipse 3.5 I get warnings about dead code, since Eclipse notices that one branch in this can not be reached:

private static final boolean ALLOW_DOMAIN_LITERALS = false;
private static final String domain = ALLOW_DOMAIN_LITERALS ? rfc2822Domain : rfc1035DomainName;

Oddly enough it is happy with this:

private static final String domain;
static {
    if(ALLOW_DOMAIN_LITERALS) {
        domain = rfc2822Domain;
    } else {
        domain= rfc1035DomainName;
    }
}

since it seems to recognize the common if(DEBUG) pattern, but the ternary operator doesn't seem to count.

Since I'd rather not fork the class too much just to keep Eclipse happy, I'd prefer putting an @SuppressWarnings at the top instead of changing the code. Unfortunately I can't find a matching one apart from the brute-force "all". Is there a value just for the dead code detection?

解决方案

UPDATE: from Adam's comment:

In Eclipse 3.6 and newer Eclipse versions @SuppressWarnings("unused") can now be used to suppress 'dead code' warnings. See Christopher Stock's answer.

See also Eclipse 4.4(Luna) help for @SuppressWarnings.

Original answer:

All SuppressWarnings values Eclipse 3.5 "knows" are listed in this page. It seems that there is no value for suppressing only the new dead-code detection. But you can use the @SuppressWarnings("all") just before the domain declaration so it will suppress warnings for only that line not for the whole class:

private static final boolean ALLOW_DOMAIN_LITERALS = false;
@SuppressWarnings("all") 
private static final String domain = ALLOW_DOMAIN_LITERALS ? rfc2822Domain : rfc1035DomainName;

Because dead code check is a new one you can also suggest an enchancement in the Eclipse bug database for supporting the ternary operation as well.

这篇关于如何禁止Eclipse 3.5的死代码警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆