Redundant Sam Constructor inspection
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package a;
|
||||
|
||||
public class A<T> {
|
||||
public void foo(JFunction1<T> r) {}
|
||||
|
||||
public static <T> JFunction1<T> expectedType(JFunction1<T> r) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package a;
|
||||
|
||||
public class GenericClass1 {
|
||||
public static <T> void staticFun1(JFunction1<T> r) {}
|
||||
public static <T> void staticFun2(JFunction1<T> r1, JFunction1<T> r2) {}
|
||||
public static <T> void staticFunWithOtherParam(int r1, JFunction1<T> r2) {}
|
||||
|
||||
public <T> void memberFun1(JFunction1<T> r) {}
|
||||
public <T> void memberFun2(JFunction1<T> r1, JFunction1<T> r2) {}
|
||||
public <T> void memberFunWithOtherParam(int r1, JFunction1<T> r2) {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package a;
|
||||
|
||||
public class GenericClass2 {
|
||||
public static <T> void staticFun1(JFunction0<T> r) {}
|
||||
public static <T> void staticFun2(JFunction0<T> r1, JFunction0<T> r2) {}
|
||||
public static <T> void staticFunWithOtherParam(int r1, JFunction0<T> r2) {}
|
||||
|
||||
public <T> void memberFun1(JFunction0<T> r) {}
|
||||
public <T> void memberFun2(JFunction0<T> r1, JFunction0<T> r2) {}
|
||||
public <T> void memberFunWithOtherParam(int r1, JFunction0<T> r2) {}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package a;
|
||||
|
||||
public class GenericClassCantBeReplaced {
|
||||
public static <T> void staticFun1(JFunction0<T> r) {}
|
||||
public static <T> void staticFun1(JFunction1<T> r) {}
|
||||
|
||||
public static <T> void staticFun2(JFunction0<T> r1, JFunction0<T> r2) {}
|
||||
public static <T> void staticFun2(JFunction1<T> r1, JFunction1<T> r2) {}
|
||||
|
||||
public <T> void memberFun1(JFunction0<T> r) {}
|
||||
public <T> void memberFun1(JFunction1<T> r) {}
|
||||
|
||||
public <T> void memberFun2(JFunction0<T> r1, JFunction0<T> r2) {}
|
||||
public <T> void memberFun2(JFunction1<T> r1, JFunction1<T> r2) {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package a;
|
||||
|
||||
public interface JFunction0<T> {
|
||||
T foo();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package a;
|
||||
|
||||
public interface JFunction1<T> {
|
||||
void foo(T t);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package a;
|
||||
|
||||
public class MyJavaClass {
|
||||
public static void staticFun1(Runnable r) {}
|
||||
public static void staticFun2(Runnable r1, Runnable r2) {}
|
||||
public static void staticFunWithOtherParam(int r1, Runnable r2) {}
|
||||
|
||||
public void memberFun1(Runnable r) {}
|
||||
public void memberFun2(Runnable r1, Runnable r2) {}
|
||||
public void memberFunWithOtherParam(int r1, Runnable r2) {}
|
||||
|
||||
public static <T> void foo1(Runnable r, T t) {}
|
||||
public static <T> void foo2(T t, Runnable r) {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
import a.A.*
|
||||
|
||||
fun testExpectedType() {
|
||||
val s1: JFunction1<String> = A.expectedType(JFunction1<String> { })
|
||||
val s2: JFunction1<String> = expectedType(JFunction1<String> { })
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>redundantSamConstructor.kt</file>
|
||||
<line>9</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructor.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructor.kt</file>
|
||||
<line>11</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructor.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WEAK_WARNING">Redundant SAM-constructors</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructor.kt</file>
|
||||
<line>22</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructor.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructor.kt</file>
|
||||
<line>25</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructor.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructor.kt</file>
|
||||
<line>27</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructor.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructor.kt</file>
|
||||
<line>38</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructor.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructorWithGenericsInReturnType.kt</file>
|
||||
<line>9</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructorWithGenericsInReturnType.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructorWithGenericsInReturnType.kt</file>
|
||||
<line>11</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructorWithGenericsInReturnType.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WEAK_WARNING">Redundant SAM-constructors</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructorWithGenericsInReturnType.kt</file>
|
||||
<line>15</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructorWithGenericsInReturnType.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructorWithGenericsInReturnType.kt</file>
|
||||
<line>18</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructorWithGenericsInReturnType.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructorWithGenericsInReturnType.kt</file>
|
||||
<line>20</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructorWithGenericsInReturnType.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>redundantSamConstructorWithGenericsInReturnType.kt</file>
|
||||
<line>24</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/redundantSamConstructorWithGenericsInReturnType.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>otherGenericsInParams.kt</file>
|
||||
<line>6</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/otherGenericsInParams.kt" />
|
||||
<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>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/otherGenericsInParams.kt" />
|
||||
<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>11</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/otherGenericsInParams.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM-constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>expectedType.kt</file>
|
||||
<line>7</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/expectedType.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>expectedType.kt</file>
|
||||
<line>8</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/expectedType.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant SAM constructor</problem_class>
|
||||
<description>Redundant SAM-constructor</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
import a.A.*
|
||||
|
||||
fun testExpectedType() {
|
||||
val s1: JFunction1<String> = A.expectedType({ })
|
||||
val s2: JFunction1<String> = expectedType({ })
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.RedundantSamConstructorInspection
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
|
||||
fun test() {
|
||||
MyJavaClass.foo1({ }, 1)
|
||||
MyJavaClass.foo1(Runnable { }, Runnable { })
|
||||
MyJavaClass.foo2(1, { })
|
||||
MyJavaClass.foo2(Runnable { }, Runnable { })
|
||||
|
||||
A<String>().foo({})
|
||||
}
|
||||
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
|
||||
fun test() {
|
||||
val runnable = Runnable { }
|
||||
val klass = MyJavaClass()
|
||||
|
||||
MyJavaClass.staticFun1({ })
|
||||
MyJavaClass.staticFun1(runnable)
|
||||
MyJavaClass.staticFun2({ }, { })
|
||||
MyJavaClass.staticFun2(runnable, Runnable { })
|
||||
MyJavaClass.staticFun2({ }, { })
|
||||
MyJavaClass.staticFun2(
|
||||
object: Runnable {
|
||||
override fun run() { }
|
||||
},
|
||||
object: Runnable {
|
||||
override fun run() { }
|
||||
})
|
||||
|
||||
MyJavaClass.staticFunWithOtherParam(1, { })
|
||||
MyJavaClass.staticFunWithOtherParam(1, runnable)
|
||||
|
||||
klass.memberFun1({ })
|
||||
klass.memberFun1(runnable)
|
||||
klass.memberFun2({ }, { })
|
||||
klass.memberFun2(runnable, Runnable { })
|
||||
klass.memberFun2({ }, { })
|
||||
klass.memberFun2(
|
||||
object: Runnable {
|
||||
override fun run() { }
|
||||
},
|
||||
object: Runnable {
|
||||
override fun run() { }
|
||||
})
|
||||
|
||||
klass.memberFunWithOtherParam(1, { })
|
||||
klass.memberFunWithOtherParam(1, runnable)
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
|
||||
fun testGenerics() {
|
||||
val runnable = JFunction1<String> { }
|
||||
val klass = GenericClass1()
|
||||
|
||||
GenericClass1.staticFun1(JFunction1<String> { })
|
||||
GenericClass1.staticFun1(runnable)
|
||||
GenericClass1.staticFun2(JFunction1<String> { }, JFunction1<String> { })
|
||||
GenericClass1.staticFun2(runnable, JFunction1<String> { })
|
||||
GenericClass1.staticFun2({ s: String -> }, { s: String -> })
|
||||
|
||||
GenericClass1.staticFunWithOtherParam(1, JFunction1<String> { })
|
||||
GenericClass1.staticFunWithOtherParam(1, runnable)
|
||||
|
||||
klass.memberFun1(JFunction1<String> { })
|
||||
klass.memberFun1(runnable)
|
||||
klass.memberFun2(JFunction1<String> { }, JFunction1<String> { })
|
||||
klass.memberFun2(runnable, JFunction1<String> { })
|
||||
klass.memberFun2({ s: String -> }, { s: String -> })
|
||||
|
||||
klass.memberFunWithOtherParam(1, JFunction1<String> { })
|
||||
klass.memberFunWithOtherParam(1, runnable)
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
|
||||
fun testGenericsReturnType() {
|
||||
val runnable = JFunction0 { "" }
|
||||
val klass = GenericClass2()
|
||||
|
||||
GenericClass2.staticFun1({ "" })
|
||||
GenericClass2.staticFun1(runnable)
|
||||
GenericClass2.staticFun2({ "" }, { "" })
|
||||
GenericClass2.staticFun2(runnable, JFunction0 { "" })
|
||||
GenericClass2.staticFun2({ -> "" }, { -> "" })
|
||||
|
||||
GenericClass2.staticFunWithOtherParam(1, { "" })
|
||||
GenericClass2.staticFunWithOtherParam(1, runnable)
|
||||
|
||||
klass.memberFun1({ "" })
|
||||
klass.memberFun1(runnable)
|
||||
klass.memberFun2({ "" }, { "" })
|
||||
klass.memberFun2(runnable, JFunction0 { "" })
|
||||
klass.memberFun2({ -> "" }, { -> "" })
|
||||
|
||||
klass.memberFunWithOtherParam(1, { "" })
|
||||
klass.memberFunWithOtherParam(1, runnable)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
|
||||
fun testNonApplicableAmbiguity() {
|
||||
GenericClassCantBeReplaced.staticFun1(JFunction0 { "" })
|
||||
GenericClassCantBeReplaced.staticFun2(JFunction0 { "" }, JFunction0 { "" })
|
||||
|
||||
val klass = GenericClassCantBeReplaced()
|
||||
klass.memberFun1(JFunction0 { "" })
|
||||
klass.memberFun2(JFunction0 { "" }, JFunction0 { "" })
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
|
||||
fun test() {
|
||||
MyJavaClass.foo1(Runnable { }, 1)
|
||||
MyJavaClass.foo1(Runnable { }, Runnable { })
|
||||
MyJavaClass.foo2(1, Runnable { })
|
||||
MyJavaClass.foo2(Runnable { }, Runnable { })
|
||||
|
||||
A<String>().foo(JFunction1<String> {})
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
|
||||
fun test() {
|
||||
val runnable = Runnable { }
|
||||
val klass = MyJavaClass()
|
||||
|
||||
MyJavaClass.staticFun1(Runnable { })
|
||||
MyJavaClass.staticFun1(runnable)
|
||||
MyJavaClass.staticFun2(Runnable { }, Runnable { })
|
||||
MyJavaClass.staticFun2(runnable, Runnable { })
|
||||
MyJavaClass.staticFun2({ }, { })
|
||||
MyJavaClass.staticFun2(
|
||||
object: Runnable {
|
||||
override fun run() { }
|
||||
},
|
||||
object: Runnable {
|
||||
override fun run() { }
|
||||
})
|
||||
|
||||
MyJavaClass.staticFunWithOtherParam(1, Runnable { })
|
||||
MyJavaClass.staticFunWithOtherParam(1, runnable)
|
||||
|
||||
klass.memberFun1(Runnable { })
|
||||
klass.memberFun1(runnable)
|
||||
klass.memberFun2(Runnable { }, Runnable { })
|
||||
klass.memberFun2(runnable, Runnable { })
|
||||
klass.memberFun2({ }, { })
|
||||
klass.memberFun2(
|
||||
object: Runnable {
|
||||
override fun run() { }
|
||||
},
|
||||
object: Runnable {
|
||||
override fun run() { }
|
||||
})
|
||||
|
||||
klass.memberFunWithOtherParam(1, Runnable { })
|
||||
klass.memberFunWithOtherParam(1, runnable)
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
|
||||
fun testGenerics() {
|
||||
val runnable = JFunction1<String> { }
|
||||
val klass = GenericClass1()
|
||||
|
||||
GenericClass1.staticFun1(JFunction1<String> { })
|
||||
GenericClass1.staticFun1(runnable)
|
||||
GenericClass1.staticFun2(JFunction1<String> { }, JFunction1<String> { })
|
||||
GenericClass1.staticFun2(runnable, JFunction1<String> { })
|
||||
GenericClass1.staticFun2({ s: String -> }, { s: String -> })
|
||||
|
||||
GenericClass1.staticFunWithOtherParam(1, JFunction1<String> { })
|
||||
GenericClass1.staticFunWithOtherParam(1, runnable)
|
||||
|
||||
klass.memberFun1(JFunction1<String> { })
|
||||
klass.memberFun1(runnable)
|
||||
klass.memberFun2(JFunction1<String> { }, JFunction1<String> { })
|
||||
klass.memberFun2(runnable, JFunction1<String> { })
|
||||
klass.memberFun2({ s: String -> }, { s: String -> })
|
||||
|
||||
klass.memberFunWithOtherParam(1, JFunction1<String> { })
|
||||
klass.memberFunWithOtherParam(1, runnable)
|
||||
}
|
||||
idea/testData/inspections/redundantSamConstructor/redundantSamConstructorWithGenericsInReturnType.kt
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
package redundantSamConstructor
|
||||
|
||||
import a.*
|
||||
|
||||
fun testGenericsReturnType() {
|
||||
val runnable = JFunction0 { "" }
|
||||
val klass = GenericClass2()
|
||||
|
||||
GenericClass2.staticFun1(JFunction0 { "" })
|
||||
GenericClass2.staticFun1(runnable)
|
||||
GenericClass2.staticFun2(JFunction0 { "" }, JFunction0 { "" })
|
||||
GenericClass2.staticFun2(runnable, JFunction0 { "" })
|
||||
GenericClass2.staticFun2({ -> "" }, { -> "" })
|
||||
|
||||
GenericClass2.staticFunWithOtherParam(1, JFunction0 { "" })
|
||||
GenericClass2.staticFunWithOtherParam(1, runnable)
|
||||
|
||||
klass.memberFun1(JFunction0 { "" })
|
||||
klass.memberFun1(runnable)
|
||||
klass.memberFun2(JFunction0 { "" }, JFunction0 { "" })
|
||||
klass.memberFun2(runnable, JFunction0 { "" })
|
||||
klass.memberFun2({ -> "" }, { -> "" })
|
||||
|
||||
klass.memberFunWithOtherParam(1, JFunction0 { "" })
|
||||
klass.memberFunWithOtherParam(1, runnable)
|
||||
}
|
||||
Reference in New Issue
Block a user