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