Issue
This is an simplified example of what I try to do but still failed
class Definition {
@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER)
@IntDef(View.VISIBLE, View.INVISIBLE, View.GONE)
//only 0,4,8 are allowed
@Retention(AnnotationRetention.SOURCE)
annotation class Visibility
}
fun isVisibleView(@Definition.Visibility visibility: Int, viewList: ArrayList<View>, ) {
for (view in viewList) {
view.visibility = visibility
}
}
//I want the ide to SHOW ERROR here since 2 is not in 0,4,8 (show before compile)
isVisibleView(2, visibleItems)
I think this question is about IDE config or Kotlin syntax
Solution
In short Enum is enough.
IntDef is android specific so you'd have to find an Android rule for IntelliJ to analyze those annotations.
Even you can make it work it only on java not Kotlin. It seems like the warning will be generated by lint but only if you write the annotation in Java, not Kotlin
As state in this issue https://youtrack.jetbrains.com/issue/KTIJ-18693
Credit: Anton Malinsky
Answered By - UmAnusorn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.