Add minor changes after review
- Rename GENERIC_TYPE -> GENERIC_ARGUMENT - Make 'callableDescriptor' nullable
This commit is contained in:
@@ -323,7 +323,7 @@ public class JetTypeMapper {
|
||||
else if (descriptor instanceof FunctionDescriptor && forceBoxedReturnType((FunctionDescriptor) descriptor)) {
|
||||
// GENERIC_TYPE is a hack to automatically box the return type
|
||||
//noinspection ConstantConditions
|
||||
return mapType(descriptor.getReturnType(), sw, TypeMappingMode.GENERIC_TYPE);
|
||||
return mapType(descriptor.getReturnType(), sw, TypeMappingMode.GENERIC_ARGUMENT);
|
||||
}
|
||||
|
||||
return mapReturnType(descriptor, sw, returnType);
|
||||
@@ -357,7 +357,7 @@ public class JetTypeMapper {
|
||||
|
||||
@NotNull
|
||||
public Type mapTypeParameter(@NotNull KotlinType jetType, @Nullable BothSignatureWriter signatureVisitor) {
|
||||
return mapType(jetType, signatureVisitor, TypeMappingMode.GENERIC_TYPE);
|
||||
return mapType(jetType, signatureVisitor, TypeMappingMode.GENERIC_ARGUMENT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -1173,7 +1173,7 @@ public class JetTypeMapper {
|
||||
for (KotlinType jetType : typeParameterDescriptor.getUpperBounds()) {
|
||||
if (jetType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor) {
|
||||
if (!isJvmInterface(jetType)) {
|
||||
mapType(jetType, sw, TypeMappingMode.GENERIC_TYPE);
|
||||
mapType(jetType, sw, TypeMappingMode.GENERIC_ARGUMENT);
|
||||
break classBound;
|
||||
}
|
||||
}
|
||||
@@ -1191,13 +1191,13 @@ public class JetTypeMapper {
|
||||
if (classifier instanceof ClassDescriptor) {
|
||||
if (isJvmInterface(jetType)) {
|
||||
sw.writeInterfaceBound();
|
||||
mapType(jetType, sw, TypeMappingMode.GENERIC_TYPE);
|
||||
mapType(jetType, sw, TypeMappingMode.GENERIC_ARGUMENT);
|
||||
sw.writeInterfaceBoundEnd();
|
||||
}
|
||||
}
|
||||
else if (classifier instanceof TypeParameterDescriptor) {
|
||||
sw.writeInterfaceBound();
|
||||
mapType(jetType, sw, TypeMappingMode.GENERIC_TYPE);
|
||||
mapType(jetType, sw, TypeMappingMode.GENERIC_ARGUMENT);
|
||||
sw.writeInterfaceBoundEnd();
|
||||
}
|
||||
else {
|
||||
@@ -1209,7 +1209,7 @@ public class JetTypeMapper {
|
||||
private void writeParameter(
|
||||
@NotNull BothSignatureWriter sw,
|
||||
@NotNull KotlinType type,
|
||||
@NotNull CallableDescriptor callableDescriptor
|
||||
@Nullable CallableDescriptor callableDescriptor
|
||||
) {
|
||||
writeParameter(sw, JvmMethodParameterKind.VALUE, type, callableDescriptor);
|
||||
}
|
||||
@@ -1218,7 +1218,7 @@ public class JetTypeMapper {
|
||||
@NotNull BothSignatureWriter sw,
|
||||
@NotNull JvmMethodParameterKind kind,
|
||||
@NotNull KotlinType type,
|
||||
@NotNull CallableDescriptor callableDescriptor
|
||||
@Nullable CallableDescriptor callableDescriptor
|
||||
) {
|
||||
sw.writeParameterType(kind);
|
||||
|
||||
@@ -1230,7 +1230,7 @@ public class JetTypeMapper {
|
||||
private void writeParameterType(
|
||||
@NotNull BothSignatureWriter sw,
|
||||
@NotNull KotlinType type,
|
||||
@NotNull CallableDescriptor callableDescriptor
|
||||
@Nullable CallableDescriptor callableDescriptor
|
||||
) {
|
||||
TypeMappingMode typeMappingMode;
|
||||
|
||||
@@ -1241,7 +1241,7 @@ public class JetTypeMapper {
|
||||
typeMappingMode = typeMappingModeFromAnnotation;
|
||||
}
|
||||
else if (TypeMappingUtil.isMethodWithDeclarationSiteWildcards(callableDescriptor) && !type.getArguments().isEmpty()) {
|
||||
typeMappingMode = TypeMappingMode.GENERIC_TYPE; // Render all wildcards
|
||||
typeMappingMode = TypeMappingMode.GENERIC_ARGUMENT; // Render all wildcards
|
||||
}
|
||||
else {
|
||||
typeMappingMode = TypeMappingMode.getOptimalModeForValueParameter(type);
|
||||
@@ -1370,11 +1370,11 @@ public class JetTypeMapper {
|
||||
sw.writeParametersStart();
|
||||
|
||||
for (ScriptDescriptor importedScript : importedScripts) {
|
||||
writeParameter(sw, importedScript.getDefaultType(), script.getUnsubstitutedPrimaryConstructor());
|
||||
writeParameter(sw, importedScript.getDefaultType(), /* callableDescriptor = */ null);
|
||||
}
|
||||
|
||||
for (ValueParameterDescriptor valueParameter : script.getUnsubstitutedPrimaryConstructor().getValueParameters()) {
|
||||
writeParameter(sw, valueParameter.getType(), script.getUnsubstitutedPrimaryConstructor());
|
||||
writeParameter(sw, valueParameter.getType(), /* callableDescriptor = */ null);
|
||||
}
|
||||
|
||||
writeVoidReturn(sw);
|
||||
|
||||
@@ -33,20 +33,20 @@ internal class TypeMappingMode private constructor(
|
||||
* kotlin.Int is mapped to Ljava/lang/Integer;
|
||||
*/
|
||||
@JvmField
|
||||
val GENERIC_TYPE = TypeMappingMode()
|
||||
val GENERIC_ARGUMENT = TypeMappingMode()
|
||||
|
||||
/**
|
||||
* kotlin.Int is mapped to I
|
||||
*/
|
||||
@JvmField
|
||||
val DEFAULT = TypeMappingMode(genericArgumentMode = GENERIC_TYPE, needPrimitiveBoxing = false)
|
||||
val DEFAULT = TypeMappingMode(genericArgumentMode = GENERIC_ARGUMENT, needPrimitiveBoxing = false)
|
||||
|
||||
/**
|
||||
* kotlin.Int is mapped to Ljava/lang/Integer;
|
||||
* No projections allowed in immediate arguments
|
||||
*/
|
||||
@JvmField
|
||||
val SUPER_TYPE = TypeMappingMode(needPrimitiveBoxing = true, skipDeclarationSiteWildcards = true, genericArgumentMode = GENERIC_TYPE)
|
||||
val SUPER_TYPE = TypeMappingMode(skipDeclarationSiteWildcards = true, genericArgumentMode = GENERIC_ARGUMENT)
|
||||
|
||||
/**
|
||||
* kotlin.reflect.KClass mapped to java.lang.Class
|
||||
@@ -56,7 +56,7 @@ internal class TypeMappingMode private constructor(
|
||||
val VALUE_FOR_ANNOTATION = TypeMappingMode(
|
||||
isForAnnotationParameter = true,
|
||||
needPrimitiveBoxing = false,
|
||||
genericArgumentMode = TypeMappingMode(isForAnnotationParameter = true, genericArgumentMode = GENERIC_TYPE))
|
||||
genericArgumentMode = TypeMappingMode(isForAnnotationParameter = true, genericArgumentMode = GENERIC_ARGUMENT))
|
||||
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -72,7 +72,7 @@ public fun getEffectiveVariance(parameterVariance: Variance, projectionKind: Var
|
||||
return Variance.OUT_VARIANCE
|
||||
}
|
||||
|
||||
val CallableDescriptor.isMethodWithDeclarationSiteWildcards: Boolean
|
||||
val CallableDescriptor?.isMethodWithDeclarationSiteWildcards: Boolean
|
||||
get() {
|
||||
if (this !is CallableMemberDescriptor) return false
|
||||
return firstOverridden {
|
||||
@@ -101,11 +101,11 @@ internal fun TypeMappingMode.updateArgumentModeFromAnnotations(type: KotlinType)
|
||||
}
|
||||
|
||||
internal fun extractTypeMappingModeFromAnnotation(
|
||||
callableDescriptor: CallableDescriptor,
|
||||
callableDescriptor: CallableDescriptor?,
|
||||
outerType: KotlinType,
|
||||
isForAnnotationParameter: Boolean
|
||||
): TypeMappingMode? =
|
||||
(outerType.suppressWildcardsMode() ?: callableDescriptor.suppressWildcardsMode())?.let {
|
||||
(outerType.suppressWildcardsMode() ?: callableDescriptor?.suppressWildcardsMode())?.let {
|
||||
if (outerType.arguments.isNotEmpty())
|
||||
TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
|
||||
skipDeclarationSiteWildcards = it, isForAnnotationParameter = isForAnnotationParameter)
|
||||
|
||||
Reference in New Issue
Block a user