Remove compiler support for kotlin-annotations-android
#KT-44815
This commit is contained in:
@@ -20,11 +20,9 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue
|
import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeUniqueAsSequence
|
import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeUniqueAsSequence
|
||||||
import org.jetbrains.kotlin.utils.DFS
|
|
||||||
import org.jetbrains.kotlin.utils.mapToIndex
|
import org.jetbrains.kotlin.utils.mapToIndex
|
||||||
|
|
||||||
class ArgumentAndDeclIndex(val arg: ResolvedValueArgument, val declIndex: Int)
|
class ArgumentAndDeclIndex(val arg: ResolvedValueArgument, val declIndex: Int)
|
||||||
@@ -70,12 +68,8 @@ abstract class ArgumentGenerator {
|
|||||||
generateExpression(declIndex, argument)
|
generateExpression(declIndex, argument)
|
||||||
}
|
}
|
||||||
is DefaultValueArgument -> {
|
is DefaultValueArgument -> {
|
||||||
if (calleeDescriptor?.defaultValueFromJava(declIndex) == true) {
|
defaultArgs.mark(declIndex)
|
||||||
generateDefaultJava(declIndex, argument)
|
generateDefault(declIndex, argument)
|
||||||
} else {
|
|
||||||
defaultArgs.mark(declIndex)
|
|
||||||
generateDefault(declIndex, argument)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
is VarargValueArgument -> {
|
is VarargValueArgument -> {
|
||||||
generateVararg(declIndex, argument)
|
generateVararg(declIndex, argument)
|
||||||
@@ -103,10 +97,6 @@ abstract class ArgumentGenerator {
|
|||||||
throw UnsupportedOperationException("Unsupported vararg value argument #$i: $argument")
|
throw UnsupportedOperationException("Unsupported vararg value argument #$i: $argument")
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun generateDefaultJava(i: Int, argument: DefaultValueArgument) {
|
|
||||||
throw UnsupportedOperationException("Unsupported default java argument #$i: $argument")
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun generateOther(i: Int, argument: ResolvedValueArgument) {
|
protected open fun generateOther(i: Int, argument: ResolvedValueArgument) {
|
||||||
throw UnsupportedOperationException("Unsupported value argument #$i: $argument")
|
throw UnsupportedOperationException("Unsupported value argument #$i: $argument")
|
||||||
}
|
}
|
||||||
@@ -116,28 +106,6 @@ abstract class ArgumentGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CallableDescriptor.defaultValueFromJava(index: Int): Boolean = DFS.ifAny(
|
|
||||||
listOf(this),
|
|
||||||
{ current -> current.original.overriddenDescriptors.map { it.original } },
|
|
||||||
{ descriptor ->
|
|
||||||
descriptor.original.overriddenDescriptors.isEmpty() &&
|
|
||||||
descriptor is JavaCallableMemberDescriptor &&
|
|
||||||
descriptor.valueParameters[index].declaresDefaultValue()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
fun shouldInvokeDefaultArgumentsStub(resolvedCall: ResolvedCall<*>): Boolean {
|
|
||||||
val descriptor = resolvedCall.resultingDescriptor
|
|
||||||
val valueArgumentsByIndex = resolvedCall.valueArgumentsByIndex ?: return false
|
|
||||||
for (index in valueArgumentsByIndex.indices) {
|
|
||||||
val resolvedValueArgument = valueArgumentsByIndex[index]
|
|
||||||
if (resolvedValueArgument is DefaultValueArgument && !descriptor.defaultValueFromJava(index)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFunctionWithDefaultArguments(functionDescriptor: FunctionDescriptor): FunctionDescriptor {
|
fun getFunctionWithDefaultArguments(functionDescriptor: FunctionDescriptor): FunctionDescriptor {
|
||||||
if (functionDescriptor.containingDeclaration !is ClassDescriptor) return functionDescriptor
|
if (functionDescriptor.containingDeclaration !is ClassDescriptor) return functionDescriptor
|
||||||
if (functionDescriptor.overriddenDescriptors.isEmpty()) return functionDescriptor
|
if (functionDescriptor.overriddenDescriptors.isEmpty()) return functionDescriptor
|
||||||
@@ -155,4 +123,4 @@ fun getFunctionWithDefaultArguments(functionDescriptor: FunctionDescriptor): Fun
|
|||||||
function.valueParameters.any { valueParameter -> valueParameter.hasDefaultValue() }
|
function.valueParameters.any { valueParameter -> valueParameter.hasDefaultValue() }
|
||||||
}
|
}
|
||||||
?: functionDescriptor
|
?: functionDescriptor
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,12 +72,6 @@ class CallBasedArgumentGenerator(
|
|||||||
callGenerator.putValueIfNeeded(getJvmKotlinType(i), lazyVararg, ValueKind.GENERAL_VARARG, i)
|
callGenerator.putValueIfNeeded(getJvmKotlinType(i), lazyVararg, ValueKind.GENERAL_VARARG, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun generateDefaultJava(i: Int, argument: DefaultValueArgument) {
|
|
||||||
val argumentValue = valueParameters[i].findJavaDefaultArgumentValue(valueParameterTypes[i], codegen.typeMapper)
|
|
||||||
|
|
||||||
callGenerator.putValueIfNeeded(getJvmKotlinType(i), argumentValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun reorderArgumentsIfNeeded(args: List<ArgumentAndDeclIndex>) {
|
override fun reorderArgumentsIfNeeded(args: List<ArgumentAndDeclIndex>) {
|
||||||
callGenerator.reorderArgumentsIfNeeded(args, valueParameterTypes)
|
callGenerator.reorderArgumentsIfNeeded(args, valueParameterTypes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,10 @@ import org.jetbrains.kotlin.resolve.constants.*;
|
|||||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluatorKt;
|
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluatorKt;
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
|
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.*;
|
import org.jetbrains.kotlin.resolve.jvm.AsmTypes;
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.JvmBindingContextSlices;
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.JvmConstantsKt;
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.RuntimeAssertionInfo;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
|
||||||
@@ -2690,7 +2693,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Callable resolveToCallable(@NotNull FunctionDescriptor fd, boolean superCall, @NotNull ResolvedCall resolvedCall) {
|
Callable resolveToCallable(@NotNull FunctionDescriptor fd, boolean superCall, @NotNull ResolvedCall<?> resolvedCall) {
|
||||||
IntrinsicMethod intrinsic = state.getIntrinsics().getIntrinsic(fd);
|
IntrinsicMethod intrinsic = state.getIntrinsics().getIntrinsic(fd);
|
||||||
if (intrinsic != null) {
|
if (intrinsic != null) {
|
||||||
return intrinsic.toCallable(fd, superCall, resolvedCall, this);
|
return intrinsic.toCallable(fd, superCall, resolvedCall, this);
|
||||||
@@ -2698,7 +2701,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
|
|
||||||
fd = SamCodegenUtil.resolveSamAdapter(fd);
|
fd = SamCodegenUtil.resolveSamAdapter(fd);
|
||||||
|
|
||||||
if (ArgumentGeneratorKt.shouldInvokeDefaultArgumentsStub(resolvedCall)) {
|
List<ResolvedValueArgument> valueArguments = resolvedCall.getValueArgumentsByIndex();
|
||||||
|
if (valueArguments != null && valueArguments.stream().anyMatch(it -> it instanceof DefaultValueArgument)) {
|
||||||
// When we invoke a function with some arguments mapped as defaults,
|
// When we invoke a function with some arguments mapped as defaults,
|
||||||
// we later reroute this call to an overridden function in a base class that processes the default arguments.
|
// we later reroute this call to an overridden function in a base class that processes the default arguments.
|
||||||
// If the base class is generic, this overridden function can have a different Kotlin signature
|
// If the base class is generic, this overridden function can have a different Kotlin signature
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
|
|
||||||
internal class ObjectSuperCallArgumentGenerator(
|
internal class ObjectSuperCallArgumentGenerator(
|
||||||
@@ -65,12 +64,6 @@ internal class ObjectSuperCallArgumentGenerator(
|
|||||||
pushDefaultValueOnStack(type, iv)
|
pushDefaultValueOnStack(type, iv)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun generateDefaultJava(i: Int, argument: DefaultValueArgument) {
|
|
||||||
val type = parameters[i].asmType
|
|
||||||
val value = superValueParameters[i].findJavaDefaultArgumentValue(type, typeMapper)
|
|
||||||
value.put(type, iv)
|
|
||||||
}
|
|
||||||
|
|
||||||
public override fun generateVararg(i: Int, argument: VarargValueArgument) {
|
public override fun generateVararg(i: Int, argument: VarargValueArgument) {
|
||||||
generateSuperCallArgument(i)
|
generateSuperCallArgument(i)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen
|
package org.jetbrains.kotlin.codegen
|
||||||
|
|
||||||
import org.jetbrains.kotlin.codegen.AsmUtil.unboxPrimitiveTypeOrNull
|
|
||||||
import org.jetbrains.kotlin.codegen.StackValue.*
|
|
||||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.load.java.Constant
|
|
||||||
import org.jetbrains.kotlin.load.java.EnumEntry
|
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.NullDefaultValue
|
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.StringDefaultValue
|
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.getDefaultValueFromAnnotation
|
|
||||||
import org.jetbrains.kotlin.load.java.lexicalCastFrom
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.utils.DFS
|
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
|
|
||||||
@@ -86,40 +75,3 @@ class FunctionCallStackValue(
|
|||||||
resultKotlinType: KotlinType?,
|
resultKotlinType: KotlinType?,
|
||||||
lambda: (v: InstructionAdapter) -> Unit
|
lambda: (v: InstructionAdapter) -> Unit
|
||||||
) : OperationStackValue(resultType, resultKotlinType, lambda)
|
) : OperationStackValue(resultType, resultKotlinType, lambda)
|
||||||
|
|
||||||
fun ValueParameterDescriptor.findJavaDefaultArgumentValue(targetType: Type, typeMapper: KotlinTypeMapper): StackValue {
|
|
||||||
val descriptorWithDefaultValue = DFS.dfs(
|
|
||||||
listOf(this.original),
|
|
||||||
{ it.original.overriddenDescriptors.map(ValueParameterDescriptor::getOriginal) },
|
|
||||||
object : DFS.AbstractNodeHandler<ValueParameterDescriptor, ValueParameterDescriptor?>() {
|
|
||||||
var result: ValueParameterDescriptor? = null
|
|
||||||
|
|
||||||
override fun beforeChildren(current: ValueParameterDescriptor?): Boolean {
|
|
||||||
if (current?.declaresDefaultValue() == true && current.getDefaultValueFromAnnotation() != null) {
|
|
||||||
result = current
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun result(): ValueParameterDescriptor? = result
|
|
||||||
}
|
|
||||||
) ?: error("Should be at least one descriptor with default value: $this")
|
|
||||||
|
|
||||||
val defaultValue = descriptorWithDefaultValue.getDefaultValueFromAnnotation()
|
|
||||||
if (defaultValue is NullDefaultValue) {
|
|
||||||
return constant(null, targetType)
|
|
||||||
}
|
|
||||||
|
|
||||||
val value = (defaultValue as StringDefaultValue).value
|
|
||||||
val castResult = type.lexicalCastFrom(value) ?: error("Should be checked in frontend")
|
|
||||||
|
|
||||||
return when (castResult) {
|
|
||||||
is EnumEntry -> enumEntry(castResult.descriptor, typeMapper)
|
|
||||||
is Constant -> {
|
|
||||||
val unboxedType = unboxPrimitiveTypeOrNull(targetType) ?: targetType
|
|
||||||
return coercion(constant(castResult.value, unboxedType), targetType, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+8
-22
@@ -18,8 +18,6 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
|||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
||||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
||||||
import org.jetbrains.kotlin.fir.declarations.synthetic.buildSyntheticProperty
|
import org.jetbrains.kotlin.fir.declarations.synthetic.buildSyntheticProperty
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression
|
|
||||||
import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
|
import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
|
||||||
import org.jetbrains.kotlin.fir.java.declarations.*
|
import org.jetbrains.kotlin.fir.java.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.render
|
import org.jetbrains.kotlin.fir.render
|
||||||
@@ -30,12 +28,9 @@ import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
|||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.jvm.FirJavaTypeRef
|
import org.jetbrains.kotlin.fir.types.jvm.FirJavaTypeRef
|
||||||
import org.jetbrains.kotlin.load.java.AnnotationQualifierApplicabilityType
|
import org.jetbrains.kotlin.load.java.AnnotationQualifierApplicabilityType
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.NullDefaultValue
|
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.StringDefaultValue
|
|
||||||
import org.jetbrains.kotlin.load.java.typeEnhancement.*
|
import org.jetbrains.kotlin.load.java.typeEnhancement.*
|
||||||
import org.jetbrains.kotlin.load.kotlin.SignatureBuildingComponents
|
import org.jetbrains.kotlin.load.kotlin.SignatureBuildingComponents
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
|
||||||
import org.jetbrains.kotlin.utils.JavaTypeEnhancementState
|
import org.jetbrains.kotlin.utils.JavaTypeEnhancementState
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -185,27 +180,26 @@ class FirSignatureEnhancement(
|
|||||||
enhanceReturnType(firMethod, overriddenMembers, memberContext, predefinedEnhancementInfo)
|
enhanceReturnType(firMethod, overriddenMembers, memberContext, predefinedEnhancementInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
val newValueParameterInfo = mutableListOf<EnhanceValueParameterResult>()
|
val enhancedValueParameterTypes = mutableListOf<FirResolvedTypeRef>()
|
||||||
|
|
||||||
for ((index, valueParameter) in firMethod.valueParameters.withIndex()) {
|
for ((index, valueParameter) in firMethod.valueParameters.withIndex()) {
|
||||||
if (hasReceiver && index == 0) continue
|
if (hasReceiver && index == 0) continue
|
||||||
newValueParameterInfo += enhanceValueParameter(
|
enhancedValueParameterTypes += enhanceValueParameterType(
|
||||||
firMethod, overriddenMembers, hasReceiver,
|
firMethod, overriddenMembers, hasReceiver,
|
||||||
memberContext, predefinedEnhancementInfo, valueParameter as FirJavaValueParameter,
|
memberContext, predefinedEnhancementInfo, valueParameter as FirJavaValueParameter,
|
||||||
if (hasReceiver) index - 1 else index
|
if (hasReceiver) index - 1 else index
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val newValueParameters = firMethod.valueParameters.zip(newValueParameterInfo) { valueParameter, newInfo ->
|
val newValueParameters = firMethod.valueParameters.zip(enhancedValueParameterTypes) { valueParameter, enhancedReturnType ->
|
||||||
val (newTypeRef, newDefaultValue) = newInfo
|
|
||||||
buildValueParameter {
|
buildValueParameter {
|
||||||
source = valueParameter.source
|
source = valueParameter.source
|
||||||
session = this@FirSignatureEnhancement.session
|
session = this@FirSignatureEnhancement.session
|
||||||
origin = FirDeclarationOrigin.Enhancement
|
origin = FirDeclarationOrigin.Enhancement
|
||||||
returnTypeRef = newTypeRef
|
returnTypeRef = enhancedReturnType
|
||||||
this.name = valueParameter.name
|
this.name = valueParameter.name
|
||||||
symbol = FirVariableSymbol(this.name)
|
symbol = FirVariableSymbol(this.name)
|
||||||
defaultValue = valueParameter.defaultValue ?: newDefaultValue
|
defaultValue = valueParameter.defaultValue
|
||||||
isCrossinline = valueParameter.isCrossinline
|
isCrossinline = valueParameter.isCrossinline
|
||||||
isNoinline = valueParameter.isNoinline
|
isNoinline = valueParameter.isNoinline
|
||||||
isVararg = valueParameter.isVararg
|
isVararg = valueParameter.isVararg
|
||||||
@@ -298,9 +292,7 @@ class FirSignatureEnhancement(
|
|||||||
return signatureParts.type
|
return signatureParts.type
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class EnhanceValueParameterResult(val typeRef: FirResolvedTypeRef, val defaultValue: FirExpression?)
|
private fun enhanceValueParameterType(
|
||||||
|
|
||||||
private fun enhanceValueParameter(
|
|
||||||
ownerFunction: FirFunction<*>,
|
ownerFunction: FirFunction<*>,
|
||||||
overriddenMembers: List<FirCallableMemberDeclaration<*>>,
|
overriddenMembers: List<FirCallableMemberDeclaration<*>>,
|
||||||
hasReceiver: Boolean,
|
hasReceiver: Boolean,
|
||||||
@@ -308,7 +300,7 @@ class FirSignatureEnhancement(
|
|||||||
predefinedEnhancementInfo: PredefinedFunctionEnhancementInfo?,
|
predefinedEnhancementInfo: PredefinedFunctionEnhancementInfo?,
|
||||||
ownerParameter: FirJavaValueParameter,
|
ownerParameter: FirJavaValueParameter,
|
||||||
index: Int
|
index: Int
|
||||||
): EnhanceValueParameterResult {
|
): FirResolvedTypeRef {
|
||||||
val signatureParts = ownerFunction.partsForValueParameter(
|
val signatureParts = ownerFunction.partsForValueParameter(
|
||||||
typeQualifierResolver,
|
typeQualifierResolver,
|
||||||
overriddenMembers,
|
overriddenMembers,
|
||||||
@@ -321,13 +313,7 @@ class FirSignatureEnhancement(
|
|||||||
predefinedEnhancementInfo?.parametersInfo?.getOrNull(index),
|
predefinedEnhancementInfo?.parametersInfo?.getOrNull(index),
|
||||||
forAnnotationMember = owner.classKind == ClassKind.ANNOTATION_CLASS
|
forAnnotationMember = owner.classKind == ClassKind.ANNOTATION_CLASS
|
||||||
)
|
)
|
||||||
val firResolvedTypeRef = signatureParts.type
|
return signatureParts.type
|
||||||
val defaultValueExpression = when (val defaultValue = ownerParameter.getDefaultValueFromAnnotation()) {
|
|
||||||
NullDefaultValue -> buildConstExpression(null, ConstantValueKind.Null, null)
|
|
||||||
is StringDefaultValue -> firResolvedTypeRef.type.lexicalCastFrom(session, defaultValue.value)
|
|
||||||
null -> null
|
|
||||||
}
|
|
||||||
return EnhanceValueParameterResult(firResolvedTypeRef, defaultValueExpression)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun enhanceReturnType(
|
private fun enhanceReturnType(
|
||||||
|
|||||||
@@ -13,11 +13,6 @@ import org.jetbrains.kotlin.fir.declarations.*
|
|||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression
|
import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildQualifiedAccessExpression
|
import org.jetbrains.kotlin.fir.expressions.builder.buildQualifiedAccessExpression
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
|
||||||
import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass
|
import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass
|
||||||
import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
|
import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
|
||||||
import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
|
||||||
@@ -31,11 +26,6 @@ import org.jetbrains.kotlin.fir.types.*
|
|||||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.jvm.FirJavaTypeRef
|
import org.jetbrains.kotlin.fir.types.jvm.FirJavaTypeRef
|
||||||
import org.jetbrains.kotlin.load.java.JavaDefaultQualifiers
|
import org.jetbrains.kotlin.load.java.JavaDefaultQualifiers
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.DEFAULT_NULL_FQ_NAME
|
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.DEFAULT_VALUE_FQ_NAME
|
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.AnnotationDefaultValue
|
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.NullDefaultValue
|
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.StringDefaultValue
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
|
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaType
|
import org.jetbrains.kotlin.load.java.structure.JavaType
|
||||||
import org.jetbrains.kotlin.load.java.typeEnhancement.*
|
import org.jetbrains.kotlin.load.java.typeEnhancement.*
|
||||||
@@ -45,7 +35,6 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.types.AbstractStrictEqualityTypeChecker
|
import org.jetbrains.kotlin.types.AbstractStrictEqualityTypeChecker
|
||||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||||
import org.jetbrains.kotlin.types.RawType
|
import org.jetbrains.kotlin.types.RawType
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|
||||||
import org.jetbrains.kotlin.utils.extractRadix
|
import org.jetbrains.kotlin.utils.extractRadix
|
||||||
|
|
||||||
internal class IndexedJavaTypeQualifiers(private val data: Array<JavaTypeQualifiers>) {
|
internal class IndexedJavaTypeQualifiers(private val data: Array<JavaTypeQualifiers>) {
|
||||||
@@ -317,22 +306,6 @@ internal fun ConeKotlinType.lexicalCastFrom(session: FirSession, value: String):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun FirValueParameter.getDefaultValueFromAnnotation(): AnnotationDefaultValue? {
|
|
||||||
annotations.find { it.classId == DEFAULT_VALUE_ID }
|
|
||||||
?.arguments?.firstOrNull()
|
|
||||||
?.safeAs<FirConstExpression<*>>()?.value?.safeAs<String>()
|
|
||||||
?.let { return StringDefaultValue(it) }
|
|
||||||
|
|
||||||
if (annotations.any { it.classId == DEFAULT_NULL_ID }) {
|
|
||||||
return NullDefaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
private val DEFAULT_VALUE_ID = ClassId.topLevel(DEFAULT_VALUE_FQ_NAME)
|
|
||||||
private val DEFAULT_NULL_ID = ClassId.topLevel(DEFAULT_NULL_FQ_NAME)
|
|
||||||
|
|
||||||
internal fun List<FirAnnotationCall>.computeTypeAttributesForJavaType(): ConeAttributes =
|
internal fun List<FirAnnotationCall>.computeTypeAttributesForJavaType(): ConeAttributes =
|
||||||
computeTypeAttributes { classId ->
|
computeTypeAttributes { classId ->
|
||||||
when (classId) {
|
when (classId) {
|
||||||
|
|||||||
+5
-16
@@ -22,12 +22,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor;
|
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor;
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.UtilKt;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod;
|
import org.jetbrains.kotlin.load.java.structure.JavaMethod;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
@@ -68,12 +66,10 @@ public class SignaturesPropagationData {
|
|||||||
JavaMethodDescriptor autoMethodDescriptor =
|
JavaMethodDescriptor autoMethodDescriptor =
|
||||||
createAutoMethodDescriptor(containingClass, method, autoReturnType, autoValueParameters, autoTypeParameters);
|
createAutoMethodDescriptor(containingClass, method, autoReturnType, autoValueParameters, autoTypeParameters);
|
||||||
|
|
||||||
boolean hasStableParameterNames = autoValueParameters.stream().allMatch(it -> UtilKt.getParameterNameAnnotation(it) != null);
|
|
||||||
|
|
||||||
superFunctions = getSuperFunctionsForMethod(method, autoMethodDescriptor, containingClass);
|
superFunctions = getSuperFunctionsForMethod(method, autoMethodDescriptor, containingClass);
|
||||||
modifiedValueParameters = superFunctions.isEmpty()
|
modifiedValueParameters = superFunctions.isEmpty()
|
||||||
? new ValueParameters(null, autoValueParameters, hasStableParameterNames)
|
? new ValueParameters(null, autoValueParameters, false)
|
||||||
: modifyValueParametersAccordingToSuperMethods(autoValueParameters, hasStableParameterNames);
|
: modifyValueParametersAccordingToSuperMethods(autoValueParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -123,10 +119,7 @@ public class SignaturesPropagationData {
|
|||||||
signatureErrors.add(error);
|
signatureErrors.add(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueParameters modifyValueParametersAccordingToSuperMethods(
|
private ValueParameters modifyValueParametersAccordingToSuperMethods(@NotNull List<ValueParameterDescriptor> parameters) {
|
||||||
@NotNull List<ValueParameterDescriptor> parameters,
|
|
||||||
boolean annotatedWithParameterName
|
|
||||||
) {
|
|
||||||
KotlinType resultReceiverType = null;
|
KotlinType resultReceiverType = null;
|
||||||
List<ValueParameterDescriptor> resultParameters = new ArrayList<>(parameters.size());
|
List<ValueParameterDescriptor> resultParameters = new ArrayList<>(parameters.size());
|
||||||
|
|
||||||
@@ -167,15 +160,12 @@ public class SignaturesPropagationData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnotationDescriptor currentName = UtilKt.getParameterNameAnnotation(originalParam);
|
|
||||||
boolean shouldTakeOldName = currentName == null && stableName != null;
|
|
||||||
|
|
||||||
resultParameters.add(new ValueParameterDescriptorImpl(
|
resultParameters.add(new ValueParameterDescriptorImpl(
|
||||||
originalParam.getContainingDeclaration(),
|
originalParam.getContainingDeclaration(),
|
||||||
null,
|
null,
|
||||||
shouldBeExtension ? originalIndex - 1 : originalIndex,
|
shouldBeExtension ? originalIndex - 1 : originalIndex,
|
||||||
originalParam.getAnnotations(),
|
originalParam.getAnnotations(),
|
||||||
shouldTakeOldName ? stableName : originalParam.getName(),
|
stableName != null ? stableName : originalParam.getName(),
|
||||||
altType,
|
altType,
|
||||||
originalParam.declaresDefaultValue(),
|
originalParam.declaresDefaultValue(),
|
||||||
originalParam.isCrossinline(),
|
originalParam.isCrossinline(),
|
||||||
@@ -186,8 +176,7 @@ public class SignaturesPropagationData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasStableParameterNames =
|
boolean hasStableParameterNames = CollectionsKt.any(superFunctions, CallableDescriptor::hasStableParameterNames);
|
||||||
annotatedWithParameterName || CollectionsKt.any(superFunctions, CallableDescriptor::hasStableParameterNames);
|
|
||||||
|
|
||||||
return new ValueParameters(resultReceiverType, resultParameters, hasStableParameterNames);
|
return new ValueParameters(resultReceiverType, resultParameters, hasStableParameterNames);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,10 +72,6 @@ public final class JvmAnnotationNames {
|
|||||||
public static final FqName ENHANCED_NULLABILITY_ANNOTATION = new FqName("kotlin.jvm.internal.EnhancedNullability");
|
public static final FqName ENHANCED_NULLABILITY_ANNOTATION = new FqName("kotlin.jvm.internal.EnhancedNullability");
|
||||||
public static final FqName ENHANCED_MUTABILITY_ANNOTATION = new FqName("kotlin.jvm.internal.EnhancedMutability");
|
public static final FqName ENHANCED_MUTABILITY_ANNOTATION = new FqName("kotlin.jvm.internal.EnhancedMutability");
|
||||||
|
|
||||||
public static final FqName PARAMETER_NAME_FQ_NAME = new FqName("kotlin.annotations.jvm.internal.ParameterName");
|
|
||||||
public static final FqName DEFAULT_VALUE_FQ_NAME = new FqName("kotlin.annotations.jvm.internal.DefaultValue");
|
|
||||||
public static final FqName DEFAULT_NULL_FQ_NAME = new FqName("kotlin.annotations.jvm.internal.DefaultNull");
|
|
||||||
|
|
||||||
private JvmAnnotationNames() {
|
private JvmAnnotationNames() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.descriptors
|
|
||||||
|
|
||||||
sealed class AnnotationDefaultValue
|
|
||||||
|
|
||||||
class StringDefaultValue(val value: String) : AnnotationDefaultValue()
|
|
||||||
|
|
||||||
object NullDefaultValue : AnnotationDefaultValue()
|
|
||||||
@@ -19,19 +19,14 @@ package org.jetbrains.kotlin.load.java.descriptors
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaStaticClassScope
|
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaStaticClassScope
|
||||||
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
|
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
|
||||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.firstArgument
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|
||||||
|
|
||||||
class ValueParameterData(val type: KotlinType, val hasDefaultValue: Boolean)
|
class ValueParameterData(val type: KotlinType, val hasDefaultValue: Boolean)
|
||||||
|
|
||||||
@@ -72,25 +67,3 @@ fun DescriptorWithContainerSource.getImplClassNameForDeserialized(): JvmClassNam
|
|||||||
|
|
||||||
fun DescriptorWithContainerSource.isFromJvmPackagePart(): Boolean =
|
fun DescriptorWithContainerSource.isFromJvmPackagePart(): Boolean =
|
||||||
containerSource is JvmPackagePartSource
|
containerSource is JvmPackagePartSource
|
||||||
|
|
||||||
fun ValueParameterDescriptor.getParameterNameAnnotation(): AnnotationDescriptor? {
|
|
||||||
val annotation = annotations.findAnnotation(JvmAnnotationNames.PARAMETER_NAME_FQ_NAME) ?: return null
|
|
||||||
if (annotation.firstArgument()?.safeAs<StringValue>()?.value?.isEmpty() != false) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return annotation
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ValueParameterDescriptor.getDefaultValueFromAnnotation(): AnnotationDefaultValue? {
|
|
||||||
annotations.findAnnotation(JvmAnnotationNames.DEFAULT_VALUE_FQ_NAME)
|
|
||||||
?.firstArgument()
|
|
||||||
?.safeAs<StringValue>()?.value
|
|
||||||
?.let { return StringDefaultValue(it) }
|
|
||||||
|
|
||||||
if (annotations.hasAnnotation(JvmAnnotationNames.DEFAULT_NULL_FQ_NAME)) {
|
|
||||||
return NullDefaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|||||||
-12
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
|
||||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
||||||
@@ -39,8 +38,6 @@ import org.jetbrains.kotlin.load.java.toDescriptorVisibility
|
|||||||
import org.jetbrains.kotlin.load.kotlin.computeJvmDescriptor
|
import org.jetbrains.kotlin.load.kotlin.computeJvmDescriptor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.*
|
import org.jetbrains.kotlin.resolve.*
|
||||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.firstArgument
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude.NonExtensions
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude.NonExtensions
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
@@ -53,7 +50,6 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
abstract class LazyJavaScope(
|
abstract class LazyJavaScope(
|
||||||
@@ -212,15 +208,9 @@ abstract class LazyJavaScope(
|
|||||||
jValueParameters: List<JavaValueParameter>
|
jValueParameters: List<JavaValueParameter>
|
||||||
): ResolvedValueParameters {
|
): ResolvedValueParameters {
|
||||||
var synthesizedNames = false
|
var synthesizedNames = false
|
||||||
val usedNames = mutableSetOf<String>()
|
|
||||||
|
|
||||||
val descriptors = jValueParameters.withIndex().map { (index, javaParameter) ->
|
val descriptors = jValueParameters.withIndex().map { (index, javaParameter) ->
|
||||||
val annotations = c.resolveAnnotations(javaParameter)
|
val annotations = c.resolveAnnotations(javaParameter)
|
||||||
val typeUsage = TypeUsage.COMMON.toAttributes()
|
val typeUsage = TypeUsage.COMMON.toAttributes()
|
||||||
val parameterName = annotations
|
|
||||||
.findAnnotation(JvmAnnotationNames.PARAMETER_NAME_FQ_NAME)
|
|
||||||
?.firstArgument()
|
|
||||||
?.safeAs<StringValue>()?.value
|
|
||||||
|
|
||||||
val (outType, varargElementType) =
|
val (outType, varargElementType) =
|
||||||
if (javaParameter.isVararg) {
|
if (javaParameter.isVararg) {
|
||||||
@@ -241,8 +231,6 @@ abstract class LazyJavaScope(
|
|||||||
// "other" in Any)
|
// "other" in Any)
|
||||||
// TODO: fix Java parameter name loading logic somehow (don't always load "p0", "p1", etc.)
|
// TODO: fix Java parameter name loading logic somehow (don't always load "p0", "p1", etc.)
|
||||||
Name.identifier("other")
|
Name.identifier("other")
|
||||||
} else if (parameterName != null && parameterName.isNotEmpty() && usedNames.add(parameterName)) {
|
|
||||||
Name.identifier(parameterName)
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: parameter names may be drawn from attached sources, which is slow; it's better to make them lazy
|
// TODO: parameter names may be drawn from attached sources, which is slow; it's better to make them lazy
|
||||||
val javaName = javaParameter.name
|
val javaName = javaParameter.name
|
||||||
|
|||||||
+2
-22
@@ -195,14 +195,8 @@ class SignatureEnhancement(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val valueParameterEnhancements = annotationOwnerForMember.valueParameters.map { p ->
|
val valueParameterEnhancements = annotationOwnerForMember.valueParameters.map { p ->
|
||||||
val enhancementResult = partsForValueParameter(p, memberContext) { it.valueParameters[p.index].type }
|
partsForValueParameter(p, memberContext) { it.valueParameters[p.index].type }
|
||||||
.enhance(predefinedEnhancementInfo?.parametersInfo?.getOrNull(p.index))
|
.enhance(predefinedEnhancementInfo?.parametersInfo?.getOrNull(p.index))
|
||||||
|
|
||||||
val actualType = if (enhancementResult.wereChanges) enhancementResult.type else p.type
|
|
||||||
val hasDefaultValue = p.hasDefaultValueInAnnotation(actualType)
|
|
||||||
val wereChanges = enhancementResult.wereChanges || (hasDefaultValue != p.declaresDefaultValue())
|
|
||||||
|
|
||||||
ValueParameterEnhancementResult(enhancementResult.type, hasDefaultValue, wereChanges, enhancementResult.containsFunctionN)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val returnTypeEnhancement =
|
val returnTypeEnhancement =
|
||||||
@@ -231,7 +225,7 @@ class SignatureEnhancement(
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return this.enhance(
|
return this.enhance(
|
||||||
receiverTypeEnhancement?.type,
|
receiverTypeEnhancement?.type,
|
||||||
valueParameterEnhancements.map { ValueParameterData(it.type, it.hasDefaultValue) },
|
valueParameterEnhancements.map { ValueParameterData(it.type, false) },
|
||||||
returnTypeEnhancement.type,
|
returnTypeEnhancement.type,
|
||||||
additionalUserData
|
additionalUserData
|
||||||
) as D
|
) as D
|
||||||
@@ -263,13 +257,6 @@ class SignatureEnhancement(
|
|||||||
fun enhanceSuperType(type: KotlinType, context: LazyJavaResolverContext) =
|
fun enhanceSuperType(type: KotlinType, context: LazyJavaResolverContext) =
|
||||||
SignatureParts(null, type, emptyList(), false, context, AnnotationQualifierApplicabilityType.TYPE_USE).enhance().type
|
SignatureParts(null, type, emptyList(), false, context, AnnotationQualifierApplicabilityType.TYPE_USE).enhance().type
|
||||||
|
|
||||||
private fun ValueParameterDescriptor.hasDefaultValueInAnnotation(type: KotlinType) =
|
|
||||||
when (val defaultValue = getDefaultValueFromAnnotation()) {
|
|
||||||
is StringDefaultValue -> type.lexicalCastFrom(defaultValue.value) != null
|
|
||||||
NullDefaultValue -> TypeUtils.acceptsNullable(type)
|
|
||||||
null -> declaresDefaultValue()
|
|
||||||
} && overriddenDescriptors.isEmpty()
|
|
||||||
|
|
||||||
private inner class SignatureParts(
|
private inner class SignatureParts(
|
||||||
private val typeContainer: Annotated?,
|
private val typeContainer: Annotated?,
|
||||||
private val fromOverride: KotlinType,
|
private val fromOverride: KotlinType,
|
||||||
@@ -592,13 +579,6 @@ class SignatureEnhancement(
|
|||||||
val containsFunctionN: Boolean
|
val containsFunctionN: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
private class ValueParameterEnhancementResult(
|
|
||||||
type: KotlinType,
|
|
||||||
val hasDefaultValue: Boolean,
|
|
||||||
wereChanges: Boolean,
|
|
||||||
containsFunctionN: Boolean
|
|
||||||
) : PartEnhancementResult(type, wereChanges, containsFunctionN)
|
|
||||||
|
|
||||||
private fun CallableMemberDescriptor.partsForValueParameter(
|
private fun CallableMemberDescriptor.partsForValueParameter(
|
||||||
// TODO: investigate if it's really can be a null (check properties' with extension overrides in Java)
|
// TODO: investigate if it's really can be a null (check properties' with extension overrides in Java)
|
||||||
parameterDescriptor: ValueParameterDescriptor?,
|
parameterDescriptor: ValueParameterDescriptor?,
|
||||||
|
|||||||
@@ -16,53 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java
|
package org.jetbrains.kotlin.load.java
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|
||||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.resolve.deprecation.Deprecation
|
import org.jetbrains.kotlin.resolve.deprecation.Deprecation
|
||||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
|
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
|
||||||
import org.jetbrains.kotlin.utils.extractRadix
|
|
||||||
|
|
||||||
sealed class JavaDefaultValue
|
|
||||||
class EnumEntry(val descriptor: ClassDescriptor) : JavaDefaultValue()
|
|
||||||
class Constant(val value: Any) : JavaDefaultValue()
|
|
||||||
|
|
||||||
fun KotlinType.lexicalCastFrom(value: String): JavaDefaultValue? {
|
|
||||||
val typeDescriptor = constructor.declarationDescriptor
|
|
||||||
if (typeDescriptor is ClassDescriptor && typeDescriptor.kind == ClassKind.ENUM_CLASS) {
|
|
||||||
val descriptor = typeDescriptor.unsubstitutedInnerClassesScope.getContributedClassifier(
|
|
||||||
Name.identifier(value),
|
|
||||||
NoLookupLocation.FROM_BACKEND
|
|
||||||
)
|
|
||||||
|
|
||||||
return if (descriptor is ClassDescriptor && descriptor.kind == ClassKind.ENUM_ENTRY) EnumEntry(descriptor) else null
|
|
||||||
}
|
|
||||||
|
|
||||||
val type = this.makeNotNullable()
|
|
||||||
val (number, radix) = extractRadix(value)
|
|
||||||
val result: Any? = try {
|
|
||||||
when {
|
|
||||||
KotlinBuiltIns.isBoolean(type) -> value.toBoolean()
|
|
||||||
KotlinBuiltIns.isChar(type) -> value.singleOrNull()
|
|
||||||
KotlinBuiltIns.isByte(type) -> number.toByteOrNull(radix)
|
|
||||||
KotlinBuiltIns.isShort(type) -> number.toShortOrNull(radix)
|
|
||||||
KotlinBuiltIns.isInt(type) -> number.toIntOrNull(radix)
|
|
||||||
KotlinBuiltIns.isLong(type) -> number.toLongOrNull(radix)
|
|
||||||
KotlinBuiltIns.isFloat(type) -> value.toFloatOrNull()
|
|
||||||
KotlinBuiltIns.isDouble(type) -> value.toDoubleOrNull()
|
|
||||||
KotlinBuiltIns.isString(type) -> value
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
} catch (e: IllegalArgumentException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
return if (result != null) Constant(result) else null
|
|
||||||
}
|
|
||||||
|
|
||||||
class DeprecationCausedByFunctionN(override val target: DeclarationDescriptor) : Deprecation {
|
class DeprecationCausedByFunctionN(override val target: DeclarationDescriptor) : Deprecation {
|
||||||
override val deprecationLevel: DeprecationLevelValue
|
override val deprecationLevel: DeprecationLevelValue
|
||||||
|
|||||||
Reference in New Issue
Block a user