传递带有自定义注释的参数时,如何显示皮棉检查?

时间:2019-08-26 18:43:08

标签: java android kotlin android-lint

我有一个具有以下结构和以下自定义注释的枚举类:

enum class Feature() {
    @TypeBoolean EnableFeatureA,
    @TypeBoolean EnableFeatureB,
    @TypeInt FeatureAValue,
    @TypeString FeatureBValue
}

@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
@Retention(AnnotationRetention.RUNTIME)
annotation class TypeBoolean

@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
@Retention(AnnotationRetention.RUNTIME)
annotation class TypeString

@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
@Retention(AnnotationRetention.RUNTIME)
annotation class TypeInt

然后我会有类似以下内容的吸气剂:

fun getFeatureBoolean(feature: Feature): Boolean {
    return featureSet.getBoolean(feature)
}

fun getFeatureString(feature: Feature): String {
    return featureSet.getString(feature)
}

fun getFeatureInt(feature: Feature): Int {
    return featureSet.getInt(feature)
}

我不希望可为null的类型或回退,因为我知道数据将在那里。我只是想确保不会传递错误类型的标签。

我已经知道如何检查成员是否具有带有验证器的注释;我缺少的是如何在编译时而不是运行时检查。

以下是我已经研究过的链接:

https://www.baeldung.com/kotlin-annotations

https://www.baeldung.com/java-custom-annotation

https://github.com/eugenp/tutorials/blob/master/core-java-modules/core-java-8/src/main/java/com/baeldung/customannotations/ObjectToJsonConverter.java

https://github.com/eugenp/tutorials/blob/master/core-kotlin-2/src/main/kotlin/com/baeldung/annotations/Validator.kt

https://kotlinlang.org/docs/reference/annotations.html

https://medium.com/tompee/kotlin-annotations-and-reflection-caa0d73bf39b

https://medium.com/@vanniktech/writing-your-first-lint-check-39ad0e90b9e6

https://developer.android.com/studio/write/lint

谢谢您的帮助

0 个答案:

没有答案