JVM: no nullability annotations for inline class '-impl' methods
Specialized generated methods for inline classes (toString-impl, hashCode-impl, equals-impl, etc) are inaccessible from Java, and thus don't require nullability annotations.
This commit is contained in:
@@ -33,10 +33,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi;
|
|||||||
import org.jetbrains.kotlin.load.java.SpecialBuiltinMembers;
|
import org.jetbrains.kotlin.load.java.SpecialBuiltinMembers;
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
|
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.*;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
|
||||||
import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt;
|
|
||||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.UnderscoreUtilKt;
|
import org.jetbrains.kotlin.resolve.calls.util.UnderscoreUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.constants.ArrayValue;
|
import org.jetbrains.kotlin.resolve.constants.ArrayValue;
|
||||||
@@ -219,7 +216,9 @@ public class FunctionCodegen {
|
|||||||
|
|
||||||
recordMethodForFunctionIfAppropriate(functionDescriptor, asmMethod);
|
recordMethodForFunctionIfAppropriate(functionDescriptor, asmMethod);
|
||||||
|
|
||||||
boolean skipNullabilityAnnotations = (flags & ACC_PRIVATE) != 0 || (flags & ACC_SYNTHETIC) != 0;
|
boolean skipNullabilityAnnotations =
|
||||||
|
(flags & ACC_PRIVATE) != 0 || (flags & ACC_SYNTHETIC) != 0 ||
|
||||||
|
InlineClassDescriptorResolver.isSpecializedEqualsMethod(functionDescriptor);
|
||||||
generateMethodAnnotationsIfRequired(
|
generateMethodAnnotationsIfRequired(
|
||||||
functionDescriptor, asmMethod, jvmSignature, mv,
|
functionDescriptor, asmMethod, jvmSignature, mv,
|
||||||
isCompatibilityStubInDefaultImpls ? Collections.singletonList(Deprecated.class) : Collections.emptyList(),
|
isCompatibilityStubInDefaultImpls ? Collections.singletonList(Deprecated.class) : Collections.emptyList(),
|
||||||
@@ -533,14 +532,18 @@ public class FunctionCodegen {
|
|||||||
? iterator.next()
|
? iterator.next()
|
||||||
: kind == JvmMethodParameterKind.RECEIVER
|
: kind == JvmMethodParameterKind.RECEIVER
|
||||||
? JvmCodegenUtil.getDirectMember(functionDescriptor).getExtensionReceiverParameter()
|
? JvmCodegenUtil.getDirectMember(functionDescriptor).getExtensionReceiverParameter()
|
||||||
: isDefaultImpl && kind == JvmMethodParameterKind.THIS ? JvmCodegenUtil.getDirectMember(functionDescriptor)
|
: kind == JvmMethodParameterKind.THIS && isDefaultImpl
|
||||||
.getDispatchReceiverParameter() : null;
|
? JvmCodegenUtil.getDirectMember(functionDescriptor).getDispatchReceiverParameter()
|
||||||
|
: null;
|
||||||
|
|
||||||
if (annotated != null) {
|
if (annotated != null) {
|
||||||
//noinspection ConstantConditions
|
|
||||||
int parameterIndex = i - syntheticParameterCount;
|
int parameterIndex = i - syntheticParameterCount;
|
||||||
AnnotationCodegen.forParameter(parameterIndex, mv, memberCodegen, state, skipNullabilityAnnotations)
|
AnnotationCodegen
|
||||||
.genAnnotations(annotated, parameterSignature.getAsmType(), annotated.getReturnType(), functionDescriptor, Collections.emptyList());
|
.forParameter(parameterIndex, mv, memberCodegen, state, skipNullabilityAnnotations)
|
||||||
|
.genAnnotations(
|
||||||
|
annotated, parameterSignature.getAsmType(), annotated.getReturnType(), functionDescriptor,
|
||||||
|
Collections.emptyList()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-10
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
|
|||||||
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.descriptors.PropertyDescriptor;
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt;
|
import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt;
|
||||||
@@ -46,6 +45,7 @@ public class FunctionsFromAnyGeneratorImpl extends FunctionsFromAnyGenerator {
|
|||||||
private final GenerationState generationState;
|
private final GenerationState generationState;
|
||||||
private final KotlinTypeMapper typeMapper;
|
private final KotlinTypeMapper typeMapper;
|
||||||
private final JvmKotlinType underlyingType;
|
private final JvmKotlinType underlyingType;
|
||||||
|
private final boolean isInErasedInlineClass;
|
||||||
|
|
||||||
public FunctionsFromAnyGeneratorImpl(
|
public FunctionsFromAnyGeneratorImpl(
|
||||||
@NotNull KtClassOrObject declaration,
|
@NotNull KtClassOrObject declaration,
|
||||||
@@ -67,23 +67,27 @@ public class FunctionsFromAnyGeneratorImpl extends FunctionsFromAnyGenerator {
|
|||||||
typeMapper.mapType(descriptor),
|
typeMapper.mapType(descriptor),
|
||||||
InlineClassesUtilsKt.substitutedUnderlyingType(descriptor.getDefaultType())
|
InlineClassesUtilsKt.substitutedUnderlyingType(descriptor.getDefaultType())
|
||||||
);
|
);
|
||||||
|
this.isInErasedInlineClass = fieldOwnerContext.getContextKind() == OwnerKind.ERASED_INLINE_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void generateToStringMethod(
|
protected void generateToStringMethod(
|
||||||
@NotNull FunctionDescriptor function, @NotNull List<? extends PropertyDescriptor> properties
|
@NotNull FunctionDescriptor function,
|
||||||
|
@NotNull List<? extends PropertyDescriptor> properties
|
||||||
) {
|
) {
|
||||||
MethodContext context = fieldOwnerContext.intoFunction(function);
|
MethodContext context = fieldOwnerContext.intoFunction(function);
|
||||||
JvmDeclarationOrigin methodOrigin = JvmDeclarationOriginKt.OtherOrigin(function);
|
JvmDeclarationOrigin methodOrigin = JvmDeclarationOriginKt.OtherOrigin(function);
|
||||||
String toStringMethodName = mapFunctionName(function);
|
String toStringMethodName = mapFunctionName(function);
|
||||||
MethodVisitor mv = v.newMethod(methodOrigin, getAccess(), toStringMethodName, getToStringDesc(), null, null);
|
MethodVisitor mv = v.newMethod(methodOrigin, getAccess(), toStringMethodName, getToStringDesc(), null, null);
|
||||||
|
|
||||||
if (fieldOwnerContext.getContextKind() != OwnerKind.ERASED_INLINE_CLASS && classDescriptor.isInline()) {
|
if (!isInErasedInlineClass && classDescriptor.isInline()) {
|
||||||
FunctionCodegen.generateMethodInsideInlineClassWrapper(methodOrigin, function, classDescriptor, mv, typeMapper);
|
FunctionCodegen.generateMethodInsideInlineClassWrapper(methodOrigin, function, classDescriptor, mv, typeMapper);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
visitEndForAnnotationVisitor(mv.visitAnnotation(Type.getDescriptor(NotNull.class), false));
|
if (!isInErasedInlineClass) {
|
||||||
|
visitEndForAnnotationVisitor(mv.visitAnnotation(Type.getDescriptor(NotNull.class), false));
|
||||||
|
}
|
||||||
|
|
||||||
if (!generationState.getClassBuilderMode().generateBodies) {
|
if (!generationState.getClassBuilderMode().generateBodies) {
|
||||||
FunctionCodegen.endVisit(mv, toStringMethodName, getDeclaration());
|
FunctionCodegen.endVisit(mv, toStringMethodName, getDeclaration());
|
||||||
@@ -144,7 +148,7 @@ public class FunctionsFromAnyGeneratorImpl extends FunctionsFromAnyGenerator {
|
|||||||
String hashCodeMethodName = mapFunctionName(function);
|
String hashCodeMethodName = mapFunctionName(function);
|
||||||
MethodVisitor mv = v.newMethod(methodOrigin, getAccess(), hashCodeMethodName, getHashCodeDesc(), null, null);
|
MethodVisitor mv = v.newMethod(methodOrigin, getAccess(), hashCodeMethodName, getHashCodeDesc(), null, null);
|
||||||
|
|
||||||
if (fieldOwnerContext.getContextKind() != OwnerKind.ERASED_INLINE_CLASS && classDescriptor.isInline()) {
|
if (!isInErasedInlineClass && classDescriptor.isInline()) {
|
||||||
FunctionCodegen.generateMethodInsideInlineClassWrapper(methodOrigin, function, classDescriptor, mv, typeMapper);
|
FunctionCodegen.generateMethodInsideInlineClassWrapper(methodOrigin, function, classDescriptor, mv, typeMapper);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -213,15 +217,14 @@ public class FunctionsFromAnyGeneratorImpl extends FunctionsFromAnyGenerator {
|
|||||||
String equalsMethodName = mapFunctionName(function);
|
String equalsMethodName = mapFunctionName(function);
|
||||||
MethodVisitor mv = v.newMethod(methodOrigin, getAccess(), equalsMethodName, getEqualsDesc(), null, null);
|
MethodVisitor mv = v.newMethod(methodOrigin, getAccess(), equalsMethodName, getEqualsDesc(), null, null);
|
||||||
|
|
||||||
boolean isErasedInlineClassKind = fieldOwnerContext.getContextKind() == OwnerKind.ERASED_INLINE_CLASS;
|
if (!isInErasedInlineClass && classDescriptor.isInline()) {
|
||||||
if (!isErasedInlineClassKind && classDescriptor.isInline()) {
|
|
||||||
FunctionCodegen.generateMethodInsideInlineClassWrapper(methodOrigin, function, classDescriptor, mv, typeMapper);
|
FunctionCodegen.generateMethodInsideInlineClassWrapper(methodOrigin, function, classDescriptor, mv, typeMapper);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
visitEndForAnnotationVisitor(
|
if (!isInErasedInlineClass) {
|
||||||
mv.visitParameterAnnotation(isErasedInlineClassKind ? 1 : 0, Type.getDescriptor(Nullable.class), false)
|
visitEndForAnnotationVisitor(mv.visitParameterAnnotation(0, Type.getDescriptor(Nullable.class), false));
|
||||||
);
|
}
|
||||||
|
|
||||||
if (!generationState.getClassBuilderMode().generateBodies) {
|
if (!generationState.getClassBuilderMode().generateBodies) {
|
||||||
FunctionCodegen.endVisit(mv, equalsMethodName, getDeclaration());
|
FunctionCodegen.endVisit(mv, equalsMethodName, getDeclaration());
|
||||||
|
|||||||
Reference in New Issue
Block a user