Add intention to convert SAM lambda to anonymous object #KT-25718 Fixed
This commit is contained in:
committed by
Vyacheslav Gerasimov
parent
eedb69b5e4
commit
d06b04f025
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.SamConversionToAnonymousObjectIntention
|
||||
@@ -0,0 +1,3 @@
|
||||
public interface Sam {
|
||||
String test(Boolean b);
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
public interface Sam {
|
||||
String test(Boolean b);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
val s = Sam<caret> { b ->
|
||||
if (b) return@Sam "x"
|
||||
"y"
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
val s = object : Sam {
|
||||
override fun test(b: Boolean): String {
|
||||
if (b) return "x"
|
||||
return "y"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
// DISABLE-ERRORS
|
||||
interface I {
|
||||
fun test()
|
||||
}
|
||||
|
||||
val i = <caret>I {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public interface NotSam {
|
||||
void foo();
|
||||
void bar();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
// DISABLE-ERRORS
|
||||
val s = <caret>NotSam {
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
public interface Sam {
|
||||
void test(String a, Boolean b);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
// DISABLE-ERRORS
|
||||
val s = Sam<caret> {
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
public interface Sam {
|
||||
void test(String str);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
public interface Sam {
|
||||
void test(String str);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(s: String) {}
|
||||
|
||||
val s = <caret>Sam {
|
||||
foo(it)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(s: String) {}
|
||||
|
||||
val s = object : Sam {
|
||||
override fun test(it: String) {
|
||||
foo(it)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
public interface Sam {
|
||||
void test(String str);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
public interface Sam {
|
||||
void test(String str);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(s: String) {}
|
||||
|
||||
val s = <caret>Sam { s ->
|
||||
foo(s)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(s: String) {}
|
||||
|
||||
val s = object : Sam {
|
||||
override fun test(s: String) {
|
||||
foo(s)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface Sam {
|
||||
List<String> test(LocalDate date, LocalDateTime time);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface Sam {
|
||||
List<String> test(LocalDate date, LocalDateTime time);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// RUNTIME_WITH_FULL_JDK
|
||||
val s = Sam<caret> { d, t ->
|
||||
val s = "$d$t"
|
||||
listOf(s)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
|
||||
// RUNTIME_WITH_FULL_JDK
|
||||
val s = object : Sam {
|
||||
override fun test(d: LocalDate, t: LocalDateTime): List<String> {
|
||||
val s = "$d$t"
|
||||
return listOf(s)
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
public interface Sam {
|
||||
void test(String str);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test(s: String) {}
|
||||
|
||||
val usedSameFunction = <caret>Sam {
|
||||
test(it)
|
||||
}
|
||||
Reference in New Issue
Block a user