没有看到用于将Array类型初始化为项目中现有类型的值的正确语法,原始类型工作正常并且程序员定义了类
Target(
AnnotationTarget.FIELD,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.VALUE_PARAMETER,
AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.SOURCE)
注释类ConfigurableIntArray( val键:字串, val文字:字串, val描述:字符串, val initialValue:IntArray )
Class BlockAnnotationTester2(@field:ConfigurableIntArray(
key = UIComponentSettings.MAXIMUM_LENGTH_KEY,
text = UIComponentSettings.MAXIMUM_LENGTH_TEXT,
description = UIComponentSettings.MAXIMUM_LENGTH_DESCRIPTION,
initialValue = [2])
val unusedIntArray: IntArray = intArrayOf(1, 2, 3, 4),
for (data in memberDataIntArray)...`
addProperty(
PropertySpec.builder(TestAnnotationProcessor.INITIAL_VALUE, IntArray::class)
.initializer("intArrayOf(${data.annotation.initialValue.asList()})")
.build()
)
object Member_BlockAnnotationTester2UnusedIntArray {
const val KEY: String =
"configurable_block_detail_ui_component_maximum_length"
const val TEXT: String = "Maximum length"
var INITIAL_VALUE: IntArray = intArrayOf([2]) <-- issue
const val DESCRIPTION: String = "Maximum length of the corresponding UI
component"
}
只能将其初始化为纯文本文字或第一个值的静态数据
答案 0 :(得分:0)
猜测有一种更简单的方法,但这有效
.initializer(“%L”,buildCodeBlock { var lregex = data.annotation.initialValue.asList()。toString() lregex = lregex.replace(“ [”,“”) lregex = lregex.replace(“]”,“”) add(“ intArrayOf($ lregex)”) })