Skip to content

Commit cde7cb1

Browse files
committed
Kapt3: Write Intellij annotations (NotNull/Nullable) to stubs
1 parent 5a46c01 commit cde7cb1

28 files changed

+269
-82
lines changed

plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class ClassFileToSourceStubConverter(
6767
"java.lang.Synthetic",
6868
"synthetic.kotlin.jvm.GeneratedByJvmOverloads", // kapt3-related annotation for marking JvmOverloads-generated methods
6969
"java.lang.annotation.", // Java annotations
70-
"org.jetbrains.annotations.", // Nullable/NotNull, ReadOnly, Mutable
7170
"kotlin.jvm.", "kotlin.Metadata" // Kotlin annotations from runtime
7271
)
7372

plugins/kapt3/testData/converter/abstractEnum.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public enum E2 {
7474
E2(int n) {
7575
}
7676

77-
E2(java.lang.String s) {
77+
E2(@org.jetbrains.annotations.NotNull()
78+
java.lang.String s) {
7879
}
7980
}
8081

@@ -84,13 +85,16 @@ public enum E2 {
8485
public enum E3 {
8586
/*public static final*/ X /* = new X(null) */,
8687
/*public static final*/ Y /* = new Y(null) */;
88+
@org.jetbrains.annotations.NotNull()
8789
private final java.lang.String a = null;
8890

91+
@org.jetbrains.annotations.NotNull()
8992
public final java.lang.String getA() {
9093
return null;
9194
}
9295

93-
E3(java.lang.String a) {
96+
E3(@org.jetbrains.annotations.NotNull()
97+
java.lang.String a) {
9498
}
9599
}
96100

@@ -99,11 +103,13 @@ public enum E3 {
99103

100104
public enum E4 {
101105
/*public static final*/ X /* = new X(null, 0, 0L, false) */;
106+
@org.jetbrains.annotations.NotNull()
102107
private final java.lang.String a = null;
103108
private final int b = 0;
104109
private final long c = 0L;
105110
private final boolean d = false;
106111

112+
@org.jetbrains.annotations.NotNull()
107113
public final java.lang.String getA() {
108114
return null;
109115
}
@@ -120,6 +126,7 @@ public enum E4 {
120126
return false;
121127
}
122128

123-
E4(java.lang.String a, int b, long c, boolean d) {
129+
E4(@org.jetbrains.annotations.NotNull()
130+
java.lang.String a, int b, long c, boolean d) {
124131
}
125132
}

plugins/kapt3/testData/converter/abstractMethods.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
public abstract class Base {
22

3-
protected abstract void doJob(java.lang.String p0, int p1);
3+
protected abstract void doJob(@org.jetbrains.annotations.NotNull()
4+
java.lang.String p0, int p1);
45

5-
protected abstract <T extends java.lang.CharSequence>void doJobGeneric(T p0, int p1);
6+
protected abstract <T extends java.lang.CharSequence>void doJobGeneric(@org.jetbrains.annotations.NotNull()
7+
T p0, int p1);
68

79
public Base() {
810
super();
@@ -15,11 +17,13 @@ public abstract class Base {
1517
public final class Impl extends Base {
1618

1719
@java.lang.Override()
18-
protected void doJob(java.lang.String job, int delay) {
20+
protected void doJob(@org.jetbrains.annotations.NotNull()
21+
java.lang.String job, int delay) {
1922
}
2023

2124
@java.lang.Override()
22-
protected <T extends java.lang.CharSequence>void doJobGeneric(T job, int delay) {
25+
protected <T extends java.lang.CharSequence>void doJobGeneric(@org.jetbrains.annotations.NotNull()
26+
T job, int delay) {
2327
}
2428

2529
public Impl() {

plugins/kapt3/testData/converter/annotations.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,29 @@ public final class TestAnno {
6363
@Anno2(i = 6, s = "BCD", ii = {4, 5, 6}, ss = {"Z", "X"}, a = @Anno1(), color = Colors.WHITE, colors = {Colors.WHITE}, clazz = TestAnno.class, classes = {TestAnno.class, Anno1.class})
6464
@Anno3(value = "value")
6565
public final class TestAnno2 {
66+
@org.jetbrains.annotations.NotNull()
6667
@Anno3(value = "field")
6768
private java.lang.String b;
6869

6970
@Anno1()
70-
public final void a(@Anno3(value = "param-pam-pam")
71+
public final void a(@org.jetbrains.annotations.NotNull()
72+
@Anno3(value = "param-pam-pam")
7173
java.lang.String param) {
7274
}
7375

7476
@Anno3(value = "property")
7577
private static void b$annotations() {
7678
}
7779

80+
@org.jetbrains.annotations.NotNull()
7881
@Anno3(value = "getter")
7982
public final java.lang.String getB() {
8083
return null;
8184
}
8285

8386
@Anno3(value = "setter")
84-
public final void setB(@Anno3(value = "setparam")
87+
public final void setB(@org.jetbrains.annotations.NotNull()
88+
@Anno3(value = "setparam")
8589
java.lang.String p0) {
8690
}
8791

plugins/kapt3/testData/converter/annotations2.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ public final class AnnotationsTest {
1717
}
1818

1919
@Anno(value = "top-level-fun")
20-
public static final void topLevelFun(@Anno(value = "top-level-fun-receiver")
20+
public static final void topLevelFun(@org.jetbrains.annotations.NotNull()
21+
@Anno(value = "top-level-fun-receiver")
2122
java.lang.String $receiver) {
2223
}
2324

2425
@Anno(value = "top-level-val")
2526
private static void topLevelVal$annotations(int p0) {
2627
}
2728

29+
@org.jetbrains.annotations.NotNull()
2830
public static final java.lang.String getTopLevelVal(@Anno(value = "top-level-val-receiver")
2931
int $receiver) {
3032
return null;
@@ -57,33 +59,39 @@ package test;
5759

5860
@Anno(value = "clazz")
5961
public abstract class Test {
62+
@org.jetbrains.annotations.NotNull()
6063
private java.lang.String v;
6164

65+
@org.jetbrains.annotations.NotNull()
6266
@Anno(value = "abstract-method")
6367
public abstract java.lang.String abstractMethod();
6468

6569
@Anno(value = "abstract-val")
6670
private static void abstractVal$annotations() {
6771
}
6872

73+
@org.jetbrains.annotations.NotNull()
6974
public abstract java.lang.String getAbstractVal();
7075

7176
@Anno(value = "v-property")
7277
private static void v$annotations() {
7378
}
7479

80+
@org.jetbrains.annotations.NotNull()
7581
@Anno(value = "v-get")
7682
public final java.lang.String getV() {
7783
return null;
7884
}
7985

8086
@Anno(value = "v-set")
81-
public final void setV(@Anno(value = "v-setparam")
87+
public final void setV(@org.jetbrains.annotations.NotNull()
88+
@Anno(value = "v-setparam")
8289
java.lang.String p0) {
8390
}
8491

8592
@Anno(value = "test-constructor")
86-
protected Test(@Anno(value = "v-param")
93+
protected Test(@org.jetbrains.annotations.NotNull()
94+
@Anno(value = "v-param")
8795
java.lang.String v) {
8896
super();
8997
}

plugins/kapt3/testData/converter/dataClass.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
21
public final class User {
2+
@org.jetbrains.annotations.NotNull()
33
private final java.lang.String firstName = null;
4+
@org.jetbrains.annotations.NotNull()
45
private final java.lang.String secondName = null;
56
private final int age = 0;
67

78
public final void procedure() {
89
}
910

11+
@org.jetbrains.annotations.NotNull()
1012
public final java.lang.String getFirstName() {
1113
return null;
1214
}
1315

16+
@org.jetbrains.annotations.NotNull()
1417
public final java.lang.String getSecondName() {
1518
return null;
1619
}
@@ -19,14 +22,18 @@ public final class User {
1922
return 0;
2023
}
2124

22-
public User(java.lang.String firstName, java.lang.String secondName, int age) {
25+
public User(@org.jetbrains.annotations.NotNull()
26+
java.lang.String firstName, @org.jetbrains.annotations.NotNull()
27+
java.lang.String secondName, int age) {
2328
super();
2429
}
2530

31+
@org.jetbrains.annotations.NotNull()
2632
public final java.lang.String component1() {
2733
return null;
2834
}
2935

36+
@org.jetbrains.annotations.NotNull()
3037
public final java.lang.String component2() {
3138
return null;
3239
}
@@ -35,7 +42,10 @@ public final class User {
3542
return 0;
3643
}
3744

38-
public final User copy(java.lang.String firstName, java.lang.String secondName, int age) {
45+
@org.jetbrains.annotations.NotNull()
46+
public final User copy(@org.jetbrains.annotations.NotNull()
47+
java.lang.String firstName, @org.jetbrains.annotations.NotNull()
48+
java.lang.String secondName, int age) {
3949
return null;
4050
}
4151

@@ -53,4 +63,4 @@ public final class User {
5363
public boolean equals(java.lang.Object p0) {
5464
return false;
5565
}
56-
}
66+
}

plugins/kapt3/testData/converter/enums.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ public enum Enum1 {
2020
public enum Enum2 {
2121
/*public static final*/ RED /* = new RED(null, 0) */,
2222
/*public static final*/ WHITE /* = new WHITE(null, 0) */;
23+
@org.jetbrains.annotations.NotNull()
2324
private final java.lang.String col = null;
2425
private final int col2 = 0;
2526

27+
@org.jetbrains.annotations.NotNull()
2628
public final java.lang.String color() {
2729
return null;
2830
}
@@ -33,6 +35,7 @@ public enum Enum2 {
3335
public final void publicEnumFun() {
3436
}
3537

38+
@org.jetbrains.annotations.NotNull()
3639
public final java.lang.String getCol() {
3740
return null;
3841
}
@@ -41,7 +44,8 @@ public enum Enum2 {
4144
return 0;
4245
}
4346

44-
Enum2(@Anno1(value = "first")
47+
Enum2(@org.jetbrains.annotations.NotNull()
48+
@Anno1(value = "first")
4549
java.lang.String col, @Anno1(value = "second")
4650
int col2) {
4751
}

plugins/kapt3/testData/converter/functions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
public final class FunctionsTest {
22

3+
@org.jetbrains.annotations.NotNull()
34
public final kotlin.reflect.KProperty1<java.lang.String, java.lang.Integer> f() {
45
return null;
56
}
67

8+
@org.jetbrains.annotations.NotNull()
79
public final kotlin.jvm.functions.Function2<java.lang.Integer, java.lang.Integer, java.lang.Boolean> f2() {
810
return null;
911
}

plugins/kapt3/testData/converter/genericRawSignatures.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
public final class GenericRawSignatures {
22

3+
@org.jetbrains.annotations.Nullable()
34
public final <T extends java.lang.Object>T genericFun() {
45
return null;
56
}
67

8+
@org.jetbrains.annotations.Nullable()
79
public final java.lang.String nonGenericFun() {
810
return null;
911
}

plugins/kapt3/testData/converter/genericSimple.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
public abstract interface ABC {
22

3-
public abstract <T extends java.lang.CharSequence>java.util.List<T> abc(T p0, java.util.List<? extends T> p1, T... p2);
4-
5-
public abstract <X extends java.lang.Object>int bcd(char... p0);
3+
@org.jetbrains.annotations.NotNull()
4+
public abstract <T extends java.lang.CharSequence>java.util.List<T> abc(@org.jetbrains.annotations.NotNull()
5+
T p0, @org.jetbrains.annotations.NotNull()
6+
java.util.List<? extends T> p1, @org.jetbrains.annotations.NotNull()
7+
T... p2);
8+
9+
public abstract <X extends java.lang.Object>int bcd(@org.jetbrains.annotations.NotNull()
10+
char... p0);
611
}
712

813
////////////////////
@@ -31,8 +36,10 @@ public abstract interface Intf2<T extends java.util.List<? extends java.lang.Str
3136

3237

3338
public final class MyClass<M1 extends java.lang.Object, M2 extends java.lang.Object> extends BaseClass<java.lang.RuntimeException> implements Intf<java.lang.Object, java.util.Date>, OtherIntf<java.lang.String> {
39+
@org.jetbrains.annotations.Nullable()
3440
private final java.util.List<java.util.Map<java.lang.String, M1>> fld = null;
3541

42+
@org.jetbrains.annotations.Nullable()
3643
public final java.util.List<java.util.Map<java.lang.String, M1>> getFld() {
3744
return null;
3845
}

plugins/kapt3/testData/converter/inheritanceSimple.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
public abstract class BaseClass {
22

3+
@org.jetbrains.annotations.NotNull()
34
public abstract Result doJob();
45

5-
public BaseClass(Context context, int num, boolean bool) {
6+
public BaseClass(@org.jetbrains.annotations.NotNull()
7+
Context context, int num, boolean bool) {
68
super();
79
}
810
}
@@ -18,12 +20,14 @@ public abstract interface Context {
1820

1921
public final class Inheritor extends BaseClass {
2022

23+
@org.jetbrains.annotations.NotNull()
2124
@java.lang.Override()
2225
public Result doJob() {
2326
return null;
2427
}
2528

26-
public Inheritor(Context context) {
29+
public Inheritor(@org.jetbrains.annotations.NotNull()
30+
Context context) {
2731
super(null, 0, false);
2832
}
2933
}

plugins/kapt3/testData/converter/javaKeywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
public final class _default_ {
2+
@org.jetbrains.annotations.NotNull()
23
public java.lang.String _extends_;
34

5+
@org.jetbrains.annotations.NotNull()
46
public final java.lang.String getExtends() {
57
return null;
68
}

0 commit comments

Comments
 (0)