core: cleanup 'public', property access syntax

This commit is contained in:
Dmitry Jemerov
2016-01-07 18:03:08 +01:00
parent 117a0d8b7b
commit 3870bd04b8
173 changed files with 1198 additions and 1240 deletions
@@ -27,7 +27,7 @@ import kotlin.reflect.jvm.internal.KTypeImpl
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/classes.html#constructors)
* for more information.
*/
public val <T : Any> KClass<T>.primaryConstructor: KFunction<T>?
val <T : Any> KClass<T>.primaryConstructor: KFunction<T>?
get() = (this as KClassImpl<T>).constructors.firstOrNull {
((it as KFunctionImpl).descriptor as ConstructorDescriptor).isPrimary
}
@@ -37,7 +37,7 @@ public val <T : Any> KClass<T>.primaryConstructor: KFunction<T>?
* Returns a [KClass] instance representing the companion object of a given class,
* or `null` if the class doesn't have a companion object.
*/
public val KClass<*>.companionObject: KClass<*>?
val KClass<*>.companionObject: KClass<*>?
get() = nestedClasses.firstOrNull {
(it as KClassImpl<*>).descriptor.isCompanionObject
}
@@ -46,7 +46,7 @@ public val KClass<*>.companionObject: KClass<*>?
* Returns an instance of the companion object of a given class,
* or `null` if the class doesn't have a companion object.
*/
public val KClass<*>.companionObjectInstance: Any?
val KClass<*>.companionObjectInstance: Any?
get() = companionObject?.objectInstance
@@ -54,7 +54,7 @@ public val KClass<*>.companionObjectInstance: Any?
* Returns a type corresponding to the given class with type parameters of that class substituted as the corresponding arguments.
* For example, for class `MyMap<K, V>` [defaultType] would return the type `MyMap<K, V>`.
*/
public val KClass<*>.defaultType: KType
val KClass<*>.defaultType: KType
get() = KTypeImpl((this as KClassImpl<*>).descriptor.defaultType) { jClass }
@@ -62,13 +62,13 @@ public val KClass<*>.defaultType: KType
* Returns all functions declared in this class, including all non-static methods declared in the class
* and the superclasses, as well as static methods declared in the class.
*/
public val KClass<*>.functions: Collection<KFunction<*>>
val KClass<*>.functions: Collection<KFunction<*>>
get() = members.filterIsInstance<KFunction<*>>()
/**
* Returns static functions declared in this class.
*/
public val KClass<*>.staticFunctions: Collection<KFunction<*>>
val KClass<*>.staticFunctions: Collection<KFunction<*>>
get() = (this as KClassImpl)
.getMembers(staticScope, declaredOnly = false, nonExtensions = true, extensions = true)
.filterIsInstance<KFunction<*>>()
@@ -77,7 +77,7 @@ public val KClass<*>.staticFunctions: Collection<KFunction<*>>
/**
* Returns non-extension non-static functions declared in this class and all of its superclasses.
*/
public val KClass<*>.memberFunctions: Collection<KFunction<*>>
val KClass<*>.memberFunctions: Collection<KFunction<*>>
get() = (this as KClassImpl)
.getMembers(memberScope, declaredOnly = false, nonExtensions = true, extensions = false)
.filterIsInstance<KFunction<*>>()
@@ -86,7 +86,7 @@ public val KClass<*>.memberFunctions: Collection<KFunction<*>>
/**
* Returns extension functions declared in this class and all of its superclasses.
*/
public val KClass<*>.memberExtensionFunctions: Collection<KFunction<*>>
val KClass<*>.memberExtensionFunctions: Collection<KFunction<*>>
get() = (this as KClassImpl)
.getMembers(memberScope, declaredOnly = false, nonExtensions = false, extensions = true)
.filterIsInstance<KFunction<*>>()
@@ -97,7 +97,7 @@ public val KClass<*>.memberExtensionFunctions: Collection<KFunction<*>>
* If this is a Java class, it includes all non-static methods (both extensions and non-extensions)
* declared in the class and the superclasses, as well as static methods declared in the class.
*/
public val KClass<*>.declaredFunctions: Collection<KFunction<*>>
val KClass<*>.declaredFunctions: Collection<KFunction<*>>
get() = (this as KClassImpl)
.getMembers(memberScope, declaredOnly = true, nonExtensions = true, extensions = true)
.plus(getMembers(staticScope, declaredOnly = true, nonExtensions = true, extensions = true))
@@ -107,7 +107,7 @@ public val KClass<*>.declaredFunctions: Collection<KFunction<*>>
/**
* Returns non-extension non-static functions declared in this class.
*/
public val KClass<*>.declaredMemberFunctions: Collection<KFunction<*>>
val KClass<*>.declaredMemberFunctions: Collection<KFunction<*>>
get() = (this as KClassImpl)
.getMembers(memberScope, declaredOnly = true, nonExtensions = true, extensions = false)
.filterIsInstance<KFunction<*>>()
@@ -116,7 +116,7 @@ public val KClass<*>.declaredMemberFunctions: Collection<KFunction<*>>
/**
* Returns extension functions declared in this class.
*/
public val KClass<*>.declaredMemberExtensionFunctions: Collection<KFunction<*>>
val KClass<*>.declaredMemberExtensionFunctions: Collection<KFunction<*>>
get() = (this as KClassImpl)
.getMembers(memberScope, declaredOnly = true, nonExtensions = false, extensions = true)
.filterIsInstance<KFunction<*>>()
@@ -126,7 +126,7 @@ public val KClass<*>.declaredMemberExtensionFunctions: Collection<KFunction<*>>
* Returns static properties declared in this class.
* Only properties representing static fields of Java classes are considered static.
*/
public val KClass<*>.staticProperties: Collection<KProperty0<*>>
val KClass<*>.staticProperties: Collection<KProperty0<*>>
get() = (this as KClassImpl)
.getMembers(staticScope, declaredOnly = false, nonExtensions = true, extensions = false)
.filterIsInstance<KProperty0<*>>()
@@ -135,7 +135,7 @@ public val KClass<*>.staticProperties: Collection<KProperty0<*>>
/**
* Returns non-extension properties declared in this class and all of its superclasses.
*/
public val <T : Any> KClass<T>.memberProperties: Collection<KProperty1<T, *>>
val <T : Any> KClass<T>.memberProperties: Collection<KProperty1<T, *>>
get() = (this as KClassImpl<T>)
.getMembers(memberScope, declaredOnly = false, nonExtensions = true, extensions = false)
.filterIsInstance<KProperty1<T, *>>()
@@ -144,7 +144,7 @@ public val <T : Any> KClass<T>.memberProperties: Collection<KProperty1<T, *>>
/**
* Returns extension properties declared in this class and all of its superclasses.
*/
public val <T : Any> KClass<T>.memberExtensionProperties: Collection<KProperty2<T, *, *>>
val <T : Any> KClass<T>.memberExtensionProperties: Collection<KProperty2<T, *, *>>
get() = (this as KClassImpl<T>)
.getMembers(memberScope, declaredOnly = false, nonExtensions = false, extensions = true)
.filterIsInstance<KProperty2<T, *, *>>()
@@ -153,7 +153,7 @@ public val <T : Any> KClass<T>.memberExtensionProperties: Collection<KProperty2<
/**
* Returns non-extension properties declared in this class.
*/
public val <T : Any> KClass<T>.declaredMemberProperties: Collection<KProperty1<T, *>>
val <T : Any> KClass<T>.declaredMemberProperties: Collection<KProperty1<T, *>>
get() = (this as KClassImpl<T>)
.getMembers(memberScope, declaredOnly = true, nonExtensions = true, extensions = false)
.filterIsInstance<KProperty1<T, *>>()
@@ -162,7 +162,7 @@ public val <T : Any> KClass<T>.declaredMemberProperties: Collection<KProperty1<T
/**
* Returns extension properties declared in this class.
*/
public val <T : Any> KClass<T>.declaredMemberExtensionProperties: Collection<KProperty2<T, *, *>>
val <T : Any> KClass<T>.declaredMemberExtensionProperties: Collection<KProperty2<T, *, *>>
get() = (this as KClassImpl<T>)
.getMembers(memberScope, declaredOnly = true, nonExtensions = false, extensions = true)
.filterIsInstance<KProperty2<T, *, *>>()
@@ -24,7 +24,7 @@ package kotlin.reflect
*
* @see [kotlin.reflect.jvm.isAccessible]
*/
public class IllegalCallableAccessException(cause: IllegalAccessException) : Exception(cause.message) {
class IllegalCallableAccessException(cause: IllegalAccessException) : Exception(cause.message) {
init {
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
(this as java.lang.Throwable).initCause(cause)
@@ -35,7 +35,7 @@ public class IllegalCallableAccessException(cause: IllegalAccessException) : Exc
* An exception that is thrown when the code tries to introspect a property of a class or a package
* and that class or the package no longer has that property.
*/
public class NoSuchPropertyException(cause: Exception? = null) : Exception() {
class NoSuchPropertyException(cause: Exception? = null) : Exception() {
init {
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
if (cause != null) {
@@ -47,4 +47,4 @@ public class NoSuchPropertyException(cause: Exception? = null) : Exception() {
/**
* Signals that Kotlin reflection had reached an inconsistent state from which it cannot recover.
*/
public class KotlinReflectionInternalError(message: String) : Error(message)
class KotlinReflectionInternalError(message: String) : Error(message)
@@ -35,7 +35,7 @@ import kotlin.reflect.jvm.internal.asKCallableImpl
*
* @see [java.lang.reflect.AccessibleObject]
*/
public var KCallable<*>.isAccessible: Boolean
var KCallable<*>.isAccessible: Boolean
get() {
return when (this) {
is KMutableProperty ->
@@ -25,7 +25,7 @@ import kotlin.reflect.jvm.internal.KClassImpl
*
* @see [java.lang.Class.getName]
*/
public val KClass<*>.jvmName: String
val KClass<*>.jvmName: String
get() {
return (this as KClassImpl).jClass.name
}
@@ -33,21 +33,21 @@ import kotlin.reflect.jvm.internal.asKPropertyImpl
* Returns a Java [Field] instance corresponding to the backing field of the given property,
* or `null` if the property has no backing field.
*/
public val KProperty<*>.javaField: Field?
val KProperty<*>.javaField: Field?
get() = this.asKPropertyImpl()?.javaField
/**
* Returns a Java [Method] instance corresponding to the getter of the given property,
* or `null` if the property has no getter, for example in case of a simple private `val` in a class.
*/
public val KProperty<*>.javaGetter: Method?
val KProperty<*>.javaGetter: Method?
get() = getter.javaMethod
/**
* Returns a Java [Method] instance corresponding to the setter of the given mutable property,
* or `null` if the property has no setter, for example in case of a simple private `var` in a class.
*/
public val KMutableProperty<*>.javaSetter: Method?
val KMutableProperty<*>.javaSetter: Method?
get() = setter.javaMethod
@@ -55,15 +55,14 @@ public val KMutableProperty<*>.javaSetter: Method?
* Returns a Java [Method] instance corresponding to the given Kotlin function,
* or `null` if this function is a constructor or cannot be represented by a Java [Method].
*/
public val KFunction<*>.javaMethod: Method?
val KFunction<*>.javaMethod: Method?
get() = this.asKCallableImpl()?.caller?.member as? Method
/**
* Returns a Java [Constructor] instance corresponding to the given Kotlin function,
* or `null` if this function is not a constructor or cannot be represented by a Java [Constructor].
*/
@Suppress("UNCHECKED_CAST")
public val <T> KFunction<T>.javaConstructor: Constructor<T>?
@Suppress("UNCHECKED_CAST") val <T> KFunction<T>.javaConstructor: Constructor<T>?
get() = this.asKCallableImpl()?.caller?.member as? Constructor<T>
@@ -72,7 +71,7 @@ public val <T> KFunction<T>.javaConstructor: Constructor<T>?
* Note that one Kotlin type may correspond to different JVM types depending on where it appears. For example, [Unit] corresponds to
* the JVM class [Unit] when it's the type of a parameter, or to `void` when it's the return type of a function.
*/
public val KType.javaType: Type
val KType.javaType: Type
get() = (this as KTypeImpl).javaType
@@ -84,9 +83,9 @@ public val KType.javaType: Type
* or `null` if this field cannot be represented by a Kotlin property
* (for example, if it is a synthetic field).
*/
public val Field.kotlinProperty: KProperty<*>?
val Field.kotlinProperty: KProperty<*>?
get() {
if (isSynthetic()) return null
if (isSynthetic) return null
// TODO: optimize (search by name)
@@ -95,7 +94,7 @@ public val Field.kotlinProperty: KProperty<*>?
return kotlinPackage.members.filterIsInstance<KProperty<*>>().firstOrNull { it.javaField == this }
}
return getDeclaringClass().kotlin.memberProperties.firstOrNull { it.javaField == this }
return declaringClass.kotlin.memberProperties.firstOrNull { it.javaField == this }
}
@@ -112,7 +111,7 @@ private fun Member.getKPackage(): KDeclarationContainer? {
* or `null` if this method cannot be represented by a Kotlin function
* (for example, if it is a synthetic method).
*/
public val Method.kotlinFunction: KFunction<*>?
val Method.kotlinFunction: KFunction<*>?
get() {
if (isSynthetic) return null
@@ -141,9 +140,9 @@ public val Method.kotlinFunction: KFunction<*>?
* or `null` if this constructor cannot be represented by a Kotlin function
* (for example, if it is a synthetic constructor).
*/
public val <T : Any> Constructor<T>.kotlinFunction: KFunction<T>?
val <T : Any> Constructor<T>.kotlinFunction: KFunction<T>?
get() {
if (isSynthetic()) return null
if (isSynthetic) return null
return getDeclaringClass().kotlin.constructors.firstOrNull { it.javaConstructor == this }
return declaringClass.kotlin.constructors.firstOrNull { it.javaConstructor == this }
}
@@ -19,37 +19,29 @@ package kotlin.reflect.jvm
import java.lang.reflect.Field
import kotlin.reflect.*
@Deprecated("Use kotlinProperty instead.", ReplaceWith("kotlinProperty"))
public val Field.kotlin: KProperty<*>?
@Deprecated("Use kotlinProperty instead.", ReplaceWith("kotlinProperty")) val Field.kotlin: KProperty<*>?
get() = kotlinProperty
@Deprecated("Use memberProperties instead.", ReplaceWith("memberProperties"))
public val <T : Any> KClass<T>.properties: Collection<KProperty1<T, *>>
@Deprecated("Use memberProperties instead.", ReplaceWith("memberProperties")) val <T : Any> KClass<T>.properties: Collection<KProperty1<T, *>>
get() = memberProperties
@Deprecated("Use extensionProperties instead.", ReplaceWith("extensionProperties"))
public val <T : Any> KClass<T>.extensionProperties: Collection<KProperty2<T, *, *>>
@Deprecated("Use extensionProperties instead.", ReplaceWith("extensionProperties")) val <T : Any> KClass<T>.extensionProperties: Collection<KProperty2<T, *, *>>
get() = memberExtensionProperties
@Deprecated("Use declaredMemberProperties instead.", ReplaceWith("declaredMemberProperties"))
public val <T : Any> KClass<T>.declaredProperties: Collection<KProperty1<T, *>>
@Deprecated("Use declaredMemberProperties instead.", ReplaceWith("declaredMemberProperties")) val <T : Any> KClass<T>.declaredProperties: Collection<KProperty1<T, *>>
get() = declaredMemberProperties
@Deprecated("Use declaredMemberExtensionProperties instead.", ReplaceWith("declaredMemberExtensionProperties"))
public val <T : Any> KClass<T>.declaredExtensionProperties: Collection<KProperty2<T, *, *>>
@Deprecated("Use declaredMemberExtensionProperties instead.", ReplaceWith("declaredMemberExtensionProperties")) val <T : Any> KClass<T>.declaredExtensionProperties: Collection<KProperty2<T, *, *>>
get() = declaredMemberExtensionProperties
@Deprecated("Use isAccessible instead.", ReplaceWith("isAccessible"))
public var KProperty<*>.accessible: Boolean
@Deprecated("Use isAccessible instead.", ReplaceWith("isAccessible")) var KProperty<*>.accessible: Boolean
get() = isAccessible
set(value) { isAccessible = value }
@Deprecated("Moved to package kotlin.jvm", ReplaceWith("java"), level = DeprecationLevel.HIDDEN)
public val <T : Any> KClass<T>.java: Class<T>
@Deprecated("Moved to package kotlin.jvm", ReplaceWith("java"), level = DeprecationLevel.HIDDEN) val <T : Any> KClass<T>.java: Class<T>
get() = java
@Deprecated("Moved to package kotlin.jvm", ReplaceWith("kotlin"), level = DeprecationLevel.HIDDEN)
public val <T : Any> Class<T>.kotlin: KClass<T>
@Deprecated("Moved to package kotlin.jvm", ReplaceWith("kotlin"), level = DeprecationLevel.HIDDEN) val <T : Any> Class<T>.kotlin: KClass<T>
get() = kotlin
@@ -35,7 +35,7 @@ import kotlin.reflect.jvm.internal.getOrCreateModule
* returns a [KFunction] instance providing introspection capabilities for that lambda or function expression and its parameters.
* Not all features are currently supported, in particular [KCallable.call] and [KCallable.callBy] will fail at the moment.
*/
public fun <R> Function<R>.reflect(): KFunction<R>? {
fun <R> Function<R>.reflect(): KFunction<R>? {
val callable = javaClass.getAnnotation(KotlinFunction::class.java) ?: return null
val input = BitEncoding.decodeBytes(callable.data).inputStream()
val nameResolver = JvmNameResolver(