IntelliJ/Kotlin PSI中的注释与注释条目
我有一个Kotlin注释:IntelliJ/Kotlin PSI中的注释与注释条目,kotlin,detekt,intellij-platform-psi,Kotlin,Detekt,Intellij Platform Psi,我有一个Kotlin注释: @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.CLASS) annotation class Type( val type: String ) 它可用于Kotlin类: @Type(type = "type") data class Annotated( … ) 我正在分析这个源代码,通过它可以访问。要获得注释,我使用如下代码: val annotation = kl
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
annotation class Type(
val type: String
)
它可用于Kotlin类:
@Type(type = "type")
data class Annotated(
…
)
我正在分析这个源代码,通过它可以访问。要获得注释,我使用如下代码:
val annotation = klass
.annotationEntries
.find {
"Type" == it?.shortName?.asString()
}
其中,klass
具有来自Kotlin PSI的KtClass
类型。我注意到,KtClass
有两个属性:annotations
和annotationEntries
,对于上面的注释类,annotations
是空的
annotations
和annotationEntries
之间有什么区别?我应该在什么时候使用什么?是一个声明(annotationclass
)
是注释(@
)的应用程序