Move .java and .kotlin extension properties to kotlin.jvm
Delete the old ones in package kotlin.reflect.jvm because otherwise the code using those functions will become red in a lot less meaningful way (overload resolution ambiguity) than if they're deleted (unresolved import) Based on the work originally done by @dnpetrov #KT-8380 Fixed
This commit is contained in:
+2
-2
@@ -38,8 +38,8 @@ import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.HashMap
|
||||
import kotlin.reflect.jvm.java
|
||||
import java.util.*
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
public class IncrementalPackageFragmentProvider(
|
||||
sourceFiles: Collection<JetFile>,
|
||||
|
||||
-3
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm.calls.checkers
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
@@ -30,7 +28,6 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.NO_REFLECTION_IN_CLASS_PATH
|
||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import kotlin.reflect.jvm.java
|
||||
|
||||
/**
|
||||
* If there's no Kotlin reflection implementation found in the classpath, checks that there are no usages
|
||||
|
||||
Vendored
-1
@@ -1,5 +1,4 @@
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.reflect.jvm.java
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation(retention = AnnotationRetention.RUNTIME) class Ann(val x: String)
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.reflect.jvm.java
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
target(AnnotationTarget.EXPRESSION)
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.reflect.jvm.java
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation(retention = AnnotationRetention.RUNTIME) class Ann(val x: String)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.reflect.jvm.java
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
target(AnnotationTarget.EXPRESSION)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.jvm.java
|
||||
|
||||
annotation(retention = AnnotationRetention.RUNTIME) class Ann(
|
||||
val i: Int = 1,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
fun box(): String {
|
||||
val any = Array<Any>::class
|
||||
|
||||
Vendored
-1
@@ -1,5 +1,4 @@
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.jvm.java
|
||||
|
||||
class Klass
|
||||
class Other
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.reflect.jvm.jvmName
|
||||
import kotlin.reflect.jvm.kotlin
|
||||
|
||||
class Klass {
|
||||
class Nested
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.reflect.jvm.kotlin
|
||||
|
||||
class Klass {
|
||||
class Nested
|
||||
|
||||
Vendored
-2
@@ -1,5 +1,3 @@
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
import kotlin.reflect.jvm.kotlin
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// NO_KOTLIN_REFLECT
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Klass
|
||||
|
||||
fun box(): String {
|
||||
val kClass = Klass::class
|
||||
val jClass = kClass.java
|
||||
val kjClass = Klass::class.java
|
||||
val kkClass = jClass.kotlin
|
||||
val jjClass = kkClass.java
|
||||
|
||||
assertEquals("Klass", jClass.getSimpleName())
|
||||
assertEquals("Klass", kjClass.getSimpleName())
|
||||
assertEquals("Klass", kkClass.simpleName)
|
||||
assertEquals(kjClass, jjClass)
|
||||
|
||||
failsWith(Error::class.java) { kClass.simpleName!! }
|
||||
failsWith(Error::class.java) { kClass.qualifiedName!! }
|
||||
failsWith(Error::class.java) { kClass.members }
|
||||
|
||||
val jlError = Error::class.java
|
||||
val kljError = Error::class
|
||||
val jljError = kljError.java
|
||||
val jlkError = jlError.kotlin
|
||||
|
||||
assertEquals("Error", jlError.getSimpleName())
|
||||
assertEquals("Error", jljError.getSimpleName())
|
||||
assertEquals("Error", jlkError.simpleName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// NO_KOTLIN_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun check(name: String, c: Class<*>) {
|
||||
assertEquals(name, c.simpleName)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check("boolean", Boolean::class.java)
|
||||
check("byte", Byte::class.java)
|
||||
check("char", Char::class.java)
|
||||
check("short", Short::class.java)
|
||||
check("int", Int::class.java)
|
||||
check("float", Float::class.java)
|
||||
check("long", Long::class.java)
|
||||
check("double", Double::class.java)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// NO_KOTLIN_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Klass
|
||||
|
||||
inline fun <reified T> simpleName(): String =
|
||||
T::class.java.getSimpleName()
|
||||
|
||||
inline fun <reified T> simpleName2(): String {
|
||||
val kClass = T::class // Intrinsic for T::class.java is not used
|
||||
return kClass.java.getSimpleName()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Integer", simpleName<Int>())
|
||||
assertEquals("Integer", simpleName2<Int>())
|
||||
assertEquals("Klass", simpleName<Klass>())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
import kotlin.reflect.jvm.kotlin
|
||||
import kotlin.reflect.*
|
||||
|
||||
var storage = "before"
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
import kotlin.reflect.jvm.kotlin
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A(val readonly: String) {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
import kotlin.reflect.jvm.kotlin
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.kotlin
|
||||
|
||||
class A(param: String) {
|
||||
val int: Int get() = 42
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import kotlin.reflect.jvm.java
|
||||
|
||||
class Klass
|
||||
|
||||
fun foo() {
|
||||
@@ -12,5 +10,5 @@ fun foo() {
|
||||
|
||||
// 2 LDC LKlass;.class
|
||||
// 1 GETSTATIC java/lang/Integer.TYPE : Ljava/lang/Class;
|
||||
// 1 INVOKESTATIC kotlin/reflect/jvm.*\.getJava
|
||||
// 1 INVOKESTATIC kotlin/jvm.*\.getJava
|
||||
// 1 LDC Ljava/lang/Integer;.class
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ fun foo(ann: A) {
|
||||
ann.toString()
|
||||
ann.hashCode()
|
||||
|
||||
javaClass<MyClass>().getAnnotation(javaClass<A>()).<!DEPRECATED_ANNOTATION_METHOD_CALL!>value()<!>
|
||||
javaClass<MyClass>().getAnnotation(javaClass<A>()).<!DEPRECATED_ANNOTATION_METHOD_CALL!>arg()<!>
|
||||
MyClass::class.java.getAnnotation(A::class.java).<!DEPRECATED_ANNOTATION_METHOD_CALL!>value()<!>
|
||||
MyClass::class.java.getAnnotation(A::class.java).<!DEPRECATED_ANNOTATION_METHOD_CALL!>arg()<!>
|
||||
}
|
||||
|
||||
fun A.bar() {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_VARIABLE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_VARIABLE -DEPRECATED_SYMBOL_WITH_MESSAGE
|
||||
|
||||
inline fun<reified T> foo(block: () -> T): String = block().toString()
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import javax.inject.Inject
|
||||
|
||||
println(javaClass<Inject>())
|
||||
println(Inject::class.java)
|
||||
|
||||
+18
@@ -3513,6 +3513,18 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("javaClass.kt")
|
||||
public void testJavaClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/javaClass.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primitiveJavaClass.kt")
|
||||
public void testPrimitiveJavaClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/primitiveJavaClass.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyGetSetName.kt")
|
||||
public void testPropertyGetSetName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/propertyGetSetName.kt");
|
||||
@@ -3525,6 +3537,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("reifiedTypeJavaClass.kt")
|
||||
public void testReifiedTypeJavaClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/reifiedTypeJavaClass.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleClassLiterals.kt")
|
||||
public void testSimpleClassLiterals() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/noKotlinReflect/simpleClassLiterals.kt");
|
||||
|
||||
@@ -45,3 +45,14 @@ public val <T> KClass<T>.declaredExtensionProperties: Collection<KProperty2<T, *
|
||||
public var KProperty<*>.accessible: Boolean
|
||||
get() = isAccessible
|
||||
set(value) { isAccessible = value }
|
||||
|
||||
|
||||
@deprecated("Use .java instead.", ReplaceWith("java"))
|
||||
public val <T> KClass<T>.__java: Class<T>
|
||||
@jvmName("getJava")
|
||||
get() = this.java
|
||||
|
||||
@deprecated("Use .kotlin instead.", ReplaceWith("kotlin"))
|
||||
public val <T> Class<T>.__kotlin: KClass<T>
|
||||
@jvmName("getKotlin")
|
||||
get() = this.kotlin
|
||||
|
||||
@@ -17,19 +17,11 @@
|
||||
package kotlin.reflect.jvm
|
||||
|
||||
import java.lang.reflect.*
|
||||
import kotlin.jvm.internal.Intrinsic
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.internal.*
|
||||
|
||||
// Kotlin reflection -> Java reflection
|
||||
|
||||
/**
|
||||
* Returns a Java [Class] instance corresponding to the given [KClass] instance.
|
||||
*/
|
||||
@Intrinsic("kotlin.KClass.java.property")
|
||||
public val <T> KClass<T>.java: Class<T>
|
||||
get() = (this as KClassImpl<T>).jClass
|
||||
|
||||
/**
|
||||
* Returns a Java [Class] instance that represents a Kotlin package.
|
||||
* The methods and fields of this class are generated from top level functions and properties in the Kotlin package.
|
||||
@@ -90,13 +82,6 @@ public val KType.javaType: Type
|
||||
|
||||
// Java reflection -> Kotlin reflection
|
||||
|
||||
// TODO: getstatic $kotlinClass or go to foreignKClasses
|
||||
/**
|
||||
* Returns a [KClass] instance corresponding to the given Java [Class] instance.
|
||||
*/
|
||||
public val <T> Class<T>.kotlin: KClass<T>
|
||||
get() = KClassImpl(this)
|
||||
|
||||
/**
|
||||
* Returns a [KPackage] instance corresponding to the Java [Class] instance.
|
||||
* The given class is generated from top level functions and properties in the Kotlin package.
|
||||
|
||||
+2
-2
@@ -23,9 +23,9 @@ import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import java.io.File
|
||||
import java.lang.reflect.Constructor
|
||||
import java.util.HashMap
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.reflect.jvm.java
|
||||
import kotlin.reflect.jvm.*
|
||||
import java.lang.reflect.Array as RArray
|
||||
|
||||
fun parse(line: String, reader: OutputLineReader, messages: MutableList<Any>, logger: ILogger): Boolean {
|
||||
|
||||
@@ -65,7 +65,7 @@ import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import kotlin.reflect.jvm.java
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
class KotlinCodeFragmentFactory: CodeFragmentFactory() {
|
||||
private val LOG = Logger.getInstance(this.javaClass)
|
||||
@@ -338,4 +338,4 @@ class KotlinCodeFragmentFactory: CodeFragmentFactory() {
|
||||
|
||||
return getContextElement(codeFragment.findElementAt(codeFragment.text.length() - 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.jvm.internal.ClassBasedDeclarationContainer
|
||||
import kotlin.jvm.internal.Intrinsic
|
||||
import kotlin.jvm.internal.Reflection
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* Returns a Java [Class] instance corresponding to the given [KClass] instance.
|
||||
*/
|
||||
@Intrinsic("kotlin.KClass.java.property")
|
||||
public val <T> KClass<T>.java: Class<T>
|
||||
get() = (this as ClassBasedDeclarationContainer).jClass as Class<T>
|
||||
|
||||
/**
|
||||
* Returns a [KClass] instance corresponding to the given Java [Class] instance.
|
||||
*/
|
||||
public val <T> Class<T>.kotlin: KClass<T>
|
||||
get() = Reflection.createKotlinClass(this) as KClass<T>
|
||||
@@ -27,13 +27,16 @@ public annotation(retention = AnnotationRetention.SOURCE) class throws(public va
|
||||
/**
|
||||
* Returns the runtime Java class of this object.
|
||||
*/
|
||||
@Intrinsic("kotlin.javaClass.property") public val <T: Any> T.javaClass : Class<T>
|
||||
@Intrinsic("kotlin.javaClass.property")
|
||||
public val <T: Any> T.javaClass : Class<T>
|
||||
get() = (this as java.lang.Object).getClass() as Class<T>
|
||||
|
||||
/**
|
||||
* Returns the Java class for the specified type.
|
||||
*/
|
||||
@Intrinsic("kotlin.javaClass.function") public fun <reified T: Any> javaClass(): Class<T> = null as Class<T>
|
||||
@Intrinsic("kotlin.javaClass.function")
|
||||
@deprecated("Use the class reference and .java extension property instead: MyClass::class.java", ReplaceWith("T::class.java"))
|
||||
public fun <reified T: Any> javaClass(): Class<T> = T::class.java
|
||||
|
||||
/**
|
||||
* Executes the given function [block] while holding the monitor of the given object [lock].
|
||||
|
||||
Reference in New Issue
Block a user