0

看不到将 Array 类型初始化为项目中现有类型的值的正确语法,原始类型工作正常,程序员定义的类

Target(
    AnnotationTarget.FIELD,
    AnnotationTarget.PROPERTY_GETTER,
    AnnotationTarget.VALUE_PARAMETER,
    AnnotationTarget.PROPERTY)
    @Retention(AnnotationRetention.SOURCE)

注释类 ConfigurableIntArray( val key: String, val text: String, val description: String, 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"
}

只能让它初始化为纯文本文字或第一个值中的静态数据

4

1 回答 1

0

猜测有一种更简单的方法,但这有效

.initializer("%L", buildCodeBlock {
                                var lregex = 
    data.annotation.initialValue.asList().toString()
                                lregex = lregex.replace("["," ")
                                lregex = lregex.replace("]"," ")
                                add("intArrayOf($lregex)")
                            })
于 2019-07-03T00:27:36.790 回答