Rewrite RedundantSamConstructorInspection to support more cases
- Now inspection does not rely on synthetic descriptors at all, instead it uses `SamConversionOracle` and `SamConversionResolver` to detect if the argument type support SAM conversion - This transparently considers all language features like `SAM conversions for kotlin functions`, `Functional interfaces` etc. - In case of multiple SAM arguments, part of them can be converted only when `SAM conversion per argument` is enabled - Fix inspection and nj2k tests that were failing because of better working inspection - Rewrite automatically fixes multiple bugs that were present - ^KT-36367 ^KT-36368 ^KT-36296 ^KT-36395 Fixed
This commit is contained in:
committed by
Roman Golyshev
parent
9b5110b9f3
commit
46ae6136cb
+22
@@ -103,6 +103,17 @@
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>otherGenericsInParams.kt</file>
|
||||
<line>7</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="method" FQNAME="redundantSamConstructor.OtherGenericsInParamsKt void test()" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
<highlighted_element>Runnable</highlighted_element>
|
||||
<offset>21</offset>
|
||||
<length>8</length>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>otherGenericsInParams.kt</file>
|
||||
<line>8</line>
|
||||
@@ -111,6 +122,17 @@
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>otherGenericsInParams.kt</file>
|
||||
<line>9</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="method" FQNAME="redundantSamConstructor.OtherGenericsInParamsKt void test()" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
<highlighted_element>Runnable</highlighted_element>
|
||||
<offset>35</offset>
|
||||
<length>8</length>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>otherGenericsInParams.kt</file>
|
||||
<line>11</line>
|
||||
|
||||
Vendored
+2
-2
@@ -4,9 +4,9 @@ import a.*
|
||||
|
||||
fun test() {
|
||||
MyJavaClass.foo1({ }, 1)
|
||||
MyJavaClass.foo1(Runnable { }, Runnable { })
|
||||
MyJavaClass.foo1({ }, Runnable { })
|
||||
MyJavaClass.foo2(1, { })
|
||||
MyJavaClass.foo2(Runnable { }, Runnable { })
|
||||
MyJavaClass.foo2(Runnable { }, { })
|
||||
|
||||
A<String>().foo({})
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
public class Test {
|
||||
static public void test(Runnable r1, Runnable r2) {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:+SamConversionPerArgument
|
||||
|
||||
fun usage(r1: Runnable) {
|
||||
Test.test(r1, Runnable<caret> {})
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:+SamConversionPerArgument
|
||||
|
||||
fun usage(r1: Runnable) {
|
||||
Test.test(r1, {})
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:+SamConversionPerArgument
|
||||
|
||||
fun test(r1: Runnable, r2: Runnable) {}
|
||||
|
||||
fun usage(r1: Runnable) {
|
||||
test(r1, Runnable<caret> {})
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:+SamConversionPerArgument
|
||||
|
||||
fun test(r1: Runnable, r2: Runnable) {}
|
||||
|
||||
fun usage(r1: Runnable) {
|
||||
test(r1, {})
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:+SamConversionPerArgument
|
||||
|
||||
fun interface KtRunnable {
|
||||
fun run()
|
||||
}
|
||||
|
||||
fun test(r1: KtRunnable, r2: KtRunnable) {}
|
||||
|
||||
fun usage(r1: KtRunnable) {
|
||||
test(r1, KtRunnable<caret> {})
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:+SamConversionPerArgument
|
||||
|
||||
fun interface KtRunnable {
|
||||
fun run()
|
||||
}
|
||||
|
||||
fun test(r1: KtRunnable, r2: KtRunnable) {}
|
||||
|
||||
fun usage(r1: KtRunnable) {
|
||||
test(r1, {})
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:+SamConversionPerArgument
|
||||
|
||||
fun test(r1: Runnable, r2: Runnable) {}
|
||||
|
||||
fun usage() {
|
||||
test(Runnable { return@Runnable }, Runnable<caret> {})
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion -XXLanguage:+SamConversionPerArgument
|
||||
|
||||
fun test(r1: Runnable, r2: Runnable) {}
|
||||
|
||||
fun usage() {
|
||||
test(Runnable { return@Runnable }, {})
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions
|
||||
// PROBLEM: none
|
||||
|
||||
fun <T> test(t: T): T = t
|
||||
|
||||
fun usage() {
|
||||
test(Runnable<caret> {})
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
interface Base {
|
||||
void test1();
|
||||
}
|
||||
|
||||
interface Extender extends Base {
|
||||
@java.lang.Override
|
||||
default void test1() { test2(); }
|
||||
|
||||
void test2();
|
||||
}
|
||||
|
||||
class Taker {
|
||||
static void take(Base b) {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun usage() {
|
||||
Taker.take(Extender<caret> {})
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion
|
||||
|
||||
fun interface KtRunnable {
|
||||
fun run()
|
||||
}
|
||||
|
||||
class Test {
|
||||
fun usage(r: KtRunnable) {}
|
||||
|
||||
fun test() {
|
||||
usage(KtRunnable<caret> { })
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions -XXLanguage:+FunctionalInterfaceConversion
|
||||
|
||||
fun interface KtRunnable {
|
||||
fun run()
|
||||
}
|
||||
|
||||
class Test {
|
||||
fun usage(r: KtRunnable) {}
|
||||
|
||||
fun test() {
|
||||
usage({ })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions
|
||||
|
||||
fun usage(r: Runnable) {}
|
||||
|
||||
fun test() {
|
||||
usage(Runnable<caret> { })
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+NewInference -XXLanguage:+SamConversionForKotlinFunctions
|
||||
|
||||
fun usage(r: Runnable) {}
|
||||
|
||||
fun test() {
|
||||
usage({ })
|
||||
}
|
||||
Reference in New Issue
Block a user