Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@StringRes, @DrawableRes, @LayoutRes and so on android annotations lint check with kotlin parameters

Tags:

android

kotlin

assuming you have such data class with default parameters

data class Info(
        @DrawableRes
        val iconRes: Int = 0,
        @StringRes
        val stringRes: Int = 0,
        @LayoutRes
        val layoutRes: Int = 0)

so you can create this data-class like

    val data = Info(
        iconRes = R.drawable.icon, 
        stringRes = R.string.text,
        layoutRes = R.layout.layout)

in this case there isn't any lint error

But when i try to use default parameters a lint error is occured:

val data = Info(
        //here is expected resource of type drawable error
        stringRes = R.string.text
        layoutRes = R.layout.layout)

Seems that it uses position in parameters, not the exact type & name.

I've tried to use explicit annotation like @param:DrawableRes, but with the same result.

Can i somehow solve this problem? I use latest Android Studio 3.0.

like image 296
Beloo Avatar asked Oct 30 '17 13:10

Beloo


1 Answers

It was an issue in Android Studio and was fixed in 3.1. Checked on 3.1-beta4

like image 114
Beloo Avatar answered Sep 20 '22 13:09

Beloo