JVM: no nullability annotations on private and synthetic fields

This commit is contained in:
Dmitry Petrov
2020-06-25 13:06:51 +03:00
parent cbd8b58d5c
commit 3f266aafb4
35 changed files with 67 additions and 72 deletions
@@ -90,12 +90,18 @@ public abstract class AnnotationCodegen {
private final KotlinTypeMapper typeMapper;
private final ModuleDescriptor module;
private final GenerationState state;
private final boolean skipNullabilityAnnotations;
private AnnotationCodegen(@NotNull InnerClassConsumer innerClassConsumer, @NotNull GenerationState state) {
this(innerClassConsumer, state, false);
}
private AnnotationCodegen(@NotNull InnerClassConsumer innerClassConsumer, @NotNull GenerationState state, boolean skipNullabilityAnnotations) {
this.innerClassConsumer = innerClassConsumer;
this.typeMapper = state.getTypeMapper();
this.module = state.getModule();
this.state = state;
this.skipNullabilityAnnotations = skipNullabilityAnnotations;
}
/**
@@ -196,9 +202,7 @@ public abstract class AnnotationCodegen {
return;
}
if (returnType != null && !AsmUtil.isPrimitive(returnType) &&
!(descriptor instanceof PropertyDescriptor && ((PropertyDescriptor) descriptor).isDelegated())
) {
if (returnType != null && !AsmUtil.isPrimitive(returnType) && !skipNullabilityAnnotations) {
generateNullabilityAnnotation(descriptor.getReturnType(), annotationDescriptorsAlreadyPresent);
}
}
@@ -644,7 +648,16 @@ public abstract class AnnotationCodegen {
@NotNull InnerClassConsumer innerClassConsumer,
@NotNull GenerationState state
) {
return new AnnotationCodegen(innerClassConsumer, state) {
return forField(fv, innerClassConsumer, state, false);
}
public static AnnotationCodegen forField(
@NotNull FieldVisitor fv,
@NotNull InnerClassConsumer innerClassConsumer,
@NotNull GenerationState state,
boolean skipNullabilityAnnotations
) {
return new AnnotationCodegen(innerClassConsumer, state, skipNullabilityAnnotations) {
@NotNull
@Override
AnnotationVisitor visitAnnotation(String descr, boolean visible) {
@@ -438,7 +438,8 @@ public class PropertyCodegen {
);
if (annotatedField != null) {
AnnotationCodegen.forField(fv, memberCodegen, state)
boolean isInvisibleField = (modifiers & ACC_PRIVATE) != 0 || (modifiers & ACC_SYNTHETIC) != 0;
AnnotationCodegen.forField(fv, memberCodegen, state, isInvisibleField)
.genAnnotations(annotatedField, type, propertyDescriptor.getType());
}
}
@@ -2,7 +2,6 @@ public final class Wrapper {
public Wrapper() { /* compiled code */ }
public static final class Equals {
@org.jetbrains.annotations.NotNull
private final p.G code;
public boolean equals(@org.jetbrains.annotations.Nullable java.lang.Object other) { /* compiled code */ }
@@ -25,7 +24,6 @@ public final class Wrapper {
}
public static final class HashCode {
@org.jetbrains.annotations.NotNull
private final p.G code;
public int hashCode() { /* compiled code */ }
@@ -48,7 +46,6 @@ public final class Wrapper {
}
public static final class ToString {
@org.jetbrains.annotations.NotNull
private final p.G code;
@org.jetbrains.annotations.NotNull
@@ -1,7 +1,6 @@
public final class A {
@kotlin.jvm.Transient
@kotlin.jvm.Volatile
@org.jetbrains.annotations.NotNull
private transient volatile java.lang.String c;
@kotlin.jvm.Synchronized
@@ -2,6 +2,7 @@ public final class SmartSet <T> extends kotlin.collections.AbstractSet<T> implem
private java.lang.Object data;
private int size;
private static final int ARRAY_THRESHOLD;
@org.jetbrains.annotations.NotNull
public static final SmartSet.Companion Companion;
public int getSize() { /* compiled code */ }
@@ -1,11 +1,7 @@
public final class Class {
@org.jetbrains.annotations.Nullable
private final java.lang.String nullableVal;
@org.jetbrains.annotations.Nullable
private java.lang.String nullableVar;
@org.jetbrains.annotations.NotNull
private final java.lang.String notNullVal;
@org.jetbrains.annotations.NotNull
private java.lang.String notNullVar;
private final java.lang.String privateNN;
private final java.lang.String privateN;
@@ -69,4 +65,4 @@ public final class Class {
public final void setNullableVarWithGetSet(@org.jetbrains.annotations.Nullable java.lang.String v) { /* compiled code */ }
public Class() { /* compiled code */ }
}
}
@@ -1,5 +1,4 @@
public final class ClassObjectField {
@org.jetbrains.annotations.Nullable
private static final java.lang.String x;
private static final java.lang.String y;
@org.jetbrains.annotations.NotNull
@@ -1,7 +1,5 @@
public final class ClassWithConstructorAndProperties {
@org.jetbrains.annotations.Nullable
private final java.lang.String nullable;
@org.jetbrains.annotations.NotNull
private final java.lang.String notNull;
@org.jetbrains.annotations.Nullable
@@ -11,4 +9,4 @@ public final class ClassWithConstructorAndProperties {
public final java.lang.String getNotNull() { /* compiled code */ }
public ClassWithConstructorAndProperties(@org.jetbrains.annotations.Nullable java.lang.String nullable, @org.jetbrains.annotations.NotNull java.lang.String notNull) { /* compiled code */ }
}
}
@@ -1,11 +1,7 @@
public final class FileFacadeKt {
@org.jetbrains.annotations.Nullable
private static final java.lang.String nullableVal;
@org.jetbrains.annotations.Nullable
private static java.lang.String nullableVar;
@org.jetbrains.annotations.NotNull
private static final java.lang.String notNullVal;
@org.jetbrains.annotations.NotNull
private static java.lang.String notNullVar;
private static final java.lang.String privateNn;
private static final java.lang.String privateN;
@@ -1,6 +1,5 @@
public final class A {
private static final int c;
@org.jetbrains.annotations.NotNull
private static java.lang.String v;
public static final int cc = 1;
@org.jetbrains.annotations.NotNull
@@ -59,7 +59,7 @@ public final class Override5Kt$inlineMe$1 {
@kotlin.Metadata
public final class Override5Kt {
private static @org.jetbrains.annotations.Nullable field c: kotlin.coroutines.Continuation
private static field c: kotlin.coroutines.Continuation
inner class Override5Kt$box$1
inner class Override5Kt$inlineMe$1
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
class Example {
@@ -1,7 +1,7 @@
@kotlin.Metadata
public final class Example {
private field prop2: int
private synthetic final @org.jetbrains.annotations.NotNull field prop: java.lang.String
private synthetic final field prop: java.lang.String
private field useSite2: int
private synthetic final field useSite: int
public method <init>(): void
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
@Target(AnnotationTarget.FIELD)
annotation class Anno
@@ -6,7 +6,7 @@ public annotation class Anno
@kotlin.Metadata
public final class C {
private final @Anno @org.jetbrains.annotations.NotNull field json: java.lang.String
private final @Anno field json: java.lang.String
private final field x: int
public method <init>(p0: int): void
public final method component1(): int
@@ -2,7 +2,7 @@
public final class LocalClassWithCapturedParamsKt$localCaptured$A {
synthetic final field $z: int
private final field x: int
private final @org.jetbrains.annotations.NotNull field z: java.lang.String
private final field z: java.lang.String
inner class LocalClassWithCapturedParamsKt$localCaptured$A
public method <init>(p0: int, @Simple @org.jetbrains.annotations.NotNull p1: java.lang.String): void
public final method getX(): int
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
class A {
val a = ""
fun b() = ""
@@ -1,6 +1,6 @@
@kotlin.Metadata
public final class A {
private final @org.jetbrains.annotations.NotNull field a: java.lang.String
private final field a: java.lang.String
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method b(): java.lang.String
public final @org.jetbrains.annotations.NotNull method getA(): java.lang.String
@@ -20,7 +20,7 @@ public final class NullabilityInExpansionKt {
@kotlin.Metadata
public final class Q1 {
private final @org.jetbrains.annotations.Nullable field x: java.lang.Integer
private final field x: java.lang.Integer
private synthetic method <init>(@org.jetbrains.annotations.Nullable p0: java.lang.Integer): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.Nullable p0: java.lang.Integer): Q1
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.Nullable p0: java.lang.Integer): java.lang.Integer
@@ -37,7 +37,7 @@ public final class Q1 {
@kotlin.Metadata
public final class Q2 {
private final @org.jetbrains.annotations.NotNull field z: java.lang.Integer
private final field z: java.lang.Integer
private synthetic method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.Integer): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.NotNull p0: java.lang.Integer): Q2
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.NotNull p0: java.lang.Integer): java.lang.Integer
@@ -54,7 +54,7 @@ public final class Q2 {
@kotlin.Metadata
public final class QN {
private final @org.jetbrains.annotations.Nullable field z: Q1
private final field z: Q1
private synthetic method <init>(@org.jetbrains.annotations.Nullable p0: Q1): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.Nullable p0: Q1): QN
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.Nullable p0: Q1): Q1
@@ -71,7 +71,7 @@ public final class QN {
@kotlin.Metadata
public final class S1 {
private final @org.jetbrains.annotations.NotNull field x: java.lang.String
private final field x: java.lang.String
private synthetic method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.NotNull p0: java.lang.String): S1
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
@@ -88,7 +88,7 @@ public final class S1 {
@kotlin.Metadata
public final class S2 {
private final @org.jetbrains.annotations.NotNull field z: java.lang.String
private final field z: java.lang.String
private synthetic method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.NotNull p0: java.lang.String): S2
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
@@ -105,7 +105,7 @@ public final class S2 {
@kotlin.Metadata
public final class SN {
private final @org.jetbrains.annotations.Nullable field z: java.lang.String
private final field z: java.lang.String
private synthetic method <init>(@org.jetbrains.annotations.Nullable p0: java.lang.String): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.Nullable p0: java.lang.String): SN
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.Nullable p0: java.lang.String): java.lang.String
@@ -122,7 +122,7 @@ public final class SN {
@kotlin.Metadata
public final class SN2 {
private final @org.jetbrains.annotations.NotNull field z: java.lang.String
private final field z: java.lang.String
private synthetic method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.NotNull p0: java.lang.String): SN2
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
@@ -139,7 +139,7 @@ public final class SN2 {
@kotlin.Metadata
public final class W1 {
private final @org.jetbrains.annotations.Nullable field x: java.lang.String
private final field x: java.lang.String
private synthetic method <init>(@org.jetbrains.annotations.Nullable p0: java.lang.String): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.Nullable p0: java.lang.String): W1
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.Nullable p0: java.lang.String): java.lang.String
@@ -156,7 +156,7 @@ public final class W1 {
@kotlin.Metadata
public final class W2 {
private final @org.jetbrains.annotations.NotNull field z: java.lang.String
private final field z: java.lang.String
private synthetic method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.NotNull p0: java.lang.String): W2
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String
@@ -173,7 +173,7 @@ public final class W2 {
@kotlin.Metadata
public final class WN {
private final @org.jetbrains.annotations.Nullable field z: W1
private final field z: W1
private synthetic method <init>(@org.jetbrains.annotations.Nullable p0: W1): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.Nullable p0: W1): WN
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.Nullable p0: W1): W1
@@ -224,7 +224,7 @@ public final class Z2 {
@kotlin.Metadata
public final class ZN {
private final @org.jetbrains.annotations.Nullable field z: Z1
private final field z: Z1
private synthetic method <init>(@org.jetbrains.annotations.Nullable p0: Z1): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.Nullable p0: Z1): ZN
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.Nullable p0: Z1): Z1
@@ -241,7 +241,7 @@ public final class ZN {
@kotlin.Metadata
public final class ZN2 {
private final @org.jetbrains.annotations.NotNull field z: Z1
private final field z: Z1
private synthetic method <init>(@org.jetbrains.annotations.NotNull p0: Z1): void
public synthetic final static @org.jetbrains.annotations.NotNull method box-impl(@org.jetbrains.annotations.NotNull p0: Z1): ZN2
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.NotNull p0: Z1): Z1
@@ -40,10 +40,10 @@ synthetic final class NoReceiverInCallableReferenceClassesKt$aFoo$1 {
@kotlin.Metadata
public final class NoReceiverInCallableReferenceClassesKt {
private final static @org.jetbrains.annotations.NotNull field A_bar: kotlin.reflect.KProperty1
private final static @org.jetbrains.annotations.NotNull field A_foo: kotlin.reflect.KFunction
private final static @org.jetbrains.annotations.NotNull field aBar: kotlin.reflect.KProperty0
private final static @org.jetbrains.annotations.NotNull field aFoo: kotlin.reflect.KFunction
private final static field A_bar: kotlin.reflect.KProperty1
private final static field A_foo: kotlin.reflect.KFunction
private final static field aBar: kotlin.reflect.KProperty0
private final static field aFoo: kotlin.reflect.KFunction
inner class NoReceiverInCallableReferenceClassesKt$A_foo$1
inner class NoReceiverInCallableReferenceClassesKt$aFoo$1
static method <clinit>(): void
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
open class Test {
var publicProperty: String = ""
private set
@@ -1,8 +1,8 @@
@kotlin.Metadata
public class Test {
private @org.jetbrains.annotations.NotNull field internalProperty: java.lang.String
private @org.jetbrains.annotations.NotNull field protectedProperty: java.lang.String
private @org.jetbrains.annotations.NotNull field publicProperty: java.lang.String
private field internalProperty: java.lang.String
private field protectedProperty: java.lang.String
private field publicProperty: java.lang.String
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getInternalProperty$test_module(): java.lang.String
protected final @org.jetbrains.annotations.NotNull method getProtectedProperty(): java.lang.String
+1 -1
View File
@@ -1,7 +1,7 @@
@kotlin.Metadata
public final class User {
private final field age: int
private final @org.jetbrains.annotations.NotNull field name: java.lang.String
private final field name: java.lang.String
public method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String, p1: int): void
public final @org.jetbrains.annotations.NotNull method component1(): java.lang.String
public final method component2(): int
+1 -1
View File
@@ -1,7 +1,7 @@
@kotlin.Metadata
@kotlin.Suppress
public final class A {
private final @org.jetbrains.annotations.NotNull field a: error.NonExistentClass
private final field a: error.NonExistentClass
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getA(): error.NonExistentClass
}
+2 -2
View File
@@ -37,8 +37,8 @@ public final class test/TopLevel$NestedClass {
@kotlin.Metadata
public final class test/TopLevel {
public final static @org.jetbrains.annotations.NotNull field Companion: test.TopLevel$Companion
private final static @org.jetbrains.annotations.NotNull field q: java.lang.String
private final @org.jetbrains.annotations.NotNull field x: java.lang.String
private final static field q: java.lang.String
private final field x: java.lang.String
private final field y: int
inner class test/TopLevel$Companion
inner class test/TopLevel$InnerInterface
@@ -19,7 +19,7 @@ public interface Intf
@kotlin.Metadata
public final class MyClass {
private @AllOpen @org.jetbrains.annotations.NotNull field prop: java.lang.String
private @AllOpen field prop: java.lang.String
public method <init>(): void
public final @AllOpen @org.jetbrains.annotations.NotNull method getProp(): java.lang.String
public final @AllOpen method method(): void
@@ -11,7 +11,7 @@ public class Test1 {
@AllOpen
@kotlin.Metadata
public class Test2 {
private final @org.jetbrains.annotations.NotNull field prop: java.lang.String
private final field prop: java.lang.String
public method <init>(): void
public @org.jetbrains.annotations.NotNull method getProp(): java.lang.String
public method method(): void
@@ -20,8 +20,8 @@ public class Test2 {
@AllOpen
@kotlin.Metadata
public class Test3 {
private final @org.jetbrains.annotations.NotNull field prop: java.lang.String
private final field prop: java.lang.String
public method <init>(): void
public @org.jetbrains.annotations.NotNull method getProp(): java.lang.String
public method method(): void
}
}
@@ -28,7 +28,7 @@ final class Test$b$2 {
@AllOpen
@kotlin.Metadata
public class Test {
private final @org.jetbrains.annotations.NotNull field a: java.lang.Runnable
private final field a: java.lang.Runnable
inner class Test$a$1
inner class Test$b$1
inner class Test$b$2
@@ -11,9 +11,9 @@ public final class Test1 {
@AllOpen
@kotlin.Metadata
public class Test2 {
private final @org.jetbrains.annotations.NotNull field prop1: java.lang.String
private final @org.jetbrains.annotations.NotNull field prop2: java.lang.String
private @org.jetbrains.annotations.NotNull field prop3: java.lang.String
private final field prop1: java.lang.String
private final field prop2: java.lang.String
private field prop3: java.lang.String
public method <init>(): void
public @org.jetbrains.annotations.NotNull method getProp1(): java.lang.String
public final @org.jetbrains.annotations.NotNull method getProp2(): java.lang.String
@@ -1,6 +1,6 @@
@kotlin.Metadata
public final class Test {
private final @org.jetbrains.annotations.NotNull field prop: java.lang.String
private final field prop: java.lang.String
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getProp(): java.lang.String
public final method method(): void
@@ -5,10 +5,10 @@ public annotation class AllOpen
@AllOpen
@kotlin.Metadata
class Test {
private final @org.jetbrains.annotations.NotNull field internalProp: java.lang.String
private final field internalProp: java.lang.String
private final field privateProp: java.lang.String
private final @org.jetbrains.annotations.NotNull field protectedProp: java.lang.String
private final @org.jetbrains.annotations.NotNull field publicProp: java.lang.String
private final field protectedProp: java.lang.String
private final field publicProp: java.lang.String
public method <init>(): void
public @org.jetbrains.annotations.NotNull method getInternalProp$test_module(): java.lang.String
protected @org.jetbrains.annotations.NotNull method getProtectedProp(): java.lang.String
@@ -10,7 +10,7 @@ public annotation class AllOpen2
@AllOpen2
@kotlin.Metadata
public class Test {
private final @org.jetbrains.annotations.NotNull field prop: java.lang.String
private final field prop: java.lang.String
public method <init>(): void
public @org.jetbrains.annotations.NotNull method getProp(): java.lang.String
public method method(): void
@@ -5,8 +5,8 @@ public annotation class AllOpen
@AllOpen
@kotlin.Metadata
public class Test {
private final @org.jetbrains.annotations.NotNull field prop: java.lang.String
private final field prop: java.lang.String
public method <init>(): void
public @org.jetbrains.annotations.NotNull method getProp(): java.lang.String
public method method(): void
}
}
@@ -10,7 +10,7 @@ public class BaseImpl {
@kotlin.Metadata
public class BaseImpl2_ShouldBeOpen {
private final @org.jetbrains.annotations.NotNull field baseImpl2Property_ShouldBeOpen: java.lang.String
private final field baseImpl2Property_ShouldBeOpen: java.lang.String
public method <init>(): void
public method baseImpl2Method_ShouldBeOpen(): void
public @org.jetbrains.annotations.NotNull method getBaseImpl2Property_ShouldBeOpen(): java.lang.String
@@ -16,7 +16,7 @@ public interface Intf
@kotlin.Metadata
public final class MyClass {
private @NoArg @org.jetbrains.annotations.NotNull field abc: java.lang.String
private @NoArg field abc: java.lang.String
public method <init>(p0: int): void
public final @NoArg @org.jetbrains.annotations.NotNull method getAbc(): java.lang.String
public final @NoArg method setAbc(@org.jetbrains.annotations.NotNull p0: java.lang.String): void