Rename KClass.properties and extensionProperties: prepend 'member'
To better emphasize the fact that all returned properties require an instance of the class they are declared in. Another issue was that 'Some::class.extensionProperties' was sometimes incorrectly perceived as "get all extension properties available on the class Some"
This commit is contained in:
@@ -43,7 +43,7 @@ public val KClass<*>.declaredFunctions: Collection<KFunction<*>>
|
||||
/**
|
||||
* Returns non-extension properties declared in this class and all of its superclasses.
|
||||
*/
|
||||
public val <T> KClass<T>.properties: Collection<KProperty1<T, *>>
|
||||
public val <T> KClass<T>.memberProperties: Collection<KProperty1<T, *>>
|
||||
get() = (this as KClassImpl<T>)
|
||||
.getMembers(declaredOnly = false, nonExtensions = true, extensions = false)
|
||||
.filterIsInstance<KProperty1<T, *>>()
|
||||
@@ -52,7 +52,7 @@ public val <T> KClass<T>.properties: Collection<KProperty1<T, *>>
|
||||
/**
|
||||
* Returns extension properties declared in this class and all of its superclasses.
|
||||
*/
|
||||
public val <T> KClass<T>.extensionProperties: Collection<KProperty2<T, *, *>>
|
||||
public val <T> KClass<T>.memberExtensionProperties: Collection<KProperty2<T, *, *>>
|
||||
get() = (this as KClassImpl<T>)
|
||||
.getMembers(declaredOnly = false, nonExtensions = false, extensions = true)
|
||||
.filterIsInstance<KProperty2<T, *, *>>()
|
||||
@@ -61,7 +61,7 @@ public val <T> KClass<T>.extensionProperties: Collection<KProperty2<T, *, *>>
|
||||
/**
|
||||
* Returns non-extension properties declared in this class.
|
||||
*/
|
||||
public val <T> KClass<T>.declaredProperties: Collection<KProperty1<T, *>>
|
||||
public val <T> KClass<T>.declaredMemberProperties: Collection<KProperty1<T, *>>
|
||||
get() = (this as KClassImpl<T>)
|
||||
.getMembers(declaredOnly = true, nonExtensions = true, extensions = false)
|
||||
.filterIsInstance<KProperty1<T, *>>()
|
||||
@@ -70,7 +70,7 @@ public val <T> KClass<T>.declaredProperties: Collection<KProperty1<T, *>>
|
||||
/**
|
||||
* Returns extension properties declared in this class.
|
||||
*/
|
||||
public val <T> KClass<T>.declaredExtensionProperties: Collection<KProperty2<T, *, *>>
|
||||
public val <T> KClass<T>.declaredMemberExtensionProperties: Collection<KProperty2<T, *, *>>
|
||||
get() = (this as KClassImpl<T>)
|
||||
.getMembers(declaredOnly = true, nonExtensions = false, extensions = true)
|
||||
.filterIsInstance<KProperty2<T, *, *>>()
|
||||
|
||||
@@ -17,8 +17,25 @@
|
||||
package kotlin.reflect.jvm
|
||||
|
||||
import java.lang.reflect.Field
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.*
|
||||
|
||||
@deprecated("Use kotlinProperty instead.", ReplaceWith("kotlinProperty"))
|
||||
public val Field.kotlin: KProperty<*>?
|
||||
get() = kotlinProperty
|
||||
|
||||
|
||||
@deprecated("Use memberProperties instead.", ReplaceWith("memberProperties"))
|
||||
public val <T> KClass<T>.properties: Collection<KProperty1<T, *>>
|
||||
get() = memberProperties
|
||||
|
||||
@deprecated("Use extensionProperties instead.", ReplaceWith("extensionProperties"))
|
||||
public val <T> KClass<T>.extensionProperties: Collection<KProperty2<T, *, *>>
|
||||
get() = memberExtensionProperties
|
||||
|
||||
@deprecated("Use declaredMemberProperties instead.", ReplaceWith("declaredMemberProperties"))
|
||||
public val <T> KClass<T>.declaredProperties: Collection<KProperty1<T, *>>
|
||||
get() = declaredMemberProperties
|
||||
|
||||
@deprecated("Use declaredMemberExtensionProperties instead.", ReplaceWith("declaredMemberExtensionProperties"))
|
||||
public val <T> KClass<T>.declaredExtensionProperties: Collection<KProperty2<T, *, *>>
|
||||
get() = declaredMemberExtensionProperties
|
||||
|
||||
@@ -111,7 +111,7 @@ public val Field.kotlinProperty: KProperty<*>?
|
||||
|
||||
// TODO: fields in package parts
|
||||
// TODO: optimize (search by name)
|
||||
return getDeclaringClass().kotlin.properties.firstOrNull { it.javaField == this }
|
||||
return getDeclaringClass().kotlin.memberProperties.firstOrNull { it.javaField == this }
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user