diff --git a/java/java-tests/testData/ipp/com/siyeh/ipp/interfaceToClass/InheritorWarnings.java b/java/java-tests/testData/ipp/com/siyeh/ipp/interfaceToClass/InheritorWarnings.java new file mode 100644 index 000000000000..f7304fe0e375 --- /dev/null +++ b/java/java-tests/testData/ipp/com/siyeh/ipp/interfaceToClass/InheritorWarnings.java @@ -0,0 +1,24 @@ +interface Probable {} +interface Something extends Probable { + void run(); +} +class AX { + void x() { + Something s = () -> {}; + } +} +interface SomethingSub extends Something {} +record SomethingElse() implements Something { + @Override + public void run() { + + } +} +enum SomethingEnum implements Something { + ; + + @Override + public void run() { + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/ipp/com/siyeh/ipp/interfaceToClass/InheritorWarnings_after.java b/java/java-tests/testData/ipp/com/siyeh/ipp/interfaceToClass/InheritorWarnings_after.java new file mode 100644 index 000000000000..50592982583b --- /dev/null +++ b/java/java-tests/testData/ipp/com/siyeh/ipp/interfaceToClass/InheritorWarnings_after.java @@ -0,0 +1,24 @@ +interface Probable {} +abstract static class Something implements Probable { + public abstract void run(); +} +class AX { + void x() { + Something s = () -> {}; + } +} +interface SomethingSub extends Something {} +record SomethingElse() implements Something { + @Override + public void run() { + + } +} +enum SomethingEnum extends Something { + ; + + @Override + public void run() { + + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/siyeh/ipp/interfacetoclass/ConvertInterfaceToClassTest.java b/java/java-tests/testSrc/com/siyeh/ipp/interfacetoclass/ConvertInterfaceToClassTest.java index 06dfd82f3b84..653eed4ed1d6 100644 --- a/java/java-tests/testSrc/com/siyeh/ipp/interfacetoclass/ConvertInterfaceToClassTest.java +++ b/java/java-tests/testSrc/com/siyeh/ipp/interfacetoclass/ConvertInterfaceToClassTest.java @@ -8,7 +8,7 @@ import com.siyeh.IntentionPowerPackBundle; import com.siyeh.ipp.IPPTestCase; import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.Set; public class ConvertInterfaceToClassTest extends IPPTestCase { public void testBasic() { doTest(); } @@ -20,17 +20,27 @@ public class ConvertInterfaceToClassTest extends IPPTestCase { public void testFunctionalExpressions() { UiInterceptors.register(new ConflictInterceptor( - List.of("() -> {...} in Test will not compile after converting interface FunctionalExpressions to a class"))); + Set.of("() -> {...} in Test will not compile after converting interface FunctionalExpressions to a class"))); doTest(); } public void testExtendsConflict() { UiInterceptors.register(new ConflictInterceptor( - List.of("class AaaImpl implementing interface Aaa already extends class " + + Set.of("class AaaImpl implementing interface Aaa already extends class " + "Bbb and will not compile after converting interface Aaa to a class"))); doTest(); } + public void testInheritorWarnings() { + UiInterceptors.register(new ConflictInterceptor( + Set.of( + "() -> {...} in x() in InheritorWarnings.AX will not compile after converting interface InheritorWarnings.Something to a class", + "enum InheritorWarnings.SomethingEnum implementing interface InheritorWarnings.Something will not compile after converting interface InheritorWarnings.Something to a class", + "interface InheritorWarnings.SomethingSub implementing interface InheritorWarnings.Something will not compile after converting interface InheritorWarnings.Something to a class" + ))); + doTest(); + } + public void testFunctionalInterface() { assertIntentionNotAvailable(); } diff --git a/platform/lang-impl/src/com/intellij/refactoring/ui/ConflictsDialog.java b/platform/lang-impl/src/com/intellij/refactoring/ui/ConflictsDialog.java index f796c70c355c..c9a203124beb 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/ui/ConflictsDialog.java +++ b/platform/lang-impl/src/com/intellij/refactoring/ui/ConflictsDialog.java @@ -1,5 +1,4 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. - package com.intellij.refactoring.ui; import com.intellij.codeInsight.highlighting.ReadWriteAccessDetector; @@ -33,7 +32,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.util.ArrayList; import java.util.LinkedHashSet; -import java.util.List; +import java.util.Set; import java.util.regex.Pattern; public class ConflictsDialog extends DialogWrapper implements ConflictsDialogBase { @@ -91,8 +90,8 @@ public class ConflictsDialog extends DialogWrapper implements ConflictsDialogBas init(); } - public List getConflictDescriptions() { - return List.of(myConflictDescriptions); + public Set getConflictDescriptions() { + return Set.of(myConflictDescriptions); } @Override diff --git a/platform/testFramework/src/com/intellij/ui/ConflictInterceptor.java b/platform/testFramework/src/com/intellij/ui/ConflictInterceptor.java index f213fbb50287..e9559511cfab 100644 --- a/platform/testFramework/src/com/intellij/ui/ConflictInterceptor.java +++ b/platform/testFramework/src/com/intellij/ui/ConflictInterceptor.java @@ -4,7 +4,7 @@ package com.intellij.ui; import com.intellij.refactoring.ui.ConflictsDialog; import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.Set; import static org.junit.Assert.assertEquals; @@ -12,12 +12,12 @@ import static org.junit.Assert.assertEquals; * An interceptor that expects a conflict dialog. An interceptor assumes that "Continue" button will be pressed */ public class ConflictInterceptor extends UiInterceptors.UiInterceptor { - private final List myConflicts; + private final Set myConflicts; /** * @param expectedConflicts list of expected conflicts */ - public ConflictInterceptor(List expectedConflicts) { + public ConflictInterceptor(Set expectedConflicts) { super(ConflictsDialog.class); myConflicts = expectedConflicts; }