Drop kotlin.jvm.internal.Intrinsic, use only one mechanism for intrinsics
This commit is contained in:
+15
-23
@@ -23,14 +23,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType;
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.CapitalizeDecapitalizeKt;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME;
|
||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
@@ -38,6 +35,9 @@ import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
public class IntrinsicMethods {
|
||||
public static final String INTRINSICS_CLASS_NAME = "kotlin/jvm/internal/Intrinsics";
|
||||
|
||||
private static final FqName KOTLIN_JVM = new FqName("kotlin.jvm");
|
||||
/* package */ static final FqNameUnsafe RECEIVER_PARAMETER_FQ_NAME = new FqNameUnsafe("T");
|
||||
|
||||
private static final IntrinsicMethod UNARY_MINUS = new UnaryMinus();
|
||||
private static final IntrinsicMethod UNARY_PLUS = new UnaryPlus();
|
||||
private static final IntrinsicMethod NUMBER_CAST = new NumberCast();
|
||||
@@ -57,20 +57,22 @@ public class IntrinsicMethods {
|
||||
private static final ToString TO_STRING = new ToString();
|
||||
private static final Clone CLONE = new Clone();
|
||||
|
||||
private final Map<String, IntrinsicMethod> namedMethods = new HashMap<String, IntrinsicMethod>();
|
||||
private static final IntrinsicMethod ARRAY_ITERATOR = new ArrayIterator();
|
||||
private final IntrinsicsMap intrinsicsMap = new IntrinsicsMap();
|
||||
|
||||
public IntrinsicMethods() {
|
||||
namedMethods.put("kotlin.javaClass.function", new JavaClassFunction());
|
||||
namedMethods.put("kotlin.javaClass.property", new JavaClassProperty());
|
||||
namedMethods.put("kotlin.KClass.java.property", new KClassJavaProperty());
|
||||
namedMethods.put("kotlin.jvm.internal.unsafe.monitorEnter", MonitorInstruction.MONITOR_ENTER);
|
||||
namedMethods.put("kotlin.jvm.internal.unsafe.monitorExit", MonitorInstruction.MONITOR_EXIT);
|
||||
namedMethods.put("kotlin.jvm.isArrayOf", new IsArrayOf());
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, null, "javaClass", 0, new JavaClassFunction());
|
||||
intrinsicsMap.registerIntrinsic(KOTLIN_JVM, RECEIVER_PARAMETER_FQ_NAME, "javaClass", -1, new JavaClassProperty());
|
||||
intrinsicsMap.registerIntrinsic(KOTLIN_JVM, KotlinBuiltIns.FQ_NAMES.kClass, "java", -1, new KClassJavaProperty());
|
||||
intrinsicsMap.registerIntrinsic(new FqName("kotlin.jvm.internal.unsafe"), null, "monitorEnter", 1, MonitorInstruction.MONITOR_ENTER);
|
||||
intrinsicsMap.registerIntrinsic(new FqName("kotlin.jvm.internal.unsafe"), null, "monitorExit", 1, MonitorInstruction.MONITOR_EXIT);
|
||||
intrinsicsMap.registerIntrinsic(KOTLIN_JVM, KotlinBuiltIns.FQ_NAMES.array, "isArrayOf", 0, new IsArrayOf());
|
||||
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, null, "arrayOf", 1, new JavaClassArray());
|
||||
|
||||
// TODO: drop when deprecated kotlin.javaClass property is gone
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, RECEIVER_PARAMETER_FQ_NAME, "javaClass", -1, new JavaClassProperty());
|
||||
|
||||
ImmutableList<Name> primitiveCastMethods = OperatorConventions.NUMBER_CONVERSIONS.asList();
|
||||
for (Name method : primitiveCastMethods) {
|
||||
String methodName = method.asString();
|
||||
@@ -180,16 +182,6 @@ public class IntrinsicMethods {
|
||||
|
||||
@Nullable
|
||||
public IntrinsicMethod getIntrinsic(@NotNull CallableMemberDescriptor descriptor) {
|
||||
IntrinsicMethod intrinsicMethod = intrinsicsMap.getIntrinsic(descriptor);
|
||||
if (intrinsicMethod != null) {
|
||||
return intrinsicMethod;
|
||||
}
|
||||
|
||||
String value = CompileTimeConstantUtils.getIntrinsicAnnotationArgument(descriptor);
|
||||
if (value != null) {
|
||||
return namedMethods.get(value);
|
||||
}
|
||||
|
||||
return null;
|
||||
return intrinsicsMap.getIntrinsic(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@ package org.jetbrains.kotlin.codegen.intrinsics;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
@@ -112,6 +109,10 @@ class IntrinsicsMap {
|
||||
ClassifierDescriptor classifier = receiverParameter.getType().getConstructor().getDeclarationDescriptor();
|
||||
if (classifier == null) return null;
|
||||
|
||||
if (classifier instanceof TypeParameterDescriptor) {
|
||||
return IntrinsicMethods.RECEIVER_PARAMETER_FQ_NAME;
|
||||
}
|
||||
|
||||
return DescriptorUtils.getFqName(classifier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,13 @@ import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
|
||||
public class MonitorInstruction private constructor(private val opcode: Int) : IntrinsicMethod() {
|
||||
class MonitorInstruction private constructor(private val opcode: Int) : IntrinsicMethod() {
|
||||
companion object {
|
||||
public val MONITOR_ENTER: MonitorInstruction = MonitorInstruction(Opcodes.MONITORENTER)
|
||||
public val MONITOR_EXIT: MonitorInstruction = MonitorInstruction(Opcodes.MONITOREXIT)
|
||||
@JvmField
|
||||
val MONITOR_ENTER: MonitorInstruction = MonitorInstruction(Opcodes.MONITORENTER)
|
||||
|
||||
@JvmField
|
||||
val MONITOR_EXIT: MonitorInstruction = MonitorInstruction(Opcodes.MONITOREXIT)
|
||||
}
|
||||
|
||||
override fun toCallable(method: CallableMethod): Callable {
|
||||
|
||||
@@ -22,9 +22,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtParameter;
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil;
|
||||
@@ -39,7 +36,6 @@ import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeProjection;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -107,19 +103,6 @@ public class CompileTimeConstantUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getIntrinsicAnnotationArgument(@NotNull Annotated annotatedDescriptor) {
|
||||
AnnotationDescriptor intrinsicAnnotation =
|
||||
annotatedDescriptor.getAnnotations().findAnnotation(new FqName("kotlin.jvm.internal.Intrinsic"));
|
||||
if (intrinsicAnnotation == null) return null;
|
||||
|
||||
Collection<ConstantValue<?>> values = intrinsicAnnotation.getAllValueArguments().values();
|
||||
if (values.isEmpty()) return null;
|
||||
|
||||
Object value = values.iterator().next().getValue();
|
||||
return value instanceof String ? (String) value : null;
|
||||
}
|
||||
|
||||
public static boolean isArrayMethodCall(@NotNull ResolvedCall<?> resolvedCall) {
|
||||
return ARRAY_CALL_NAMES.contains(DescriptorUtils.getFqName(resolvedCall.getCandidateDescriptor()).asString());
|
||||
}
|
||||
|
||||
@@ -13,21 +13,18 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:kotlin.jvm.JvmName("JvmClassMappingKt")
|
||||
@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
@file:JvmName("JvmClassMappingKt")
|
||||
@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "UNCHECKED_CAST")
|
||||
|
||||
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.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Intrinsic("kotlin.KClass.java.property")
|
||||
public val <T : Any> KClass<T>.java: Class<T>
|
||||
@JvmName("getJavaClass")
|
||||
get() = (this as ClassBasedDeclarationContainer).jClass as Class<T>
|
||||
@@ -35,7 +32,6 @@ public val <T : Any> KClass<T>.java: Class<T>
|
||||
/**
|
||||
* Returns a Java [Class] instance representing the primitive type corresponding to the given [KClass] if it exists.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public val <T : Any> KClass<T>.javaPrimitiveType: Class<T>?
|
||||
get() {
|
||||
val thisJClass = (this as ClassBasedDeclarationContainer).jClass
|
||||
@@ -58,7 +54,6 @@ public val <T : Any> KClass<T>.javaPrimitiveType: Class<T>?
|
||||
* Returns a Java [Class] instance corresponding to the given [KClass] instance.
|
||||
* In case of primitive types it returns corresponding wrapper classes.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST", "PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
public val <T : Any> KClass<T>.javaObjectType: Class<T>
|
||||
get() {
|
||||
val thisJClass = (this as ClassBasedDeclarationContainer).jClass
|
||||
@@ -80,7 +75,6 @@ public val <T : Any> KClass<T>.javaObjectType: Class<T>
|
||||
/**
|
||||
* Returns a [KClass] instance corresponding to the given Java [Class] instance.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public val <T : Any> Class<T>.kotlin: KClass<T>
|
||||
@JvmName("getKotlinClass")
|
||||
get() = Reflection.createKotlinClass(this) as KClass<T>
|
||||
@@ -89,8 +83,6 @@ public val <T : Any> Class<T>.kotlin: KClass<T>
|
||||
/**
|
||||
* Returns the runtime Java class of this object.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Intrinsic("kotlin.javaClass.property")
|
||||
public val <T: Any> T.javaClass : Class<T>
|
||||
get() = (this as java.lang.Object).getClass() as Class<T>
|
||||
|
||||
@@ -102,7 +94,6 @@ public val <T: Any> KClass<T>.javaClass: Class<KClass<T>>
|
||||
/**
|
||||
* Checks if array can contain element of type [T].
|
||||
*/
|
||||
@Intrinsic("kotlin.jvm.isArrayOf")
|
||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
||||
public fun <reified T : Any> Array<*>.isArrayOf(): Boolean =
|
||||
T::class.java.isAssignableFrom(this.javaClass.componentType)
|
||||
@@ -110,6 +101,5 @@ public fun <reified T : Any> Array<*>.isArrayOf(): Boolean =
|
||||
/**
|
||||
* Returns a [KClass] instance corresponding to the annotation type of this annotation.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public val <T : Annotation> T.annotationClass: KClass<out T>
|
||||
get() = (this as java.lang.annotation.Annotation).annotationType().kotlin as KClass<out T>
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
public annotation class Intrinsic(val value: String)
|
||||
@@ -16,14 +16,10 @@
|
||||
|
||||
package kotlin.jvm.internal.unsafe
|
||||
|
||||
import kotlin.jvm.internal.Intrinsic
|
||||
|
||||
/** @suppress */
|
||||
@Intrinsic("kotlin.jvm.internal.unsafe.monitorEnter")
|
||||
@Deprecated("This function supports the standard library infrastructure and is not intended to be used directly from user code.", level = DeprecationLevel.ERROR)
|
||||
public fun monitorEnter(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
|
||||
|
||||
/** @suppress */
|
||||
@Intrinsic("kotlin.jvm.internal.unsafe.monitorExit")
|
||||
@Deprecated("This function supports the standard library infrastructure and is not intended to be used directly from user code.", level = DeprecationLevel.ERROR)
|
||||
public fun monitorExit(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
package kotlin
|
||||
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.jvm.internal.Intrinsic
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
@@ -31,7 +30,6 @@ public annotation class throws(public vararg val exceptionClasses: KClass<out Th
|
||||
/**
|
||||
* Returns the runtime Java class of this object.
|
||||
*/
|
||||
@Intrinsic("kotlin.javaClass.property")
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public val <T: Any> T.javaClass : Class<T>
|
||||
get() = (this as java.lang.Object).getClass() as Class<T>
|
||||
@@ -39,7 +37,6 @@ public val <T: Any> T.javaClass : Class<T>
|
||||
/**
|
||||
* Returns the Java class for the specified type.
|
||||
*/
|
||||
@Intrinsic("kotlin.javaClass.function")
|
||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
||||
@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
|
||||
|
||||
Reference in New Issue
Block a user