Move runtime.jvm sources to stdlib/jvm/runtime

Update path in kotlin-runtime
Update path in kotlin-mock-runtime-for-tests
This commit is contained in:
Ilya Gorbunov
2018-01-31 07:04:43 +03:00
committed by Stanislav Erokhin
parent 00b23a0fe9
commit c796e5338b
67 changed files with 143 additions and 336 deletions
+1 -7
View File
@@ -21,13 +21,7 @@ sourceSets {
builtins {
java {
srcDir "${rootDir}/core/builtins/src"
srcDir "${rootDir}/core/runtime.jvm/src"
exclude 'org/jetbrains/annotations/**'
}
kotlin {
srcDir "${rootDir}/core/builtins/src"
srcDir "${rootDir}/core/runtime.jvm/src"
exclude 'org/jetbrains/annotations/**'
srcDir "jvm/runtime"
}
}
main {
@@ -0,0 +1,23 @@
/*
* 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
public open class KotlinNullPointerException : NullPointerException {
constructor()
constructor(message: String?) : super(message)
}
@@ -0,0 +1,74 @@
/*
* 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
/**
* This annotation is present on any class file produced by the Kotlin compiler and is read by the compiler and reflection.
* Parameters have very short names on purpose: these names appear in the generated class files, and we'd like to reduce their size.
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
internal annotation class Metadata(
/**
* A kind of the metadata this annotation encodes. Kotlin compiler recognizes the following kinds (see KotlinClassHeader.Kind):
*
* 1 Class
* 2 File
* 3 Synthetic class
* 4 Multi-file class facade
* 5 Multi-file class part
*
* The class file with a kind not listed here is treated as a non-Kotlin file.
*/
val k: Int = 1,
/**
* The version of the metadata provided in the arguments of this annotation.
*/
val mv: IntArray = intArrayOf(),
/**
* The version of the bytecode interface (naming conventions, signatures) of the class file annotated with this annotation.
*/
val bv: IntArray = intArrayOf(),
/**
* Metadata in a custom format. The format may be different (or even absent) for different kinds.
*/
val d1: Array<String> = arrayOf(),
/**
* An addition to [d1]: array of strings which occur in metadata, written in plain text so that strings already present
* in the constant pool are reused. These strings may be then indexed in the metadata by an integer index in this array.
*/
val d2: Array<String> = arrayOf(),
/**
* An extra string. For a multi-file part class, internal name of the facade class.
*/
val xs: String = "",
/**
* Fully qualified name of the package this class is located in, from Kotlin's point of view, or empty string if this name
* does not differ from the JVM's package FQ name. These names can be different in case the [JvmPackageName] annotation is used.
* Note that this information is also stored in the corresponding module's `.kotlin_module` file.
*/
val pn: String = "",
/**
* An extra int. Bits of this number represent the following flags:
*
* 0 - this is a multi-file class facade or part, compiled with `-Xmultifile-parts-inherit`.
* 1 - this class file is compiled by a pre-release version of Kotlin and is not visible to release versions.
* 2 - this class file is a compiled Kotlin script source file (.kts).
*/
@SinceKotlin("1.1")
val xi: Int = 0
)
@@ -0,0 +1,27 @@
/*
* 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
public open class NoWhenBranchMatchedException : RuntimeException {
constructor()
constructor(message: String?) : super(message)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
}
@@ -0,0 +1,36 @@
/*
* 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
@SinceKotlin("1.1") public typealias Error = java.lang.Error
@SinceKotlin("1.1") public typealias Exception = java.lang.Exception
@SinceKotlin("1.1") public typealias RuntimeException = java.lang.RuntimeException
@SinceKotlin("1.1") public typealias IllegalArgumentException = java.lang.IllegalArgumentException
@SinceKotlin("1.1") public typealias IllegalStateException = java.lang.IllegalStateException
@SinceKotlin("1.1") public typealias IndexOutOfBoundsException = java.lang.IndexOutOfBoundsException
@SinceKotlin("1.1") public typealias UnsupportedOperationException = java.lang.UnsupportedOperationException
@SinceKotlin("1.1") public typealias NumberFormatException = java.lang.NumberFormatException
@SinceKotlin("1.1") public typealias NullPointerException = java.lang.NullPointerException
@SinceKotlin("1.1") public typealias ClassCastException = java.lang.ClassCastException
@SinceKotlin("1.1") public typealias AssertionError = java.lang.AssertionError
@SinceKotlin("1.1") public typealias NoSuchElementException = java.util.NoSuchElementException
@SinceKotlin("1.1") public typealias Comparator<T> = java.util.Comparator<T>
@@ -0,0 +1,23 @@
/*
* 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
public open class TypeCastException : ClassCastException {
constructor()
constructor(message: String?) : super(message)
}
@@ -0,0 +1,27 @@
/*
* 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
public class UninitializedPropertyAccessException : RuntimeException {
constructor()
constructor(message: String?) : super(message)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
}
@@ -0,0 +1,118 @@
/*
* 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.
*/
@file:JvmName("JvmClassMappingKt")
@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST")
package kotlin.jvm
import kotlin.jvm.internal.ClassBasedDeclarationContainer
import kotlin.jvm.internal.Reflection
import kotlin.reflect.KClass
import java.lang.Boolean as JavaLangBoolean
import java.lang.Byte as JavaLangByte
import java.lang.Character as JavaLangCharacter
import java.lang.Double as JavaLangDouble
import java.lang.Float as JavaLangFloat
import java.lang.Integer as JavaLangInteger
import java.lang.Long as JavaLangLong
import java.lang.Short as JavaLangShort
/**
* Returns a Java [Class] instance corresponding to the given [KClass] instance.
*/
@Suppress("UPPER_BOUND_VIOLATED")
public val <T> KClass<T>.java: Class<T>
@JvmName("getJavaClass")
get() = (this as ClassBasedDeclarationContainer).jClass as Class<T>
/**
* Returns a Java [Class] instance representing the primitive type corresponding to the given [KClass] if it exists.
*/
public val <T : Any> KClass<T>.javaPrimitiveType: Class<T>?
get() {
val thisJClass = (this as ClassBasedDeclarationContainer).jClass
if (thisJClass.isPrimitive) return thisJClass as Class<T>
return when (thisJClass.name) {
"java.lang.Boolean" -> Boolean::class.java
"java.lang.Character" -> Char::class.java
"java.lang.Byte" -> Byte::class.java
"java.lang.Short" -> Short::class.java
"java.lang.Integer" -> Int::class.java
"java.lang.Float" -> Float::class.java
"java.lang.Long" -> Long::class.java
"java.lang.Double" -> Double::class.java
"java.lang.Void" -> Void.TYPE
else -> null
} as Class<T>?
}
/**
* Returns a Java [Class] instance corresponding to the given [KClass] instance.
* In case of primitive types it returns corresponding wrapper classes.
*/
public val <T : Any> KClass<T>.javaObjectType: Class<T>
get() {
val thisJClass = (this as ClassBasedDeclarationContainer).jClass
if (!thisJClass.isPrimitive) return thisJClass as Class<T>
return when (thisJClass.name) {
"boolean" -> JavaLangBoolean::class.java
"char" -> JavaLangCharacter::class.java
"byte" -> JavaLangByte::class.java
"short" -> JavaLangShort::class.java
"int" -> JavaLangInteger::class.java
"float" -> JavaLangFloat::class.java
"long" -> JavaLangLong::class.java
"double" -> JavaLangDouble::class.java
"void" -> Void::class.java
else -> thisJClass
} as Class<T>
}
/**
* Returns a [KClass] instance corresponding to the given Java [Class] instance.
*/
public val <T : Any> Class<T>.kotlin: KClass<T>
@JvmName("getKotlinClass")
get() = Reflection.getOrCreateKotlinClass(this) as KClass<T>
/**
* Returns the runtime Java class of this object.
*/
public inline val <T: Any> T.javaClass : Class<T>
@Suppress("UsePropertyAccessSyntax")
get() = (this as java.lang.Object).getClass() as Class<T>
@Deprecated("Use 'java' property to get Java class corresponding to this Kotlin class or cast this instance to Any if you really want to get the runtime Java class of this implementation of KClass.", ReplaceWith("(this as Any).javaClass"), level = DeprecationLevel.ERROR)
public inline val <T: Any> KClass<T>.javaClass: Class<KClass<T>>
@JvmName("getRuntimeClassOfKClassInstance")
@Suppress("UsePropertyAccessSyntax")
get() = (this as java.lang.Object).getClass() as Class<KClass<T>>
/**
* Checks if array can contain element of type [T].
*/
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
public fun <reified T : Any> Array<*>.isArrayOf(): Boolean =
T::class.java.isAssignableFrom(this::class.java.componentType)
/**
* Returns a [KClass] instance corresponding to the annotation type of this annotation.
*/
public val <T : Annotation> T.annotationClass: KClass<out T>
get() = (this as java.lang.annotation.Annotation).annotationType().kotlin as KClass<out T>
@@ -0,0 +1,29 @@
/*
* 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.jvm
import java.lang.Error
public open class KotlinReflectionNotSupportedError : Error {
constructor() : super("Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath")
constructor(message: String?) : super(message)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
}
@@ -0,0 +1,50 @@
/*
* 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.jvm
/**
* Instructs the Kotlin compiler to treat annotated Java class as pure implementation of given Kotlin interface.
* "Pure" means here that each type parameter of class becomes non-platform type argument of that interface.
*
* Example:
*
* ```java
* class MyList<T> extends AbstractList<T> { ... }
* ```
*
* Methods defined in `MyList<T>` use `T` as platform, i.e. it's possible to perform unsafe operation in Kotlin:
*
* ```kotlin
* MyList<Int>().add(null) // compiles
* ```
*
* ```java
* @PurelyImplements("kotlin.collections.MutableList")
* class MyPureList<T> extends AbstractList<T> { ... }
* ```
*
* Methods defined in `MyPureList<T>` overriding methods in `MutableList` use `T` as non-platform types:
*
* ```kotlin
* MyList<Int>().add(null) // Error
* MyList<Int?>().add(null) // Ok
* ```
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
public annotation class PurelyImplements(val value: String)
@@ -0,0 +1,57 @@
/*
* Copyright 2010-2014 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.jvm
import kotlin.annotation.AnnotationTarget.*
/**
* Marks the JVM backing field of the annotated property as `volatile`, meaning that writes to this field
* are immediately made visible to other threads.
*/
@Target(FIELD)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
public annotation class Volatile
/**
* Marks the JVM backing field of the annotated property as `transient`, meaning that it is not
* part of the default serialized form of the object.
*/
@Target(FIELD)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
public annotation class Transient
/**
* Marks the JVM method generated from the annotated function as `strictfp`, meaning that the precision
* of floating point operations performed inside the method needs to be restricted in order to
* achieve better portability.
*/
@Target(FUNCTION, CONSTRUCTOR, PROPERTY_GETTER, PROPERTY_SETTER, CLASS)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
public annotation class Strictfp
/**
* Marks the JVM method generated from the annotated function as `synchronized`, meaning that the method
* will be protected from concurrent execution by multiple threads by the monitor of the instance (or,
* for static methods, the class) on which the method is defined.
*/
@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
public annotation class Synchronized
@@ -0,0 +1,137 @@
/*
* 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.jvm
import kotlin.reflect.KClass
/**
* Instructs the Kotlin compiler to generate overloads for this function that substitute default parameter values.
*
* If a method has N parameters and M of which have default values, M overloads are generated: the first one
* takes N-1 parameters (all but the last one that takes a default value), the second takes N-2 parameters, and so on.
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
@Retention(AnnotationRetention.BINARY)
@MustBeDocumented
public annotation class JvmOverloads
/**
* Specifies that an additional static method needs to be generated from this element if it's a function.
* If this element is a property, additional static getter/setter methods should be generated.
*
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#static-methods)
* for more information.
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@Retention(AnnotationRetention.RUNTIME)
@MustBeDocumented
public annotation class JvmStatic
/**
* Specifies the name for the Java class or method which is generated from this element.
*
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#handling-signature-clashes-with-jvmname)
* for more information.
* @property name the name of the element.
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FILE)
@Retention(AnnotationRetention.BINARY)
@MustBeDocumented
public annotation class JvmName(val name: String)
/**
* Instructs the Kotlin compiler to generate a multifile class with top-level functions and properties declared in this file as one of its parts.
* Name of the corresponding multifile class is provided by the [JvmName] annotation.
*/
@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
public annotation class JvmMultifileClass
/**
* Changes the fully qualified name of the JVM package of the .class file generated from this file.
* This does not affect the way Kotlin clients will see the declarations in this file, but Java clients and other JVM language clients
* will see the class file as if it was declared in the specified package.
* If a file is annotated with this annotation, it can only have function, property and typealias declarations, but no classes.
*/
@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
@SinceKotlin("1.2")
internal annotation class JvmPackageName(val name: String)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FIELD)
@Retention(AnnotationRetention.SOURCE)
public annotation class JvmSynthetic
/**
* This annotation indicates what exceptions should be declared by a function when compiled to a JVM method.
*
* Example:
*
* ```
* @Throws(IOException::class)
* fun readFile(name: String): String {...}
* ```
*
* will be translated to
*
* ```
* String readFile(String name) throws IOException {...}
* ```
*
* @property exceptionClasses the list of checked exception classes that may be thrown by the function.
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.CONSTRUCTOR)
@Retention(AnnotationRetention.SOURCE)
public annotation class Throws(vararg val exceptionClasses: KClass<out Throwable>)
/**
* Instructs the Kotlin compiler not to generate getters/setters for this property and expose it as a field.
*
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#instance-fields)
* for more information.
*/
@Target(AnnotationTarget.FIELD)
@Retention(AnnotationRetention.BINARY)
@MustBeDocumented
public annotation class JvmField
/**
* Instructs compiler to generate or omit wildcards for type arguments corresponding to parameters with
* declaration-site variance, for example such as `Collection<out T>` has.
*
* If the innermost applied `@JvmSuppressWildcards` has `suppress=true`, the type is generated without wildcards.
* If the innermost applied `@JvmSuppressWildcards` has `suppress=false`, the type is generated with wildcards.
*
* It may be helpful only if declaration seems to be inconvenient to use from Java.
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.TYPE)
@Retention(AnnotationRetention.BINARY)
@MustBeDocumented
public annotation class JvmSuppressWildcards(val suppress: Boolean = true)
/**
* Instructs compiler to generate wildcard for annotated type arguments corresponding to parameters with declaration-site variance.
*
* It may be helpful only if declaration seems to be inconvenient to use from Java without wildcard.
*/
@Target(AnnotationTarget.TYPE)
@Retention(AnnotationRetention.BINARY)
@MustBeDocumented
public annotation class JvmWildcard
@@ -0,0 +1,135 @@
/*
* Copyright 2010-2018 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.
*/
// Auto-generated file. DO NOT EDIT!
package kotlin.jvm.functions
/** A function that takes 0 arguments. */
public interface Function0<out R> : Function<R> {
/** Invokes the function. */
public operator fun invoke(): R
}
/** A function that takes 1 argument. */
public interface Function1<in P1, out R> : Function<R> {
/** Invokes the function with the specified argument. */
public operator fun invoke(p1: P1): R
}
/** A function that takes 2 arguments. */
public interface Function2<in P1, in P2, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2): R
}
/** A function that takes 3 arguments. */
public interface Function3<in P1, in P2, in P3, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3): R
}
/** A function that takes 4 arguments. */
public interface Function4<in P1, in P2, in P3, in P4, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4): R
}
/** A function that takes 5 arguments. */
public interface Function5<in P1, in P2, in P3, in P4, in P5, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R
}
/** A function that takes 6 arguments. */
public interface Function6<in P1, in P2, in P3, in P4, in P5, in P6, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R
}
/** A function that takes 7 arguments. */
public interface Function7<in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R
}
/** A function that takes 8 arguments. */
public interface Function8<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R
}
/** A function that takes 9 arguments. */
public interface Function9<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R
}
/** A function that takes 10 arguments. */
public interface Function10<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R
}
/** A function that takes 11 arguments. */
public interface Function11<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R
}
/** A function that takes 12 arguments. */
public interface Function12<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R
}
/** A function that takes 13 arguments. */
public interface Function13<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R
}
/** A function that takes 14 arguments. */
public interface Function14<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R
}
/** A function that takes 15 arguments. */
public interface Function15<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R
}
/** A function that takes 16 arguments. */
public interface Function16<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R
}
/** A function that takes 17 arguments. */
public interface Function17<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R
}
/** A function that takes 18 arguments. */
public interface Function18<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R
}
/** A function that takes 19 arguments. */
public interface Function19<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R
}
/** A function that takes 20 arguments. */
public interface Function20<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R
}
/** A function that takes 21 arguments. */
public interface Function21<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R
}
/** A function that takes 22 arguments. */
public interface Function22<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R
}
@@ -0,0 +1,25 @@
/*
* 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.jvm.internal
private class ArrayIterator<T>(val array: Array<T>) : Iterator<T> {
private var index = 0
override fun hasNext() = index < array.size
override fun next() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }
}
public fun <T> iterator(array: Array<T>): Iterator<T> = ArrayIterator(array)
@@ -0,0 +1,76 @@
/*
* Copyright 2010-2018 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.
*/
// Auto-generated file. DO NOT EDIT!
package kotlin.jvm.internal
private class ArrayByteIterator(private val array: ByteArray) : ByteIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextByte() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }
}
private class ArrayCharIterator(private val array: CharArray) : CharIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextChar() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }
}
private class ArrayShortIterator(private val array: ShortArray) : ShortIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextShort() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }
}
private class ArrayIntIterator(private val array: IntArray) : IntIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextInt() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }
}
private class ArrayLongIterator(private val array: LongArray) : LongIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextLong() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }
}
private class ArrayFloatIterator(private val array: FloatArray) : FloatIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextFloat() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }
}
private class ArrayDoubleIterator(private val array: DoubleArray) : DoubleIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextDouble() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }
}
private class ArrayBooleanIterator(private val array: BooleanArray) : BooleanIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextBoolean() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }
}
public fun iterator(array: ByteArray): ByteIterator = ArrayByteIterator(array)
public fun iterator(array: CharArray): CharIterator = ArrayCharIterator(array)
public fun iterator(array: ShortArray): ShortIterator = ArrayShortIterator(array)
public fun iterator(array: IntArray): IntIterator = ArrayIntIterator(array)
public fun iterator(array: LongArray): LongIterator = ArrayLongIterator(array)
public fun iterator(array: FloatArray): FloatIterator = ArrayFloatIterator(array)
public fun iterator(array: DoubleArray): DoubleIterator = ArrayDoubleIterator(array)
public fun iterator(array: BooleanArray): BooleanIterator = ArrayBooleanIterator(array)
@@ -0,0 +1,180 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.jvm.KotlinReflectionNotSupportedError;
import kotlin.reflect.*;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
/**
* A superclass for all classes generated by Kotlin compiler for callable references.
*
* All methods from KCallable should be implemented here and should delegate to the actual implementation, loaded dynamically
* and stored in the {@link CallableReference#reflected} field.
*/
@SuppressWarnings({"unchecked", "NullableProblems"})
public abstract class CallableReference implements KCallable, Serializable {
// This field is not volatile intentionally:
// 1) It's fine if the value is computed multiple times in different threads;
// 2) An uninitialized value cannot be observed in this field from other thread because only already initialized or safely initialized
// objects are written to it. The latter is guaranteed because both KFunctionImpl and KPropertyImpl have at least one final field.
private transient KCallable reflected;
@SinceKotlin(version = "1.1")
protected final Object receiver;
@SinceKotlin(version = "1.1")
public static final Object NO_RECEIVER = NoReceiver.INSTANCE;
@SinceKotlin(version = "1.2")
private static class NoReceiver implements Serializable {
private static final NoReceiver INSTANCE = new NoReceiver();
private Object readResolve() throws ObjectStreamException {
return INSTANCE;
}
}
public CallableReference() {
this(NO_RECEIVER);
}
@SinceKotlin(version = "1.1")
protected CallableReference(Object receiver) {
this.receiver = receiver;
}
protected abstract KCallable computeReflected();
@SinceKotlin(version = "1.1")
public Object getBoundReceiver() {
return receiver;
}
@SinceKotlin(version = "1.1")
public KCallable compute() {
KCallable result = reflected;
if (result == null) {
result = computeReflected();
reflected = result;
}
return result;
}
@SinceKotlin(version = "1.1")
protected KCallable getReflected() {
KCallable result = compute();
if (result == this) {
throw new KotlinReflectionNotSupportedError();
}
return result;
}
// The following methods provide the information identifying this callable, which is used by the reflection implementation.
// They are supposed to be overridden in each subclass (each anonymous class generated for a callable reference).
/**
* @return the class or package where the callable should be located, usually specified on the LHS of the '::' operator
*/
public KDeclarationContainer getOwner() {
throw new AbstractMethodError();
}
/**
* @return Kotlin name of the callable, the one which was declared in the source code (@JvmName doesn't change it)
*/
@Override
public String getName() {
throw new AbstractMethodError();
}
/**
* @return JVM signature of the callable, e.g. "println(Ljava/lang/Object;)V". If this is a property reference,
* returns the JVM signature of its getter, e.g. "getFoo(Ljava/lang/String;)I". If the property has no getter in the bytecode
* (e.g. private property in a class), it's still the signature of the imaginary default getter that would be generated otherwise.
*
* Note that technically the signature itself is not even used as a signature per se in reflection implementation,
* but only as a unique and unambiguous way to map a function/property descriptor to a string.
*/
public String getSignature() {
throw new AbstractMethodError();
}
// The following methods are the delegating implementations of reflection functions. They are called when you're using reflection
// on a callable reference. Without kotlin-reflect.jar in the classpath, getReflected() throws an exception.
@Override
public List<KParameter> getParameters() {
return getReflected().getParameters();
}
@Override
public KType getReturnType() {
return getReflected().getReturnType();
}
@Override
public List<Annotation> getAnnotations() {
return getReflected().getAnnotations();
}
@Override
@SinceKotlin(version = "1.1")
public List<KTypeParameter> getTypeParameters() {
return getReflected().getTypeParameters();
}
@Override
public Object call(Object... args) {
return getReflected().call(args);
}
@Override
public Object callBy(Map args) {
return getReflected().callBy(args);
}
@Override
@SinceKotlin(version = "1.1")
public KVisibility getVisibility() {
return getReflected().getVisibility();
}
@Override
@SinceKotlin(version = "1.1")
public boolean isFinal() {
return getReflected().isFinal();
}
@Override
@SinceKotlin(version = "1.1")
public boolean isOpen() {
return getReflected().isOpen();
}
@Override
@SinceKotlin(version = "1.1")
public boolean isAbstract() {
return getReflected().isAbstract();
}
}
@@ -0,0 +1,23 @@
/*
* 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.jvm.internal
import kotlin.reflect.KDeclarationContainer
public interface ClassBasedDeclarationContainer : KDeclarationContainer {
public val jClass: Class<*>
}
@@ -0,0 +1,96 @@
/*
* 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.jvm.internal
import kotlin.reflect.*
public class ClassReference(override val jClass: Class<*>) : KClass<Any>, ClassBasedDeclarationContainer {
override val simpleName: String?
get() = error()
override val qualifiedName: String?
get() = error()
override val members: Collection<KCallable<*>>
get() = error()
override val constructors: Collection<KFunction<Any>>
get() = error()
override val nestedClasses: Collection<KClass<*>>
get() = error()
override val annotations: List<Annotation>
get() = error()
override val objectInstance: Any?
get() = error()
@SinceKotlin("1.1")
override fun isInstance(value: Any?): Boolean = error()
@SinceKotlin("1.1")
override val typeParameters: List<KTypeParameter>
get() = error()
@SinceKotlin("1.1")
override val supertypes: List<KType>
get() = error()
@SinceKotlin("1.1")
override val visibility: KVisibility?
get() = error()
@SinceKotlin("1.1")
override val isFinal: Boolean
get() = error()
@SinceKotlin("1.1")
override val isOpen: Boolean
get() = error()
@SinceKotlin("1.1")
override val isAbstract: Boolean
get() = error()
@SinceKotlin("1.1")
override val isSealed: Boolean
get() = error()
@SinceKotlin("1.1")
override val isData: Boolean
get() = error()
@SinceKotlin("1.1")
override val isInner: Boolean
get() = error()
@SinceKotlin("1.1")
override val isCompanion: Boolean
get() = error()
private fun error(): Nothing = throw KotlinReflectionNotSupportedError()
override fun equals(other: Any?) =
other is ClassReference && javaObjectType == other.javaObjectType
override fun hashCode() =
javaObjectType.hashCode()
override fun toString() =
jClass.toString() + Reflection.REFLECTION_NOT_AVAILABLE
}
@@ -0,0 +1,81 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
@file:JvmName("CollectionToArray")
package kotlin.jvm.internal
import java.lang.reflect.Array as JavaArray
import java.lang.NullPointerException as JavaNPE
import java.util.Arrays
private val EMPTY = emptyArray<Any?>() // shared empty array
private const val MAX_SIZE = Int.MAX_VALUE - 2 // empirically maximal array size that can be allocated without exceeding VM limits
@JvmName("toArray")
fun collectionToArray(collection: Collection<*>): Array<Any?> =
toArrayImpl(
collection,
empty = { EMPTY },
alloc = { size -> arrayOfNulls<Any?>(size) },
trim = { result, size -> Arrays.copyOf(result, size) }
)
// Note: Array<Any?> here can have any reference array JVM type at run time
@JvmName("toArray")
fun collectionToArray(collection: Collection<*>, a: Array<Any?>?): Array<Any?> {
// Collection.toArray contract requires that NullPointerException is thrown when array is null
if (a == null) throw JavaNPE()
return toArrayImpl(
collection,
empty = {
if (a.size > 0) a[0] = null
a
},
alloc = { size ->
@Suppress("UNCHECKED_CAST")
if (size <= a.size) a else JavaArray.newInstance(a.javaClass.componentType, size) as Array<Any?>
},
trim = { result, size ->
if (result === a) {
a[size] = null
a
} else
Arrays.copyOf(result, size)
}
)
}
private inline fun toArrayImpl(
collection: Collection<*>,
empty: () -> Array<Any?>,
alloc: (Int) -> Array<Any?>,
trim: (Array<Any?>, Int) -> Array<Any?>
): Array<Any?> {
val size = collection.size
if (size == 0) return empty() // quick path on zero size
val iter = collection.iterator() // allocate iterator for non-empty collection
if (!iter.hasNext()) return empty() // size was > 0, but no actual elements
var result = alloc(size) // use size as a guess to allocate result array
var i = 0
// invariant: iter.hasNext is true && i < result.size
while (true) {
result[i++] = iter.next()
if (i >= result.size) {
if (!iter.hasNext()) return result // perfect match of array size
// array size was too small -- grow array (invariant: i == result.size > 0 here)
// now grow at a factor of 1.5 (we expect this to be extremely rare, but still use fast code)
// note that corner case here is when i == 1 (should get newSize == 2)
var newSize = (i * 3 + 1) ushr 1
if (newSize <= i) { // detect overflow in the above line
if (i >= MAX_SIZE) throw OutOfMemoryError() // exceeded max array that VM can allocate
newSize = MAX_SIZE // try max array size that VM can allocate
}
result = Arrays.copyOf(result, newSize)
} else {
if (!iter.hasNext()) return trim(result, i) // ended too early (allocated array too big)
}
}
}
@@ -0,0 +1,21 @@
/*
* 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.jvm.internal;
final class DefaultConstructorMarker {
private DefaultConstructorMarker() {}
}
@@ -0,0 +1,25 @@
/*
* 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.jvm.internal;
import kotlin.Function;
import java.io.Serializable;
public interface FunctionBase extends Function, Serializable {
int getArity();
}
@@ -0,0 +1,188 @@
/*
* 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.jvm.internal;
import kotlin.DeprecationLevel;
import kotlin.Function;
import kotlin.jvm.functions.*;
import java.io.Serializable;
@SuppressWarnings("unused")
@Deprecated
@kotlin.Deprecated(message = "This class is no longer supported, do not use it.", level = DeprecationLevel.ERROR)
public abstract class FunctionImpl
implements Function, Serializable,
Function0, Function1, Function2, Function3, Function4, Function5, Function6, Function7, Function8, Function9,
Function10, Function11, Function12, Function13, Function14, Function15, Function16, Function17, Function18, Function19,
Function20, Function21, Function22 {
public abstract int getArity();
@SuppressWarnings({"WeakerAccess", "MethodMayBeStatic"})
public Object invokeVararg(Object... p) {
throw new UnsupportedOperationException();
}
private void checkArity(int expected) {
if (getArity() != expected) {
throwWrongArity(expected);
}
}
private void throwWrongArity(int expected) {
throw new IllegalStateException("Wrong function arity, expected: " + expected + ", actual: " + getArity());
}
@Override
public Object invoke() {
checkArity(0);
return invokeVararg();
}
@Override
public Object invoke(Object p1) {
checkArity(1);
return invokeVararg(p1);
}
@Override
public Object invoke(Object p1, Object p2) {
checkArity(2);
return invokeVararg(p1, p2);
}
@Override
public Object invoke(Object p1, Object p2, Object p3) {
checkArity(3);
return invokeVararg(p1, p2, p3);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4) {
checkArity(4);
return invokeVararg(p1, p2, p3, p4);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5) {
checkArity(5);
return invokeVararg(p1, p2, p3, p4, p5);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) {
checkArity(6);
return invokeVararg(p1, p2, p3, p4, p5, p6);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7) {
checkArity(7);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8) {
checkArity(8);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9) {
checkArity(9);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10) {
checkArity(10);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11) {
checkArity(11);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12) {
checkArity(12);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13) {
checkArity(13);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13, Object p14) {
checkArity(14);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13, Object p14, Object p15) {
checkArity(15);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13, Object p14, Object p15, Object p16) {
checkArity(16);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13, Object p14, Object p15, Object p16, Object p17) {
checkArity(17);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13, Object p14, Object p15, Object p16, Object p17, Object p18) {
checkArity(18);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13, Object p14, Object p15, Object p16, Object p17, Object p18, Object p19) {
checkArity(19);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13, Object p14, Object p15, Object p16, Object p17, Object p18, Object p19, Object p20) {
checkArity(20);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13, Object p14, Object p15, Object p16, Object p17, Object p18, Object p19, Object p20, Object p21) {
checkArity(21);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21);
}
@Override
public Object invoke(Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10, Object p11, Object p12, Object p13, Object p14, Object p15, Object p16, Object p17, Object p18, Object p19, Object p20, Object p21, Object p22) {
checkArity(22);
return invokeVararg(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22);
}
}
@@ -0,0 +1,117 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KFunction;
public class FunctionReference extends CallableReference implements FunctionBase, KFunction {
private final int arity;
public FunctionReference(int arity) {
this.arity = arity;
}
@SinceKotlin(version = "1.1")
public FunctionReference(int arity, Object receiver) {
super(receiver);
this.arity = arity;
}
@Override
public int getArity() {
return arity;
}
@Override
@SinceKotlin(version = "1.1")
protected KFunction getReflected() {
return (KFunction) super.getReflected();
}
@Override
@SinceKotlin(version = "1.1")
protected KCallable computeReflected() {
return Reflection.function(this);
}
@Override
@SinceKotlin(version = "1.1")
public boolean isInline() {
return getReflected().isInline();
}
@Override
@SinceKotlin(version = "1.1")
public boolean isExternal() {
return getReflected().isExternal();
}
@Override
@SinceKotlin(version = "1.1")
public boolean isOperator() {
return getReflected().isOperator();
}
@Override
@SinceKotlin(version = "1.1")
public boolean isInfix() {
return getReflected().isInfix();
}
@Override
@SinceKotlin(version = "1.1")
public boolean isSuspend() {
return getReflected().isSuspend();
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj instanceof FunctionReference) {
FunctionReference other = (FunctionReference) obj;
return (getOwner() == null ? other.getOwner() == null : getOwner().equals(other.getOwner())) &&
getName().equals(other.getName()) &&
getSignature().equals(other.getSignature()) &&
Intrinsics.areEqual(getBoundReceiver(), other.getBoundReceiver());
}
if (obj instanceof KFunction) {
return obj.equals(compute());
}
return false;
}
@Override
public int hashCode() {
return ((getOwner() == null ? 0 : getOwner().hashCode() * 31) + getName().hashCode()) * 31 + getSignature().hashCode();
}
@Override
public String toString() {
KCallable reflected = compute();
if (reflected != this) {
return reflected.toString();
}
// TODO: consider adding the class name to toString() for constructors
return "<init>".equals(getName())
? "constructor" + Reflection.REFLECTION_NOT_AVAILABLE
: "function " + getName() + Reflection.REFLECTION_NOT_AVAILABLE;
}
}
@@ -0,0 +1,47 @@
/*
* 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.jvm.internal;
import kotlin.reflect.KDeclarationContainer;
public class FunctionReferenceImpl extends FunctionReference {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public FunctionReferenceImpl(int arity, KDeclarationContainer owner, String name, String signature) {
super(arity);
this.owner = owner;
this.name = name;
this.signature = signature;
}
@Override
public KDeclarationContainer getOwner() {
return owner;
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
}
}
@@ -0,0 +1,37 @@
/*
* 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.jvm.internal;
public class InlineMarker {
public static void mark(int i) {
}
public static void mark(String name) {
}
public static void beforeInlineCall() {
}
public static void afterInlineCall() {
}
public static void finallyStart(int finallyDepth) {
}
public static void finallyEnd(int finallyDepth) {
}
}
@@ -0,0 +1,266 @@
/*
* 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.jvm.internal;
import kotlin.KotlinNullPointerException;
import kotlin.SinceKotlin;
import kotlin.UninitializedPropertyAccessException;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("unused")
public class Intrinsics {
private Intrinsics() {
}
public static String stringPlus(String self, Object other) {
return self + other;
}
public static void checkNotNull(Object object) {
if (object == null) {
throwNpe();
}
}
public static void checkNotNull(Object object, String message) {
if (object == null) {
throwNpe(message);
}
}
public static void throwNpe() {
throw sanitizeStackTrace(new KotlinNullPointerException());
}
public static void throwNpe(String message) {
throw sanitizeStackTrace(new KotlinNullPointerException(message));
}
public static void throwUninitializedProperty(String message) {
throw sanitizeStackTrace(new UninitializedPropertyAccessException(message));
}
public static void throwUninitializedPropertyAccessException(String propertyName) {
throwUninitializedProperty("lateinit property " + propertyName + " has not been initialized");
}
public static void throwAssert() {
throw sanitizeStackTrace(new AssertionError());
}
public static void throwAssert(String message) {
throw sanitizeStackTrace(new AssertionError(message));
}
public static void throwIllegalArgument() {
throw sanitizeStackTrace(new IllegalArgumentException());
}
public static void throwIllegalArgument(String message) {
throw sanitizeStackTrace(new IllegalArgumentException(message));
}
public static void throwIllegalState() {
throw sanitizeStackTrace(new IllegalStateException());
}
public static void throwIllegalState(String message) {
throw sanitizeStackTrace(new IllegalStateException(message));
}
public static void checkExpressionValueIsNotNull(Object value, String expression) {
if (value == null) {
throw sanitizeStackTrace(new IllegalStateException(expression + " must not be null"));
}
}
public static void checkNotNullExpressionValue(Object value, String message) {
if (value == null) {
throw sanitizeStackTrace(new IllegalStateException(message));
}
}
public static void checkReturnedValueIsNotNull(Object value, String className, String methodName) {
if (value == null) {
throw sanitizeStackTrace(
new IllegalStateException("Method specified as non-null returned null: " + className + "." + methodName)
);
}
}
public static void checkReturnedValueIsNotNull(Object value, String message) {
if (value == null) {
throw sanitizeStackTrace(new IllegalStateException(message));
}
}
public static void checkFieldIsNotNull(Object value, String className, String fieldName) {
if (value == null) {
throw sanitizeStackTrace(new IllegalStateException("Field specified as non-null is null: " + className + "." + fieldName));
}
}
public static void checkFieldIsNotNull(Object value, String message) {
if (value == null) {
throw sanitizeStackTrace(new IllegalStateException(message));
}
}
public static void checkParameterIsNotNull(Object value, String paramName) {
if (value == null) {
throwParameterIsNullException(paramName);
}
}
public static void checkNotNullParameter(Object value, String message) {
if (value == null) {
throw sanitizeStackTrace(new IllegalArgumentException(message));
}
}
private static void throwParameterIsNullException(String paramName) {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
// #0 Thread.getStackTrace()
// #1 Intrinsics.throwParameterIsNullException
// #2 Intrinsics.checkParameterIsNotNull
// #3 our caller
StackTraceElement caller = stackTraceElements[3];
String className = caller.getClassName();
String methodName = caller.getMethodName();
IllegalArgumentException exception =
new IllegalArgumentException("Parameter specified as non-null is null: " +
"method " + className + "." + methodName +
", parameter " + paramName);
throw sanitizeStackTrace(exception);
}
public static int compare(long thisVal, long anotherVal) {
return thisVal < anotherVal ? -1 : thisVal == anotherVal ? 0 : 1;
}
public static int compare(int thisVal, int anotherVal) {
return thisVal < anotherVal ? -1 : thisVal == anotherVal ? 0 : 1;
}
public static boolean areEqual(Object first, Object second) {
return first == null ? second == null : first.equals(second);
}
@SinceKotlin(version = "1.1")
public static boolean areEqual(Double first, Double second) {
return first == null ? second == null : second != null && first.doubleValue() == second.doubleValue();
}
@SinceKotlin(version = "1.1")
public static boolean areEqual(Double first, double second) {
return first != null && first.doubleValue() == second;
}
@SinceKotlin(version = "1.1")
public static boolean areEqual(double first, Double second) {
return second != null && first == second.doubleValue();
}
@SinceKotlin(version = "1.1")
public static boolean areEqual(Float first, Float second) {
return first == null ? second == null : second != null && first.floatValue() == second.floatValue();
}
@SinceKotlin(version = "1.1")
public static boolean areEqual(Float first, float second) {
return first != null && first.floatValue() == second;
}
@SinceKotlin(version = "1.1")
public static boolean areEqual(float first, Float second) {
return second != null && first == second.floatValue();
}
public static void throwUndefinedForReified() {
throwUndefinedForReified(
"This function has a reified type parameter and thus can only be inlined at compilation time, not called directly."
);
}
public static void throwUndefinedForReified(String message) {
throw new UnsupportedOperationException(message);
}
public static void reifiedOperationMarker(int id, String typeParameterIdentifier) {
throwUndefinedForReified();
}
public static void reifiedOperationMarker(int id, String typeParameterIdentifier, String message) {
throwUndefinedForReified(message);
}
public static void needClassReification() {
throwUndefinedForReified();
}
public static void needClassReification(String message) {
throwUndefinedForReified(message);
}
public static void checkHasClass(String internalName) throws ClassNotFoundException {
String fqName = internalName.replace('/', '.');
try {
Class.forName(fqName);
}
catch (ClassNotFoundException e) {
throw sanitizeStackTrace(new ClassNotFoundException(
"Class " + fqName + " is not found. Please update the Kotlin runtime to the latest version", e
));
}
}
public static void checkHasClass(String internalName, String requiredVersion) throws ClassNotFoundException {
String fqName = internalName.replace('/', '.');
try {
Class.forName(fqName);
}
catch (ClassNotFoundException e) {
throw sanitizeStackTrace(new ClassNotFoundException(
"Class " + fqName + " is not found: this code requires the Kotlin runtime of version at least " + requiredVersion, e
));
}
}
private static <T extends Throwable> T sanitizeStackTrace(T throwable) {
return sanitizeStackTrace(throwable, Intrinsics.class.getName());
}
static <T extends Throwable> T sanitizeStackTrace(T throwable, String classNameToDrop) {
StackTraceElement[] stackTrace = throwable.getStackTrace();
int size = stackTrace.length;
int lastIntrinsic = -1;
for (int i = 0; i < size; i++) {
if (classNameToDrop.equals(stackTrace[i].getClassName())) {
lastIntrinsic = i;
}
}
List<StackTraceElement> list = Arrays.asList(stackTrace).subList(lastIntrinsic + 1, size);
throwable.setStackTrace(list.toArray(new StackTraceElement[list.size()]));
return throwable;
}
}
@@ -0,0 +1,23 @@
/*
* 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.jvm.internal
public abstract class Lambda(private val arity: Int) : FunctionBase {
override fun getArity() = arity
override fun toString() = Reflection.renderLambdaToString(this)
}
@@ -0,0 +1,76 @@
/*
* Copyright 2010-2017 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.jvm.internal;
import kotlin.SinceKotlin;
@SinceKotlin(version = "1.2")
public class MagicApiIntrinsics {
public static <T> T anyMagicApiCall(int id) {
return null;
}
public static void voidMagicApiCall(int id) {
}
public static int intMagicApiCall(int id) {
return 0;
}
public static <T> T anyMagicApiCall(Object data) {
return null;
}
public static void voidMagicApiCall(Object data) {
}
public static int intMagicApiCall(Object data) {
return 0;
}
public static int intMagicApiCall(int id, long longData, Object anyData) {
return 0;
}
public static int intMagicApiCall(int id, long longData1, long longData2, Object anyData) {
return 0;
}
public static int intMagicApiCall(int id, Object anyData1, Object anyData2) {
return 0;
}
public static int intMagicApiCall(int id, Object anyData1, Object anyData2, Object anyData3, Object anyData4) {
return 0;
}
public static <T> T anyMagicApiCall(int id, long longData, Object anyData) {
return null;
}
public static <T> T anyMagicApiCall(int id, long longData1, long longData2, Object anyData) {
return null;
}
public static <T> T anyMagicApiCall(int id, Object anyData1, Object anyData2) {
return null;
}
public static <T> T anyMagicApiCall(int id, Object anyData1, Object anyData2, Object anyData3, Object anyData4) {
return null;
}
}
@@ -0,0 +1,30 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KMutableProperty;
public abstract class MutablePropertyReference extends PropertyReference implements KMutableProperty {
public MutablePropertyReference() {
}
@SinceKotlin(version = "1.1")
public MutablePropertyReference(Object receiver) {
super(receiver);
}
}
@@ -0,0 +1,58 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KMutableProperty0;
import kotlin.reflect.KProperty0;
public abstract class MutablePropertyReference0 extends MutablePropertyReference implements KMutableProperty0 {
public MutablePropertyReference0() {
}
@SinceKotlin(version = "1.1")
public MutablePropertyReference0(Object receiver) {
super(receiver);
}
@Override
protected KCallable computeReflected() {
return Reflection.mutableProperty0(this);
}
@Override
public Object invoke() {
return get();
}
@Override
public KProperty0.Getter getGetter() {
return ((KMutableProperty0) getReflected()).getGetter();
}
@Override
public KMutableProperty0.Setter getSetter() {
return ((KMutableProperty0) getReflected()).getSetter();
}
@Override
@SinceKotlin(version = "1.1")
public Object getDelegate() {
return ((KMutableProperty0) getReflected()).getDelegate();
}
}
@@ -0,0 +1,56 @@
/*
* 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.jvm.internal;
import kotlin.reflect.KDeclarationContainer;
public class MutablePropertyReference0Impl extends MutablePropertyReference0 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public MutablePropertyReference0Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
}
@Override
public KDeclarationContainer getOwner() {
return owner;
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
}
@Override
public Object get() {
return getGetter().call();
}
@Override
public void set(Object value) {
getSetter().call(value);
}
}
@@ -0,0 +1,58 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KMutableProperty1;
import kotlin.reflect.KProperty1;
public abstract class MutablePropertyReference1 extends MutablePropertyReference implements KMutableProperty1 {
public MutablePropertyReference1() {
}
@SinceKotlin(version = "1.1")
public MutablePropertyReference1(Object receiver) {
super(receiver);
}
@Override
protected KCallable computeReflected() {
return Reflection.mutableProperty1(this);
}
@Override
public Object invoke(Object receiver) {
return get(receiver);
}
@Override
public KProperty1.Getter getGetter() {
return ((KMutableProperty1) getReflected()).getGetter();
}
@Override
public KMutableProperty1.Setter getSetter() {
return ((KMutableProperty1) getReflected()).getSetter();
}
@Override
@SinceKotlin(version = "1.1")
public Object getDelegate(Object receiver) {
return ((KMutableProperty1) getReflected()).getDelegate(receiver);
}
}
@@ -0,0 +1,56 @@
/*
* 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.jvm.internal;
import kotlin.reflect.KDeclarationContainer;
public class MutablePropertyReference1Impl extends MutablePropertyReference1 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public MutablePropertyReference1Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
}
@Override
public KDeclarationContainer getOwner() {
return owner;
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
}
@Override
public Object get(Object receiver) {
return getGetter().call(receiver);
}
@Override
public void set(Object receiver, Object value) {
getSetter().call(receiver, value);
}
}
@@ -0,0 +1,50 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KMutableProperty2;
import kotlin.reflect.KProperty2;
public abstract class MutablePropertyReference2 extends MutablePropertyReference implements KMutableProperty2 {
@Override
protected KCallable computeReflected() {
return Reflection.mutableProperty2(this);
}
@Override
public Object invoke(Object receiver1, Object receiver2) {
return get(receiver1, receiver2);
}
@Override
public KProperty2.Getter getGetter() {
return ((KMutableProperty2) getReflected()).getGetter();
}
@Override
public KMutableProperty2.Setter getSetter() {
return ((KMutableProperty2) getReflected()).getSetter();
}
@Override
@SinceKotlin(version = "1.1")
public Object getDelegate(Object receiver1, Object receiver2) {
return ((KMutableProperty2) getReflected()).getDelegate(receiver1, receiver2);
}
}
@@ -0,0 +1,56 @@
/*
* 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.jvm.internal;
import kotlin.reflect.KDeclarationContainer;
public class MutablePropertyReference2Impl extends MutablePropertyReference2 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public MutablePropertyReference2Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
}
@Override
public KDeclarationContainer getOwner() {
return owner;
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
}
@Override
public Object get(Object receiver1, Object receiver2) {
return getGetter().call(receiver1, receiver2);
}
@Override
public void set(Object receiver1, Object receiver2, Object value) {
getSetter().call(receiver1, receiver2, value);
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2017 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.jvm.internal
import kotlin.reflect.KCallable
@SinceKotlin("1.1")
public class PackageReference(
override val jClass: Class<*>,
@Suppress("unused") private val moduleName: String
) : ClassBasedDeclarationContainer {
override val members: Collection<KCallable<*>>
get() = throw KotlinReflectionNotSupportedError()
override fun equals(other: Any?) =
other is PackageReference && jClass == other.jClass
override fun hashCode() =
jClass.hashCode()
override fun toString() =
jClass.toString() + Reflection.REFLECTION_NOT_AVAILABLE
}
@@ -0,0 +1,66 @@
/*
* 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.jvm.internal
internal object DoubleCompanionObject {
val MIN_VALUE: Double = java.lang.Double.MIN_VALUE
val MAX_VALUE: Double = java.lang.Double.MAX_VALUE
val POSITIVE_INFINITY : Double = java.lang.Double.POSITIVE_INFINITY
val NEGATIVE_INFINITY : Double = java.lang.Double.NEGATIVE_INFINITY
val NaN : Double = java.lang.Double.NaN
}
internal object FloatCompanionObject {
val MIN_VALUE: Float = java.lang.Float.MIN_VALUE
val MAX_VALUE: Float = java.lang.Float.MAX_VALUE
val POSITIVE_INFINITY : Float = java.lang.Float.POSITIVE_INFINITY
val NEGATIVE_INFINITY : Float = java.lang.Float.NEGATIVE_INFINITY
val NaN : Float = java.lang.Float.NaN
}
internal object IntCompanionObject {
const val MIN_VALUE: Int = java.lang.Integer.MIN_VALUE
const val MAX_VALUE: Int = java.lang.Integer.MAX_VALUE
}
internal object LongCompanionObject {
const val MIN_VALUE: Long = java.lang.Long.MIN_VALUE
const val MAX_VALUE: Long = java.lang.Long.MAX_VALUE
}
internal object ShortCompanionObject {
const val MIN_VALUE: Short = java.lang.Short.MIN_VALUE
const val MAX_VALUE: Short = java.lang.Short.MAX_VALUE
}
internal object ByteCompanionObject {
const val MIN_VALUE: Byte = java.lang.Byte.MIN_VALUE
const val MAX_VALUE: Byte = java.lang.Byte.MAX_VALUE
}
internal object CharCompanionObject {
const val MIN_HIGH_SURROGATE: Char = '\uD800'
const val MAX_HIGH_SURROGATE: Char = '\uDBFF'
const val MIN_LOW_SURROGATE: Char = '\uDC00'
const val MAX_LOW_SURROGATE: Char = '\uDFFF'
const val MIN_SURROGATE: Char = MIN_HIGH_SURROGATE
const val MAX_SURROGATE: Char = MAX_LOW_SURROGATE
}
internal object StringCompanionObject {}
internal object EnumCompanionObject {}
@@ -0,0 +1,149 @@
/*
* 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.jvm.internal
public abstract class PrimitiveSpreadBuilder<T : Any>(private val size: Int) {
abstract protected fun T.getSize(): Int
protected var position: Int = 0
@Suppress("UNCHECKED_CAST")
private val spreads: Array<T?> = arrayOfNulls<Any>(size) as Array<T?>
public fun addSpread(spreadArgument: T) {
spreads[position++] = spreadArgument
}
protected fun size(): Int {
var totalLength = 0
for (i in 0..size - 1) {
totalLength += spreads[i]?.getSize() ?: 1
}
return totalLength
}
protected fun toArray(values: T, result: T): T {
var dstIndex = 0
var copyValuesFrom = 0
for (i in 0..size - 1) {
val spreadArgument = spreads[i]
if (spreadArgument != null) {
if (copyValuesFrom < i) {
System.arraycopy(values, copyValuesFrom, result, dstIndex, i - copyValuesFrom)
dstIndex += i - copyValuesFrom
}
val spreadSize = spreadArgument.getSize()
System.arraycopy(spreadArgument, 0, result, dstIndex, spreadSize)
dstIndex += spreadSize
copyValuesFrom = i + 1
}
}
if (copyValuesFrom < size) {
System.arraycopy(values, copyValuesFrom, result, dstIndex, size - copyValuesFrom)
}
return result
}
}
public class ByteSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<ByteArray>(size) {
private val values: ByteArray = ByteArray(size)
override fun ByteArray.getSize(): Int = this.size
public fun add(value: Byte) {
values[position++] = value
}
public fun toArray(): ByteArray = toArray(values, ByteArray(size()))
}
public class CharSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<CharArray>(size) {
private val values: CharArray = CharArray(size)
override fun CharArray.getSize(): Int = this.size
public fun add(value: Char) {
values[position++] = value
}
public fun toArray(): CharArray = toArray(values, CharArray(size()))
}
public class DoubleSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<DoubleArray>(size) {
private val values: DoubleArray = DoubleArray(size)
override fun DoubleArray.getSize(): Int = this.size
public fun add(value: Double) {
values[position++] = value
}
public fun toArray(): DoubleArray = toArray(values, DoubleArray(size()))
}
public class FloatSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<FloatArray>(size) {
private val values: FloatArray = FloatArray(size)
override fun FloatArray.getSize(): Int = this.size
public fun add(value: Float) {
values[position++] = value
}
public fun toArray(): FloatArray = toArray(values, FloatArray(size()))
}
public class IntSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<IntArray>(size) {
private val values: IntArray = IntArray(size)
override fun IntArray.getSize(): Int = this.size
public fun add(value: Int) {
values[position++] = value
}
public fun toArray(): IntArray = toArray(values, IntArray(size()))
}
public class LongSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<LongArray>(size) {
private val values: LongArray = LongArray(size)
override fun LongArray.getSize(): Int = this.size
public fun add(value: Long) {
values[position++] = value
}
public fun toArray(): LongArray = toArray(values, LongArray(size()))
}
public class ShortSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<ShortArray>(size) {
private val values: ShortArray = ShortArray(size)
override fun ShortArray.getSize(): Int = this.size
public fun add(value: Short) {
values[position++] = value
}
public fun toArray(): ShortArray = toArray(values, ShortArray(size()))
}
public class BooleanSpreadBuilder(size: Int) : PrimitiveSpreadBuilder<BooleanArray>(size) {
private val values: BooleanArray = BooleanArray(size)
override fun BooleanArray.getSize(): Int = this.size
public fun add(value: Boolean) {
values[position++] = value
}
public fun toArray(): BooleanArray = toArray(values, BooleanArray(size()))
}
@@ -0,0 +1,81 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KProperty;
public abstract class PropertyReference extends CallableReference implements KProperty {
public PropertyReference() {
super();
}
@SinceKotlin(version = "1.1")
public PropertyReference(Object receiver) {
super(receiver);
}
@Override
@SinceKotlin(version = "1.1")
protected KProperty getReflected() {
return (KProperty) super.getReflected();
}
@Override
@SinceKotlin(version = "1.1")
public boolean isLateinit() {
return getReflected().isLateinit();
}
@Override
@SinceKotlin(version = "1.1")
public boolean isConst() {
return getReflected().isConst();
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj instanceof PropertyReference) {
PropertyReference other = (PropertyReference) obj;
return getOwner().equals(other.getOwner()) &&
getName().equals(other.getName()) &&
getSignature().equals(other.getSignature()) &&
Intrinsics.areEqual(getBoundReceiver(), other.getBoundReceiver());
}
if (obj instanceof KProperty) {
return obj.equals(compute());
}
return false;
}
@Override
public int hashCode() {
return (getOwner().hashCode() * 31 + getName().hashCode()) * 31 + getSignature().hashCode();
}
@Override
public String toString() {
KCallable reflected = compute();
if (reflected != this) {
return reflected.toString();
}
return "property " + getName() + Reflection.REFLECTION_NOT_AVAILABLE;
}
}
@@ -0,0 +1,53 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KProperty0;
public abstract class PropertyReference0 extends PropertyReference implements KProperty0 {
public PropertyReference0() {
super();
}
@SinceKotlin(version = "1.1")
public PropertyReference0(Object receiver) {
super(receiver);
}
@Override
protected KCallable computeReflected() {
return Reflection.property0(this);
}
@Override
public Object invoke() {
return get();
}
@Override
public KProperty0.Getter getGetter() {
return ((KProperty0) getReflected()).getGetter();
}
@Override
@SinceKotlin(version = "1.1")
public Object getDelegate() {
return ((KProperty0) getReflected()).getDelegate();
}
}
@@ -0,0 +1,51 @@
/*
* 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.jvm.internal;
import kotlin.reflect.KDeclarationContainer;
public class PropertyReference0Impl extends PropertyReference0 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public PropertyReference0Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
}
@Override
public KDeclarationContainer getOwner() {
return owner;
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
}
@Override
public Object get() {
return getGetter().call();
}
}
@@ -0,0 +1,52 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KProperty1;
public abstract class PropertyReference1 extends PropertyReference implements KProperty1 {
public PropertyReference1() {
}
@SinceKotlin(version = "1.1")
public PropertyReference1(Object receiver) {
super(receiver);
}
@Override
protected KCallable computeReflected() {
return Reflection.property1(this);
}
@Override
public Object invoke(Object receiver) {
return get(receiver);
}
@Override
public KProperty1.Getter getGetter() {
return ((KProperty1) getReflected()).getGetter();
}
@Override
@SinceKotlin(version = "1.1")
public Object getDelegate(Object receiver) {
return ((KProperty1) getReflected()).getDelegate(receiver);
}
}
@@ -0,0 +1,51 @@
/*
* 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.jvm.internal;
import kotlin.reflect.KDeclarationContainer;
public class PropertyReference1Impl extends PropertyReference1 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public PropertyReference1Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
}
@Override
public KDeclarationContainer getOwner() {
return owner;
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
}
@Override
public Object get(Object receiver) {
return getGetter().call(receiver);
}
}
@@ -0,0 +1,44 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.KCallable;
import kotlin.reflect.KProperty2;
public abstract class PropertyReference2 extends PropertyReference implements KProperty2 {
@Override
protected KCallable computeReflected() {
return Reflection.property2(this);
}
@Override
public Object invoke(Object receiver1, Object receiver2) {
return get(receiver1, receiver2);
}
@Override
public KProperty2.Getter getGetter() {
return ((KProperty2) getReflected()).getGetter();
}
@Override
@SinceKotlin(version = "1.1")
public Object getDelegate(Object receiver1, Object receiver2) {
return ((KProperty2) getReflected()).getDelegate(receiver1, receiver2);
}
}
@@ -0,0 +1,51 @@
/*
* 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.jvm.internal;
import kotlin.reflect.KDeclarationContainer;
public class PropertyReference2Impl extends PropertyReference2 {
private final KDeclarationContainer owner;
private final String name;
private final String signature;
public PropertyReference2Impl(KDeclarationContainer owner, String name, String signature) {
this.owner = owner;
this.name = name;
this.signature = signature;
}
@Override
public KDeclarationContainer getOwner() {
return owner;
}
@Override
public String getName() {
return name;
}
@Override
public String getSignature() {
return signature;
}
@Override
public Object get(Object receiver1, Object receiver2) {
return getGetter().call(receiver1, receiver2);
}
}
@@ -0,0 +1,104 @@
/*
* 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.jvm.internal;
import java.io.Serializable;
public class Ref {
private Ref() {}
public static final class ObjectRef<T> implements Serializable {
public T element;
@Override
public String toString() {
return String.valueOf(element);
}
}
public static final class ByteRef implements Serializable {
public byte element;
@Override
public String toString() {
return String.valueOf(element);
}
}
public static final class ShortRef implements Serializable {
public short element;
@Override
public String toString() {
return String.valueOf(element);
}
}
public static final class IntRef implements Serializable {
public int element;
@Override
public String toString() {
return String.valueOf(element);
}
}
public static final class LongRef implements Serializable {
public long element;
@Override
public String toString() {
return String.valueOf(element);
}
}
public static final class FloatRef implements Serializable {
public float element;
@Override
public String toString() {
return String.valueOf(element);
}
}
public static final class DoubleRef implements Serializable {
public double element;
@Override
public String toString() {
return String.valueOf(element);
}
}
public static final class CharRef implements Serializable {
public char element;
@Override
public String toString() {
return String.valueOf(element);
}
}
public static final class BooleanRef implements Serializable {
public boolean element;
@Override
public String toString() {
return String.valueOf(element);
}
}
}
@@ -0,0 +1,114 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.*;
/**
* This class serves as a facade to the actual reflection implementation. JVM back-end generates calls to static methods of this class
* on any reflection-using construct.
*/
@SuppressWarnings("unused")
public class Reflection {
private static final ReflectionFactory factory;
static {
ReflectionFactory impl;
try {
Class<?> implClass = Class.forName("kotlin.reflect.jvm.internal.ReflectionFactoryImpl");
impl = (ReflectionFactory) implClass.newInstance();
}
catch (ClassCastException e) { impl = null; }
catch (ClassNotFoundException e) { impl = null; }
catch (InstantiationException e) { impl = null; }
catch (IllegalAccessException e) { impl = null; }
factory = impl != null ? impl : new ReflectionFactory();
}
/* package */ static final String REFLECTION_NOT_AVAILABLE = " (Kotlin reflection is not available)";
private static final KClass[] EMPTY_K_CLASS_ARRAY = new KClass[0];
public static KClass createKotlinClass(Class javaClass) {
return factory.createKotlinClass(javaClass);
}
public static KClass createKotlinClass(Class javaClass, String internalName) {
return factory.createKotlinClass(javaClass, internalName);
}
public static KDeclarationContainer getOrCreateKotlinPackage(Class javaClass, String moduleName) {
return factory.getOrCreateKotlinPackage(javaClass, moduleName);
}
public static KClass getOrCreateKotlinClass(Class javaClass) {
return factory.getOrCreateKotlinClass(javaClass);
}
public static KClass getOrCreateKotlinClass(Class javaClass, String internalName) {
return factory.getOrCreateKotlinClass(javaClass, internalName);
}
public static KClass[] getOrCreateKotlinClasses(Class[] javaClasses) {
int size = javaClasses.length;
if (size == 0) return EMPTY_K_CLASS_ARRAY;
KClass[] kClasses = new KClass[size];
for (int i = 0; i < size; i++) {
kClasses[i] = getOrCreateKotlinClass(javaClasses[i]);
}
return kClasses;
}
@SinceKotlin(version = "1.1")
public static String renderLambdaToString(Lambda lambda) {
return factory.renderLambdaToString(lambda);
}
// Functions
public static KFunction function(FunctionReference f) {
return factory.function(f);
}
// Properties
public static KProperty0 property0(PropertyReference0 p) {
return factory.property0(p);
}
public static KMutableProperty0 mutableProperty0(MutablePropertyReference0 p) {
return factory.mutableProperty0(p);
}
public static KProperty1 property1(PropertyReference1 p) {
return factory.property1(p);
}
public static KMutableProperty1 mutableProperty1(MutablePropertyReference1 p) {
return factory.mutableProperty1(p);
}
public static KProperty2 property2(PropertyReference2 p) {
return factory.property2(p);
}
public static KMutableProperty2 mutableProperty2(MutablePropertyReference2 p) {
return factory.mutableProperty2(p);
}
}
@@ -0,0 +1,82 @@
/*
* 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.jvm.internal;
import kotlin.SinceKotlin;
import kotlin.reflect.*;
public class ReflectionFactory {
private static final String KOTLIN_JVM_FUNCTIONS = "kotlin.jvm.functions.";
public KClass createKotlinClass(Class javaClass) {
return new ClassReference(javaClass);
}
public KClass createKotlinClass(Class javaClass, String internalName) {
return new ClassReference(javaClass);
}
public KDeclarationContainer getOrCreateKotlinPackage(Class javaClass, String moduleName) {
return new PackageReference(javaClass, moduleName);
}
public KClass getOrCreateKotlinClass(Class javaClass) {
return new ClassReference(javaClass);
}
public KClass getOrCreateKotlinClass(Class javaClass, String internalName) {
return new ClassReference(javaClass);
}
@SinceKotlin(version = "1.1")
public String renderLambdaToString(Lambda lambda) {
String result = lambda.getClass().getGenericInterfaces()[0].toString();
return result.startsWith(KOTLIN_JVM_FUNCTIONS) ? result.substring(KOTLIN_JVM_FUNCTIONS.length()) : result;
}
// Functions
public KFunction function(FunctionReference f) {
return f;
}
// Properties
public KProperty0 property0(PropertyReference0 p) {
return p;
}
public KMutableProperty0 mutableProperty0(MutablePropertyReference0 p) {
return p;
}
public KProperty1 property1(PropertyReference1 p) {
return p;
}
public KMutableProperty1 mutableProperty1(MutablePropertyReference1 p) {
return p;
}
public KProperty2 property2(PropertyReference2 p) {
return p;
}
public KMutableProperty2 mutableProperty2(MutablePropertyReference2 p) {
return p;
}
}
@@ -0,0 +1,73 @@
/*
* 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.jvm.internal;
import java.lang.Object;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class SpreadBuilder {
private final ArrayList<Object> list;
public SpreadBuilder(int size) {
list = new ArrayList<Object>(size);
}
public void addSpread(Object container) {
if (container == null) return;
if (container instanceof Object[]) {
Object[] array = (Object[]) container;
if (array.length > 0) {
list.ensureCapacity(list.size() + array.length);
for (Object element : array) {
list.add(element);
}
}
}
else if (container instanceof Collection) {
list.addAll((Collection) container);
}
else if (container instanceof Iterable) {
for (Object element : (Iterable) container) {
list.add(element);
}
}
else if (container instanceof Iterator) {
for (Iterator iterator = (Iterator) container; iterator.hasNext(); ) {
list.add(iterator.next());
}
}
else {
throw new UnsupportedOperationException("Don't know how to spread " + container.getClass());
}
}
public int size() {
return list.size();
}
public void add(Object element) {
list.add(element);
}
public Object[] toArray(Object[] a) {
return list.toArray(a);
}
}
@@ -0,0 +1,364 @@
/*
* 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.jvm.internal;
import kotlin.Function;
import kotlin.jvm.functions.*;
import kotlin.jvm.internal.markers.*;
import java.util.*;
@SuppressWarnings({"unused", "WeakerAccess"})
public class TypeIntrinsics {
private static <T extends Throwable> T sanitizeStackTrace(T throwable) {
return Intrinsics.sanitizeStackTrace(throwable, TypeIntrinsics.class.getName());
}
public static void throwCce(Object argument, String requestedClassName) {
String argumentClassName = argument == null ? "null" : argument.getClass().getName();
throwCce(argumentClassName + " cannot be cast to " + requestedClassName);
}
public static void throwCce(String message) {
throw throwCce(new ClassCastException(message));
}
public static ClassCastException throwCce(ClassCastException e) {
throw sanitizeStackTrace(e);
}
public static boolean isMutableIterator(Object obj) {
return obj instanceof Iterator &&
(!(obj instanceof KMappedMarker) || obj instanceof KMutableIterator);
}
public static Iterator asMutableIterator(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableIterator)) {
throwCce(obj, "kotlin.collections.MutableIterator");
}
return castToIterator(obj);
}
public static Iterator asMutableIterator(Object obj, String message) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableIterator)) {
throwCce(message);
}
return castToIterator(obj);
}
public static Iterator castToIterator(Object obj) {
try {
return (Iterator) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
}
public static boolean isMutableListIterator(Object obj) {
return obj instanceof ListIterator &&
(!(obj instanceof KMappedMarker) || obj instanceof KMutableListIterator);
}
public static ListIterator asMutableListIterator(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableListIterator)) {
throwCce(obj, "kotlin.collections.MutableListIterator");
}
return castToListIterator(obj);
}
public static ListIterator asMutableListIterator(Object obj, String message) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableListIterator)) {
throwCce(message);
}
return castToListIterator(obj);
}
public static ListIterator castToListIterator(Object obj) {
try {
return (ListIterator) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
}
public static boolean isMutableIterable(Object obj) {
return obj instanceof Iterable &&
(!(obj instanceof KMappedMarker) || obj instanceof KMutableIterable);
}
public static Iterable asMutableIterable(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableIterable)) {
throwCce(obj, "kotlin.collections.MutableIterable");
}
return castToIterable(obj);
}
public static Iterable asMutableIterable(Object obj, String message) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableIterable)) {
throwCce(message);
}
return castToIterable(obj);
}
public static Iterable castToIterable(Object obj) {
try {
return (Iterable) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
}
public static boolean isMutableCollection(Object obj) {
return obj instanceof Collection &&
(!(obj instanceof KMappedMarker) || obj instanceof KMutableCollection);
}
public static Collection asMutableCollection(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableCollection)) {
throwCce(obj, "kotlin.collections.MutableCollection");
}
return castToCollection(obj);
}
public static Collection asMutableCollection(Object obj, String message) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableCollection)) {
throwCce(message);
}
return castToCollection(obj);
}
public static Collection castToCollection(Object obj) {
try {
return (Collection) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
}
public static boolean isMutableList(Object obj) {
return obj instanceof List &&
(!(obj instanceof KMappedMarker) || obj instanceof KMutableList);
}
public static List asMutableList(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableList)) {
throwCce(obj, "kotlin.collections.MutableList");
}
return castToList(obj);
}
public static List asMutableList(Object obj, String message) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableList)) {
throwCce(message);
}
return castToList(obj);
}
public static List castToList(Object obj) {
try {
return (List) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
}
public static boolean isMutableSet(Object obj) {
return obj instanceof Set &&
(!(obj instanceof KMappedMarker) || obj instanceof KMutableSet);
}
public static Set asMutableSet(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableSet)) {
throwCce(obj, "kotlin.collections.MutableSet");
}
return castToSet(obj);
}
public static Set asMutableSet(Object obj, String message) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableSet)) {
throwCce(message);
}
return castToSet(obj);
}
public static Set castToSet(Object obj) {
try {
return (Set) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
}
public static boolean isMutableMap(Object obj) {
return obj instanceof Map &&
(!(obj instanceof KMappedMarker) || obj instanceof KMutableMap);
}
public static Map asMutableMap(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableMap)) {
throwCce(obj, "kotlin.collections.MutableMap");
}
return castToMap(obj);
}
public static Map asMutableMap(Object obj, String message) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableMap)) {
throwCce(message);
}
return castToMap(obj);
}
public static Map castToMap(Object obj) {
try {
return (Map) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
}
public static boolean isMutableMapEntry(Object obj) {
return obj instanceof Map.Entry &&
(!(obj instanceof KMappedMarker) || obj instanceof KMutableMap.Entry);
}
public static Map.Entry asMutableMapEntry(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableMap.Entry)) {
throwCce(obj, "kotlin.collections.MutableMap.MutableEntry");
}
return castToMapEntry(obj);
}
public static Map.Entry asMutableMapEntry(Object obj, String message) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableMap.Entry)) {
throwCce(message);
}
return castToMapEntry(obj);
}
public static Map.Entry castToMapEntry(Object obj) {
try {
return (Map.Entry) obj;
}
catch (ClassCastException e) {
throw throwCce(e);
}
}
public static int getFunctionArity(Object obj) {
if (obj instanceof FunctionBase) {
return ((FunctionBase) obj).getArity();
}
else if (obj instanceof Function0) {
return 0;
}
else if (obj instanceof Function1) {
return 1;
}
else if (obj instanceof Function2) {
return 2;
}
else if (obj instanceof Function3) {
return 3;
}
else if (obj instanceof Function4) {
return 4;
}
else if (obj instanceof Function5) {
return 5;
}
else if (obj instanceof Function6) {
return 6;
}
else if (obj instanceof Function7) {
return 7;
}
else if (obj instanceof Function8) {
return 8;
}
else if (obj instanceof Function9) {
return 9;
}
else if (obj instanceof Function10) {
return 10;
}
else if (obj instanceof Function11) {
return 11;
}
else if (obj instanceof Function12) {
return 12;
}
else if (obj instanceof Function13) {
return 13;
}
else if (obj instanceof Function14) {
return 14;
}
else if (obj instanceof Function15) {
return 15;
}
else if (obj instanceof Function16) {
return 16;
}
else if (obj instanceof Function17) {
return 17;
}
else if (obj instanceof Function18) {
return 18;
}
else if (obj instanceof Function19) {
return 19;
}
else if (obj instanceof Function20) {
return 20;
}
else if (obj instanceof Function21) {
return 21;
}
else if (obj instanceof Function22) {
return 22;
}
else {
return -1;
}
}
public static boolean isFunctionOfArity(Object obj, int arity) {
return obj instanceof Function && getFunctionArity(obj) == arity;
}
public static Object beforeCheckcastToFunctionOfArity(Object obj, int arity) {
// TODO should we instead inline bytecode for this in TypeIntrinsics.kt?
if (obj != null && !isFunctionOfArity(obj, arity)) {
throwCce(obj, "kotlin.jvm.functions.Function" + arity);
}
return obj;
}
public static Object beforeCheckcastToFunctionOfArity(Object obj, int arity, String message) {
if (obj != null && !isFunctionOfArity(obj, arity)) {
throwCce(message);
}
return obj;
}
}
@@ -0,0 +1,40 @@
/*
* 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.jvm.internal
import kotlin.reflect.KDeclarationContainer
private fun notSupportedError(): Nothing {
throw kotlin.UnsupportedOperationException("Not supported for local property reference.")
}
@SinceKotlin("1.1")
open class LocalVariableReference : PropertyReference0() {
override fun getOwner(): KDeclarationContainer = notSupportedError()
override fun get(): Any? = notSupportedError()
}
@SinceKotlin("1.1")
open class MutableLocalVariableReference : MutablePropertyReference0() {
override fun getOwner(): KDeclarationContainer = notSupportedError()
override fun get(): Any? = notSupportedError()
override fun set(value: Any?): Unit = notSupportedError()
}
@@ -0,0 +1,24 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. 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.jvm.internal.markers
interface KMappedMarker
interface KMutableIterable : KMappedMarker
interface KMutableCollection : KMutableIterable
interface KMutableList : KMutableCollection
interface KMutableIterator : KMappedMarker
interface KMutableListIterator : KMutableIterator
interface KMutableMap : KMappedMarker {
interface Entry : KMappedMarker
}
interface KMutableSet : KMutableCollection
@@ -0,0 +1,20 @@
/*
* 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.text
@SinceKotlin("1.1") public typealias Appendable = java.lang.Appendable
@SinceKotlin("1.1") public typealias StringBuilder = java.lang.StringBuilder
@@ -228,12 +228,12 @@ internal fun <T> List<T>.optimizeReadOnlyList() = when (size) {
@JvmVersion
@kotlin.internal.InlineOnly
internal inline fun copyToArrayImpl(collection: Collection<*>): Array<Any?> =
kotlin.jvm.internal.CollectionToArray.toArray(collection)
kotlin.jvm.internal.collectionToArray(collection)
@JvmVersion
@kotlin.internal.InlineOnly
internal inline fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<T>): Array<T> =
kotlin.jvm.internal.CollectionToArray.toArray(collection, array)
kotlin.jvm.internal.collectionToArray(collection, array as Array<Any?>) as Array<T>
// copies typed varargs array to array of objects
@JvmVersion