Remove reflect API not actually supported in K/JS

#KT-32186
This commit is contained in:
Ilya Gorbunov
2019-12-25 02:40:16 +03:00
parent 562bac3f6f
commit 8af43155c3
12 changed files with 23 additions and 568 deletions
@@ -27,22 +27,22 @@ fun testSomeValidCases(p0: KProperty0<Int>, pm0: KMutableProperty0<String>, f: K
fun <T : Any> kclass(k: KClass<*>, kt: KClass<T>) {
k.simpleName
k.<!UNSUPPORTED!>qualifiedName<!>
k.<!UNSUPPORTED!>members<!>
k.<!UNSUPPORTED!>constructors<!>
k.<!UNSUPPORTED!>nestedClasses<!>
k.<!UNSUPPORTED!>objectInstance<!>
k.<!UNSUPPORTED!>typeParameters<!>
k.<!UNSUPPORTED!>supertypes<!>
k.<!UNSUPPORTED!>visibility<!>
k.<!UNSUPPORTED!>isFinal<!>
k.<!UNSUPPORTED!>isOpen<!>
k.<!UNSUPPORTED!>isAbstract<!>
k.<!UNSUPPORTED!>isSealed<!>
k.<!UNSUPPORTED!>isData<!>
k.<!UNSUPPORTED!>isInner<!>
k.<!UNSUPPORTED!>isCompanion<!>
k.<!UNRESOLVED_REFERENCE!>members<!>
k.<!UNRESOLVED_REFERENCE!>constructors<!>
k.<!UNRESOLVED_REFERENCE!>nestedClasses<!>
k.<!UNRESOLVED_REFERENCE!>objectInstance<!>
k.<!UNRESOLVED_REFERENCE!>typeParameters<!>
k.<!UNRESOLVED_REFERENCE!>supertypes<!>
k.<!UNRESOLVED_REFERENCE!>visibility<!>
k.<!UNRESOLVED_REFERENCE!>isFinal<!>
k.<!UNRESOLVED_REFERENCE!>isOpen<!>
k.<!UNRESOLVED_REFERENCE!>isAbstract<!>
k.<!UNRESOLVED_REFERENCE!>isSealed<!>
k.<!UNRESOLVED_REFERENCE!>isData<!>
k.<!UNRESOLVED_REFERENCE!>isInner<!>
k.<!UNRESOLVED_REFERENCE!>isCompanion<!>
k.<!UNSUPPORTED!>annotations<!>
k.<!UNRESOLVED_REFERENCE!>annotations<!>
k == kt
k.hashCode()
@@ -1,18 +0,0 @@
/*
* Copyright 2010-2019 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 kotlin.reflect
/**
* Represents an annotated element and allows to obtain its annotations.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/annotations.html)
* for more information.
*/
public interface KAnnotatedElement {
/**
* Annotations which are present on this element.
*/
public val annotations: List<Annotation>
}
@@ -10,7 +10,7 @@ package kotlin.reflect
*
* @param R return type of the callable.
*/
public actual interface KCallable<out R> : KAnnotatedElement {
public actual interface KCallable<out R> {
/**
* The name of this callable as it was declared in the source code.
* If the callable has no name, a special invented name is created.
@@ -20,66 +20,4 @@ public actual interface KCallable<out R> : KAnnotatedElement {
* the setter, similarly, will have the name "<set-foo>".
*/
public actual val name: String
/**
* Parameters required to make a call to this callable.
* If this callable requires a `this` instance or an extension receiver parameter,
* they come first in the list in that order.
*/
public val parameters: List<KParameter>
/**
* The type of values returned by this callable.
*/
public val returnType: KType
/**
* The list of type parameters of this callable.
*/
@SinceKotlin("1.1")
public val typeParameters: List<KTypeParameter>
/**
* Calls this callable with the specified list of arguments and returns the result.
* Throws an exception if the number of specified arguments is not equal to the size of [parameters],
* or if their types do not match the types of the parameters.
*/
public fun call(vararg args: Any?): R
/**
* Calls this callable with the specified mapping of parameters to arguments and returns the result.
* If a parameter is not found in the mapping and is not optional (as per [KParameter.isOptional]),
* or its type does not match the type of the provided value, an exception is thrown.
*/
public fun callBy(args: Map<KParameter, Any?>): R
/**
* Visibility of this callable, or `null` if its visibility cannot be represented in Kotlin.
*/
@SinceKotlin("1.1")
public val visibility: KVisibility?
/**
* `true` if this callable is `final`.
*/
@SinceKotlin("1.1")
public val isFinal: Boolean
/**
* `true` if this callable is `open`.
*/
@SinceKotlin("1.1")
public val isOpen: Boolean
/**
* `true` if this callable is `abstract`.
*/
@SinceKotlin("1.1")
public val isAbstract: Boolean
/**
* `true` if this is a suspending function.
*/
@SinceKotlin("1.3")
public val isSuspend: Boolean
}
@@ -23,110 +23,17 @@ public actual interface KClass<T : Any> : KClassifier {
/**
* The fully qualified dot-separated name of the class,
* or `null` if the class is local or it is an anonymous object literal.
*
* This property is currently not supported in Kotlin/JS.
*/
public actual val qualifiedName: String?
/**
* All functions and properties accessible in this class, including those declared in this class
* and all of its superclasses. Does not include constructors.
*/
override val members: Collection<KCallable<*>>
/**
* All constructors declared in this class.
*/
public val constructors: Collection<KFunction<T>>
/**
* All classes declared inside this class. This includes both inner and static nested classes.
*/
public val nestedClasses: Collection<KClass<*>>
/**
* The instance of the object declaration, or `null` if this class is not an object declaration.
*/
public val objectInstance: T?
/**
* Returns `true` if [value] is an instance of this class on a given platform.
*/
@SinceKotlin("1.1")
public actual fun isInstance(value: Any?): Boolean
/**
* The list of type parameters of this class. This list does *not* include type parameters of outer classes.
*/
@SinceKotlin("1.1")
public val typeParameters: List<KTypeParameter>
/**
* The list of immediate supertypes of this class, in the order they are listed in the source code.
*/
@SinceKotlin("1.1")
public val supertypes: List<KType>
/**
* The list of the immediate subclasses if this class is a sealed class, or an empty list otherwise.
*/
@SinceKotlin("1.3")
public val sealedSubclasses: List<KClass<out T>>
/**
* Visibility of this class, or `null` if its visibility cannot be represented in Kotlin.
*/
@SinceKotlin("1.1")
public val visibility: KVisibility?
/**
* `true` if this class is `final`.
*/
@SinceKotlin("1.1")
public val isFinal: Boolean
/**
* `true` if this class is `open`.
*/
@SinceKotlin("1.1")
public val isOpen: Boolean
/**
* `true` if this class is `abstract`.
*/
@SinceKotlin("1.1")
public val isAbstract: Boolean
/**
* `true` if this class is `sealed`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/sealed-classes.html)
* for more information.
*/
@SinceKotlin("1.1")
public val isSealed: Boolean
/**
* `true` if this class is a data class.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/data-classes.html)
* for more information.
*/
@SinceKotlin("1.1")
public val isData: Boolean
/**
* `true` if this class is an inner class.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/nested-classes.html#inner-classes)
* for more information.
*/
@SinceKotlin("1.1")
public val isInner: Boolean
/**
* `true` if this class is a companion object.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/object-declarations.html#companion-objects)
* for more information.
*/
@SinceKotlin("1.1")
public val isCompanion: Boolean
/**
* Returns `true` if this [KClass] instance represents the same Kotlin class as the class represented by [other].
* On JVM this means that all of the following conditions are satisfied:
@@ -10,40 +10,9 @@ import kotlin.reflect.*
internal abstract class KClassImpl<T : Any>(
internal open val jClass: JsClass<T>
) : KClass<T> {
override val annotations: List<Annotation>
get() = TODO()
override val constructors: Collection<KFunction<T>>
get() = TODO()
override val isAbstract: Boolean
get() = TODO()
override val isCompanion: Boolean
get() = TODO()
override val isData: Boolean
get() = TODO()
override val isFinal: Boolean
get() = TODO()
override val isInner: Boolean
get() = TODO()
override val isOpen: Boolean
get() = TODO()
override val isSealed: Boolean
get() = TODO()
override val members: Collection<KCallable<*>>
get() = TODO()
override val nestedClasses: Collection<KClass<*>>
get() = TODO()
override val objectInstance: T?
get() = TODO()
override val qualifiedName: String?
get() = TODO()
override val supertypes: List<KType>
get() = TODO()
override val typeParameters: List<KTypeParameter>
get() = TODO()
override val sealedSubclasses: List<KClass<out T>>
get() = TODO()
override val visibility: KVisibility?
get() = TODO()
override fun equals(other: Any?): Boolean {
return other is KClassImpl<*> && jClass == other.jClass
@@ -1,28 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.reflect
/**
* Represents an entity which may contain declarations of any other entities,
* such as a class or a package.
*/
public interface KDeclarationContainer {
/**
* All functions and properties accessible in this container.
*/
public val members: Collection<KCallable<*>>
}
@@ -8,42 +8,4 @@ package kotlin.reflect
/**
* Represents a function with introspection capabilities.
*/
public actual interface KFunction<out R> : KCallable<R>, Function<R> {
/**
* `true` if this function is `inline`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/inline-functions.html)
* for more information.
*/
@SinceKotlin("1.1")
public val isInline: Boolean
/**
* `true` if this function is `external`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/java-interop.html#using-jni-with-kotlin)
* for more information.
*/
@SinceKotlin("1.1")
public val isExternal: Boolean
/**
* `true` if this function is `operator`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/operator-overloading.html)
* for more information.
*/
@SinceKotlin("1.1")
public val isOperator: Boolean
/**
* `true` if this function is `infix`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/functions.html#infix-notation)
* for more information.
*/
@SinceKotlin("1.1")
public val isInfix: Boolean
/**
* `true` if this is a suspending function.
*/
@SinceKotlin("1.1")
public override val isSuspend: Boolean
}
public actual interface KFunction<out R> : KCallable<R>, Function<R>
@@ -1,80 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.reflect
/**
* Represents a parameter passed to a function or a property getter/setter,
* including `this` and extension receiver parameters.
*/
public interface KParameter {
/**
* 0-based index of this parameter in the parameter list of its containing callable.
*/
public val index: Int
/**
* Name of this parameter as it was declared in the source code,
* or `null` if the parameter has no name or its name is not available at runtime.
* Examples of nameless parameters include `this` instance for member functions,
* extension receiver for extension functions or properties, parameters of Java methods
* compiled without the debug information, and others.
*/
public val name: String?
/**
* Type of this parameter. For a `vararg` parameter, this is the type of the corresponding array,
* not the individual element.
*/
public val type: KType
/**
* Kind of this parameter.
*/
public val kind: Kind
/**
* Kind represents a particular position of the parameter declaration in the source code,
* such as an instance, an extension receiver parameter or a value parameter.
*/
public enum class Kind {
/** Instance required to make a call to the member, or an outer class instance for an inner class constructor. */
INSTANCE,
/** Extension receiver of an extension function or property. */
EXTENSION_RECEIVER,
/** Ordinary named value parameter. */
VALUE,
}
/**
* `true` if this parameter is optional and can be omitted when making a call via [KCallable.callBy], or `false` otherwise.
*
* A parameter is optional in any of the two cases:
* 1. The default value is provided at the declaration of this parameter.
* 2. The parameter is declared in a member function and one of the corresponding parameters in the super functions is optional.
*/
public val isOptional: Boolean
/**
* `true` if this parameter is `vararg`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/functions.html#variable-number-of-arguments-varargs)
* for more information.
*/
@SinceKotlin("1.1")
public val isVararg: Boolean
}
@@ -15,56 +15,12 @@ package kotlin.reflect
*
* @param R the type of the property.
*/
public actual interface KProperty<out R> : KCallable<R> {
/**
* `true` if this property is `lateinit`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/properties.html#late-initialized-properties)
* for more information.
*/
@SinceKotlin("1.1")
public val isLateinit: Boolean
/**
* `true` if this property is `const`.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/properties.html#compile-time-constants)
* for more information.
*/
@SinceKotlin("1.1")
public val isConst: Boolean
/** The getter of this property, used to obtain the value of the property. */
public val getter: Getter<R>
/**
* Represents a property accessor, which is a `get` or `set` method declared alongside the property.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/properties.html#getters-and-setters)
* for more information.
*
* @param R the type of the property, which it is an accessor of.
*/
public interface Accessor<out R> {
/** The property which this accessor is originated from. */
public val property: KProperty<R>
}
/**
* Getter of the property is a `get` method declared alongside the property.
*/
public interface Getter<out R> : Accessor<R>, KFunction<R>
}
public actual interface KProperty<out R> : KCallable<R>
/**
* Represents a property declared as a `var`.
*/
public actual interface KMutableProperty<R> : KProperty<R> {
/** The setter of this mutable property, used to change the value of the property. */
public val setter: Setter<R>
/**
* Setter of the property is a `set` method declared alongside the property.
*/
public interface Setter<R> : KProperty.Accessor<R>, KFunction<Unit>
}
public actual interface KMutableProperty<R> : KProperty<R>
/**
@@ -77,23 +33,6 @@ public actual interface KProperty0<out R> : KProperty<R>, () -> R {
* Returns the current value of the property.
*/
public actual fun get(): R
/**
* Returns the value of the delegate if this is a delegated property, or `null` if this property is not delegated.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/delegated-properties.html)
* for more information.
*/
@SinceKotlin("1.1")
public fun getDelegate(): Any?
override val getter: Getter<R>
/**
* Getter of the property is a `get` method declared alongside the property.
*
* Can be used as a function that takes 0 arguments and returns the value of the property type [R].
*/
public interface Getter<out R> : KProperty.Getter<R>, () -> R
}
/**
@@ -106,15 +45,6 @@ public actual interface KMutableProperty0<R> : KProperty0<R>, KMutableProperty<R
* @param value the new value to be assigned to this property.
*/
public actual fun set(value: R)
override val setter: Setter<R>
/**
* Setter of the property is a `set` method declared alongside the property.
*
* Can be used as a function that takes new property value as an argument and returns [Unit].
*/
public interface Setter<R> : KMutableProperty.Setter<R>, (R) -> Unit
}
@@ -133,32 +63,6 @@ public actual interface KProperty1<T, out R> : KProperty<R>, (T) -> R {
* or an extension receiver if this is a top level extension property.
*/
public actual fun get(receiver: T): R
/**
* Returns the value of the delegate if this is a delegated property, or `null` if this property is not delegated.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/delegated-properties.html)
* for more information.
*
* Note that for a top level **extension** property, the delegate is the same for all extension receivers,
* so the actual [receiver] instance passed in is not going to make any difference, it must only be a value of [T].
*
* @param receiver the receiver which is used to obtain the value of the property delegate.
* For example, it should be a class instance if this is a member property of that class,
* or an extension receiver if this is a top level extension property.
*
* @see [kotlin.reflect.full.getExtensionDelegate] // [KProperty1.getExtensionDelegate]
*/
@SinceKotlin("1.1")
public fun getDelegate(receiver: T): Any?
override val getter: Getter<T, R>
/**
* Getter of the property is a `get` method declared alongside the property.
*
* Can be used as a function that takes an argument of type [T] (the receiver) and returns the value of the property type [R].
*/
public interface Getter<T, out R> : KProperty.Getter<R>, (T) -> R
}
/**
@@ -174,15 +78,6 @@ public actual interface KMutableProperty1<T, R> : KProperty1<T, R>, KMutableProp
* @param value the new value to be assigned to this property.
*/
public actual fun set(receiver: T, value: R)
override val setter: Setter<T, R>
/**
* Setter of the property is a `set` method declared alongside the property.
*
* Can be used as a function that takes the receiver and the new property value as arguments and returns [Unit].
*/
public interface Setter<T, R> : KMutableProperty.Setter<R>, (T, R) -> Unit
}
@@ -205,32 +100,6 @@ public actual interface KProperty2<D, E, out R> : KProperty<R>, (D, E) -> R {
* @param receiver2 the instance of the second receiver.
*/
public actual fun get(receiver1: D, receiver2: E): R
/**
* Returns the value of the delegate if this is a delegated property, or `null` if this property is not delegated.
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/delegated-properties.html)
* for more information.
*
* In case of the extension property in a class, the instance of the class should be passed first
* and the instance of the extension receiver second.
*
* @param receiver1 the instance of the first receiver.
* @param receiver2 the instance of the second receiver.
*
* @see [kotlin.reflect.full.getExtensionDelegate] // [KProperty2.getExtensionDelegate]
*/
@SinceKotlin("1.1")
public fun getDelegate(receiver1: D, receiver2: E): Any?
override val getter: Getter<D, E, R>
/**
* Getter of the property is a `get` method declared alongside the property.
*
* Can be used as a function that takes an argument of type [D] (the first receiver), an argument of type [E] (the second receiver)
* and returns the value of the property type [R].
*/
public interface Getter<D, E, out R> : KProperty.Getter<R>, (D, E) -> R
}
/**
@@ -245,14 +114,4 @@ public actual interface KMutableProperty2<D, E, R> : KProperty2<D, E, R>, KMutab
* @param value the new value to be assigned to this property.
*/
public actual fun set(receiver1: D, receiver2: E, value: R)
override val setter: Setter<D, E, R>
/**
* Setter of the property is a `set` method declared alongside the property.
*
* Can be used as a function that takes an argument of type [D] (the first receiver), an argument of type [E] (the second receiver),
* and the new property value and returns [Unit].
*/
public interface Setter<D, E, R> : KMutableProperty.Setter<R>, (D, E, R) -> Unit
}
@@ -9,7 +9,7 @@ package kotlin.reflect
* Represents a type. Type is usually either a class with optional type arguments,
* or a type parameter of some declaration, plus nullability.
*/
public actual interface KType : KAnnotatedElement {
public actual interface KType {
/**
* The declaration of the classifier used in this type.
* For example, in the type `List<String>` the classifier would be the [KClass] instance for [List].
@@ -12,9 +12,6 @@ internal class KTypeImpl(
override val arguments: List<KTypeProjection>,
override val isMarkedNullable: Boolean
) : KType {
override val annotations: List<Annotation>
get() = emptyList()
override fun equals(other: Any?): Boolean =
other is KTypeImpl &&
classifier == other.classifier && arguments == other.arguments && isMarkedNullable == other.isMarkedNullable
@@ -49,7 +46,6 @@ internal object DynamicKType : KType {
override val classifier: KClassifier? = null
override val arguments: List<KTypeProjection> = emptyList()
override val isMarkedNullable: Boolean = false
override val annotations: List<Annotation> = emptyList()
override fun toString(): String = "dynamic"
}
@@ -1,50 +0,0 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.reflect
/**
* Visibility is an aspect of a Kotlin declaration regulating where that declaration is accessible in the source code.
* Visibility can be changed with one of the following modifiers: `public`, `protected`, `internal`, `private`.
*
* Note that some Java visibilities such as package-private and protected (which also gives access to items from the same package)
* cannot be represented in Kotlin, so there's no [KVisibility] value corresponding to them.
*
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/visibility-modifiers.html)
* for more information.
*/
@SinceKotlin("1.1")
enum class KVisibility {
/**
* Visibility of declarations marked with the `public` modifier, or with no modifier at all.
*/
PUBLIC,
/**
* Visibility of declarations marked with the `protected` modifier.
*/
PROTECTED,
/**
* Visibility of declarations marked with the `internal` modifier.
*/
INTERNAL,
/**
* Visibility of declarations marked with the `private` modifier.
*/
PRIVATE,
}