[FIR] Implement UNNECESSARY_SAFE_CALL checker for java warning level types

#KT-63528 Fixed
This commit is contained in:
Kirill Rakhman
2024-01-02 17:22:55 +01:00
committed by Space Team
parent 9c0ac27307
commit d6bd31b313
17 changed files with 66 additions and 288 deletions
@@ -1,38 +0,0 @@
// FILE: ClassWithExternalAnnotatedMembers.java
import org.jetbrains.annotations.NotNull;
public class ClassWithExternalAnnotatedMembers {
public String externalNotNullField;
@NotNull
public String explicitNotNullField;
public static String staticExternalNotNullField;
@NotNull
public static String staticExplicitNotNullField;
}
// FILE: usage.kt
fun test() {
val x = ClassWithExternalAnnotatedMembers()
x.externalNotNullField?.foo()
x.explicitNotNullField<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
ClassWithExternalAnnotatedMembers.staticExternalNotNullField?.foo()
ClassWithExternalAnnotatedMembers.staticExplicitNotNullField<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
}
fun String.foo() {
}
// FILE: annotations.xml
<root>
<item name='ClassWithExternalAnnotatedMembers externalNotNullField'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='ClassWithExternalAnnotatedMembers staticExternalNotNullField'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: ClassWithExternalAnnotatedMembers.java
import org.jetbrains.annotations.NotNull;
@@ -1,44 +0,0 @@
// FILE: one/two/ClassWithExternalAnnotatedMembers.java
package one.two;
import org.jetbrains.annotations.NotNull;
public class ClassWithExternalAnnotatedMembers {
public String externalNotNullField;
@NotNull
public String explicitNotNullField;
public static String staticExternalNotNullField;
@NotNull
public static String staticExplicitNotNullField;
}
// FILE: one/usage.kt
package one
import one.two.ClassWithExternalAnnotatedMembers
fun test() {
val x = ClassWithExternalAnnotatedMembers()
x.externalNotNullField?.foo()
x.explicitNotNullField<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
ClassWithExternalAnnotatedMembers.staticExternalNotNullField?.foo()
ClassWithExternalAnnotatedMembers.staticExplicitNotNullField<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
}
fun String.foo() {
}
// FILE: one/two/annotations.xml
<root>
<item name='one.two.ClassWithExternalAnnotatedMembers externalNotNullField'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='one.two.ClassWithExternalAnnotatedMembers staticExternalNotNullField'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: one/two/ClassWithExternalAnnotatedMembers.java
package one.two;
@@ -1,46 +0,0 @@
// FILE: ClassWithExternalAnnotatedMembers.java
import org.jetbrains.annotations.NotNull;
public class ClassWithExternalAnnotatedMembers {
public String externalNotNullMethod() {
return "";
}
@NotNull
public String explicitNotNullMethod() {
return "";
}
public static String staticExternalNotNullMethod() {
return "";
}
@NotNull
public static String staticExplicitNotNullMethod() {
return "";
}
}
// FILE: usage.kt
fun test() {
val x = ClassWithExternalAnnotatedMembers()
x.externalNotNullMethod()?.foo()
x.explicitNotNullMethod()<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
ClassWithExternalAnnotatedMembers.staticExternalNotNullMethod()?.foo()
ClassWithExternalAnnotatedMembers.staticExplicitNotNullMethod()<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
}
fun String.foo() {
}
// FILE: annotations.xml
<root>
<item name='ClassWithExternalAnnotatedMembers java.lang.String externalNotNullMethod()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='ClassWithExternalAnnotatedMembers java.lang.String staticExternalNotNullMethod()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: ClassWithExternalAnnotatedMembers.java
import org.jetbrains.annotations.NotNull;
@@ -1,71 +0,0 @@
// MODULE: javaModule
// FILE: one/two/FirstModuleClass.java
package one.two;
import org.jetbrains.annotations.NotNull;
public class FirstModuleClass {
public String externalNotNullMethod() {
return "";
}
@NotNull
public String explicitNotNullMethod() {
return "";
}
}
// FILE: one/two/annotations.xml
<root>
<item name='one.two.FirstModuleClass java.lang.String externalNotNullMethod()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
// FILE: usage.kt
package usage1
import one.two.FirstModuleClass
fun test() {
val x = FirstModuleClass()
x.externalNotNullMethod()?.foo()
x.explicitNotNullMethod()<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
}
fun String.foo() {
}
// MODULE: javaModule2
// FILE: three/SecondModuleClass.java
package three;
import org.jetbrains.annotations.NotNull;
public class SecondModuleClass {
public static String staticExternalNotNullMethod() {
return "";
}
@NotNull
public static String staticExplicitNotNullMethod() {
return "";
}
}
// FILE: three/annotations.xml
<root>
<item name='three.SecondModuleClass java.lang.String staticExternalNotNullMethod()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
// FILE: my/pack/usage.kt
package my.pack
import three.SecondModuleClass
fun test() {
SecondModuleClass.staticExternalNotNullMethod()?.foo()
SecondModuleClass.staticExplicitNotNullMethod()<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
}
fun String.foo() {
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: javaModule
// FILE: one/two/FirstModuleClass.java
package one.two;