mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspection] IDEA-382937 "Static import can be used" leads to compile error due to conflict with interface method
GitOrigin-RevId: d1e2afc5c36577deead95a4252fbbaf7aed46799
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d9abd8f060
commit
f9a382a2a5
+10
-2
@@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -81,8 +82,15 @@ public final class AddOnDemandStaticImportAction extends PsiUpdateModCommandActi
|
||||
final PsiElement qualifier = call.getMethodExpression().getQualifier();
|
||||
if (qualifier == null) return null;
|
||||
qualifier.delete();
|
||||
final PsiMethod method = call.resolveMethod();
|
||||
if (method != null && method.getContainingClass() != psiClass) return null;
|
||||
JavaResolveResult[] results = call.multiResolve(false);
|
||||
if (Arrays.stream(results)
|
||||
.filter(Objects::nonNull)
|
||||
.map(ResolveResult::getElement)
|
||||
.anyMatch(psiElement ->
|
||||
psiElement instanceof PsiMethod psiMethod &&
|
||||
psiMethod.getContainingClass() != psiClass)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PsiElement refNameElement = parentRef.getReferenceNameElement();
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package staticImportCanBeUsed;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
final class ExampleImpls {
|
||||
|
||||
record ExampleImpl(String translationKey) implements Example {
|
||||
|
||||
@Override
|
||||
public String localize(Locale locale) {
|
||||
return StaticMethod.localize(locale, translationKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -303,6 +303,34 @@ public class StaticImportCanBeUsedInspectionTest extends LightJavaInspectionTest
|
||||
}
|
||||
}
|
||||
|
||||
public void testDoubleTheSameMethod() {
|
||||
try {
|
||||
myFixture.addClass("""
|
||||
package staticImportCanBeUsed;
|
||||
import java.util.Locale;
|
||||
public interface Example {
|
||||
default String localize() {
|
||||
return localize(Locale.getDefault());
|
||||
}
|
||||
String localize(Locale locale);
|
||||
}""");
|
||||
|
||||
myFixture.addClass("""
|
||||
package staticImportCanBeUsed;
|
||||
import java.util.Locale;
|
||||
public class StaticMethod {
|
||||
public static String localize(Locale locale, String translationKey) {
|
||||
return translationKey;
|
||||
}
|
||||
}""");
|
||||
addStaticAutoImportToProject("staticImportCanBeUsed.StaticMethod.localize");
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
cleanTable();
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanupTest() {
|
||||
IntentionAction intention = myFixture.getAvailableIntention(AnalysisBundle.message("cleanup.in.file"));
|
||||
myFixture.launchAction(intention);
|
||||
|
||||
Reference in New Issue
Block a user