@IntDef annotation and return value from other's code that cannot be annotated or how to temporarily disable annotation from affecting the code?

百般思念 提交于 2019-12-05 02:00:11
fractalwrench

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

@SuppressWarnings("ResourceType")

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

If you only suppress the warning for this single statement by inserting //noinspection ResourceType above it, isn't this equivalent to "making it understand the value returned by getInt() at this point is correct"?

Alternatively, you could add to UiLockMode a simple method translating from int to @UiLockMode, e.g. something along the lines of:

public @UiLockMode.AllowedValues static int lockModeTranslate(int val)
{
    switch(val)
    {
        case 0: return UiLockMode.DEFAULT;
        case 1: return UiLockMode.NONE;
        case 2: return UiLockMode.TRANSPARENT;
        case 3: return UiLockMode.VISIBLE;
    }

    throw new SomethingHorrible;
}

Then a call like setLockMode(UiLockMode.lockModeTranslate(in.getInt())); will no longer cause a warning.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!