[java-refactoring] IDEA-71792 Support inlining of abstract methods having one implementation

GitOrigin-RevId: 00491acff53aff96705a866e0d799dfe22873d23
This commit is contained in:
Tagir Valeev
2024-10-10 16:22:04 +02:00
committed by intellij-monorepo-bot
parent ce73510eb1
commit 09bd11efd8
12 changed files with 284 additions and 116 deletions

View File

@@ -0,0 +1,18 @@
import java.util.List;
public class InlineSingleImplementation {
interface MyIface<T> {
void mySimpleMethod();
}
static class MyIfaceImpl<E extends CharSequence> implements MyIface<E> {
@Override
public void mySimpleMethod() {
System.out.println("Impl");
}
}
void test(MyIface<String> iface) {
iface.<caret>mySimpleMethod();
}
}

View File

@@ -0,0 +1,16 @@
public class InlineSingleImplementation {
interface MyIface<T> {
void mySimpleMethod();
}
static class MyIfaceImpl<E extends CharSequence> implements MyIface<E> {
@Override
public void mySimpleMethod() {
System.out.println("Impl");
}
}
void test(MyIface<String> iface) {
System.out.println("Impl");
}
}

View File

@@ -0,0 +1,19 @@
import java.util.List;
public class InlineSingleImplementation {
interface MyIface<T> {
void myUseGenericMethod(T t);
}
static class MyIfaceImpl<E extends CharSequence> implements MyIface<E> {
@Override
public void myUseGenericMethod(E e) {
E e1 = e;
System.out.println("Impl: " + e);
}
}
void test(MyIface<String> iface) {
iface.<caret>myUseGenericMethod("hello");
}
}

View File

@@ -0,0 +1,18 @@
public class InlineSingleImplementation {
interface MyIface<T> {
void myUseGenericMethod(T t);
}
static class MyIfaceImpl<E extends CharSequence> implements MyIface<E> {
@Override
public void myUseGenericMethod(E e) {
E e1 = e;
System.out.println("Impl: " + e);
}
}
void test(MyIface<String> iface) {
String e1 = "hello";
System.out.println("Impl: " + "hello");
}
}

View File

@@ -0,0 +1,22 @@
import java.util.List;
public class InlineSingleImplementation {
interface MyIface<T> {
<M> M myGenericMethod(M m, T t);
}
static class MyIfaceImpl<E extends CharSequence> implements MyIface<E> {
@Override
public <M1> M1 myGenericMethod(M1 m, E e) {
M1 m1 = m;
E e1 = e;
if (m == null) return null;
System.out.println("Impl: " + m1 + " : " + e);
return m;
}
}
void test(MyIface<String> iface) {
int x = iface.<caret>myGenericMethod(123, "hello");
}
}

View File

@@ -0,0 +1,27 @@
public class InlineSingleImplementation {
interface MyIface<T> {
<M> M myGenericMethod(M m, T t);
}
static class MyIfaceImpl<E extends CharSequence> implements MyIface<E> {
@Override
public <M1> M1 myGenericMethod(M1 m, E e) {
M1 m1 = m;
E e1 = e;
if (m == null) return null;
System.out.println("Impl: " + m1 + " : " + e);
return m;
}
}
void test(MyIface<String> iface) {
Integer result = null;
Integer m1 = 123;
String e1 = "hello";
if ((Integer) 123 != null) {
System.out.println("Impl: " + m1 + " : " + "hello");
result = 123;
}
int x = result;
}
}