Remove copying of transient fields in argumentUtils
Current code in argumentUtils handles transient fields incorrectly and copies them (not intended behaviour) change is required for further work in arguments handling ref https://jetbrains.team/im/review/3CCOfH4ffz5J?message=9fPd30T1rQz&channel=1y9ZTj2JB0aG
This commit is contained in:
+3
-2
@@ -17,13 +17,14 @@
|
||||
package org.jetbrains.kotlin.cli.common.arguments
|
||||
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import java.util.*
|
||||
import java.lang.reflect.Modifier
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.KVisibility
|
||||
import kotlin.reflect.full.declaredMemberProperties
|
||||
import kotlin.reflect.full.memberProperties
|
||||
import kotlin.reflect.jvm.javaField
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Any> copyBean(bean: T) = copyBeanTo(bean, bean::class.java.newInstance()!!)
|
||||
@@ -103,7 +104,7 @@ fun <T : Any> collectProperties(kClass: KClass<T>, inheritedOnly: Boolean): List
|
||||
properties.removeAll(kClass.declaredMemberProperties)
|
||||
}
|
||||
return properties.filter { property ->
|
||||
property.visibility == KVisibility.PUBLIC && (property.annotations.firstOrNull { it is Transient } as Transient?) == null
|
||||
property.visibility == KVisibility.PUBLIC && (property.javaField?.modifiers?.let { Modifier.isTransient(it) } != true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.cli.common.arguments.ArgumentParseErrors
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.copyBeanTo
|
||||
import java.lang.reflect.Modifier
|
||||
import kotlin.reflect.jvm.javaField
|
||||
|
||||
class ArgumentUtilTest : TestCase() {
|
||||
fun testCopyDoesNotCopyTransientFields() {
|
||||
assertTrue(Modifier.isTransient(K2JVMCompilerArguments::errors.javaField!!.modifiers))
|
||||
|
||||
val a = K2JVMCompilerArguments()
|
||||
a.errors = ArgumentParseErrors()
|
||||
a.moduleName = "my module name"
|
||||
|
||||
val b = K2JVMCompilerArguments()
|
||||
assertNull(b.errors)
|
||||
assertNull(b.moduleName)
|
||||
|
||||
copyBeanTo(a, b)
|
||||
|
||||
assertNull(b.errors)
|
||||
assertEquals("my module name", b.moduleName)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user