@IntDef从其他的code注释和返回值不能注释或如何暂时影响code禁止标注? [英] @IntDef annotation and return value from other's code that cannot be annotated or how to temporarily disable annotation from affecting the code?

查看:375
本文介绍了@IntDef从其他的code注释和返回值不能注释或如何暂时影响code禁止标注?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 IntDef 从的在我的code Android的支持注释(但我的问题是在更广泛的范围内,请继续阅读:)是这样的:

I am using IntDef from Android Support annotation in my code (but my question is wider in scope so please keep reading :) like this:

public class UiLockMode
{
    @IntDef({DEFAULT, NONE, VISIBLE, TRANSPARENT})
    @Retention(RetentionPolicy.SOURCE)
    public @interface AllowedValues {}

    public static final int DEFAULT     = 0;
    public static final int NONE        = 1;
    public static final int VISIBLE     = 2;
    public static final int TRANSPARENT = 3;
}

接下来,我用它注解像这样的一些其他的方法:

Next, I got some other methods annotated with it like this:

protected void setLockMode(@UiLockMode.AllowedValues int lockMode) {
    ...

在这一点上是一切优秀和漂亮,但问题显示出来,每当我想从其他方法的返回值传递给 setLockMode(),像Parcelable即实施

At that point is all fine and nice but the problem shows up whenever I'd like to pass return value from other methods to setLockMode(), like i.e. from Parcelable implementation:

private Foo(Parcel in) {
    ...
    setLockMode(in.getInt());

在这种情况下,我的IDE抱怨,我只允许使用 DEFAULT,NONE,看得见的,透明 setLockMode()。但调用getInt()不是我的方法,所以我不能诠释它的返回值,让这一切快乐。我也几乎可以肯定这是不是唯一的用例,但我没能找到要么暂时抱怨这里或从<$以铸造返回值禁用 ALLOWEDVALUES 注释的方式C $ C>调用getInt(),使一个allowedValue 没有抱怨。

In such case my IDE complains that I am only allowed to use DEFAULT, NONE, VISIBLE, TRANSPARENT with setLockMode(). But getInt() is not my method so I cannot annotate its return value and make all this happy. I am also almost sure this is not unique use case but I failed to find the way to either temporarily disable AllowedValues annotation from complaining here or to "cast" return value from getInt() to make AllowedValue not complaining.

所以,我的问题是:是否有解决这个问题的方法吗?也许我缺少有关说明一些东西很明显,但也许我将创建错误报告,使谷歌解决这个问题呢?

So my questions are: is there any way of solving this problem? Maybe I am missing something obvious about annotations but maybe I shall be creating bug report to make Google address this problem instead?

任何输入或思想AP preciated。

Any input or thought appreciated.

修改

由于@fractalwrench在他的回答的建议,我可以燮preSS的警告。当然,这样的作品,但摆脱这一警告是不是我的本意。我不想用晚餐preSS的警告,但,如果可能的话,我想,使其了解调用getInt()由返回值的是正确的,那恕我直言pretty显著差异。

As @fractalwrench suggested in his answer, I can suppress the warning. Sure, that works, but getting rid of this warning is not my intention. I do not want to suppress the warning but, if possible, I'd like to make it understand the value returned by getInt() at is correct, and that's IMHO pretty significant difference.

推荐答案

您可以共进晚餐preSS IntDef 皮棉警告将通过以下注解它的方法:

You can suppress IntDef Lint warnings for a method by annotating it with the following:

@SuppressWarnings("ResourceType")

您也可以禁用这些警告各个语句和全类 - 看到的 Android的工具网站进一步的文档。

You can also disable these warnings for individual statements and whole classes - see the Android Tools site for further documentation.

这篇关于@IntDef从其他的code注释和返回值不能注释或如何暂时影响code禁止标注?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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