From b4c155f5defc46e464162575dbaf3af3d6f68ade Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 21 Oct 2024 09:29:17 +0200 Subject: [PATCH] Java: allow importing a class when there is a variable/method with the exact same name (IDEA-216101) GitOrigin-RevId: e4c5b86ce2f4910711e33581c58d271dadbf6970 --- .../impl/quickfix/ImportClassFixBase.java | 2 +- .../codeStyle/JavaReferenceAdjuster.java | 2 +- .../correctConstantPosition_after.java | 2 +- .../intention/AddImportActionTest.java | 20 +++++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java index 03f5c0e44318..171e2a83a488 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ImportClassFixBase.java @@ -145,7 +145,7 @@ public abstract class ImportClassFixBase R = new R<>() { + public static final R R = new R<>() { final String param = ""; @Override diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/AddImportActionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/AddImportActionTest.java index 79a953462ef1..5f5fa6a4b7da 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/AddImportActionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/intention/AddImportActionTest.java @@ -76,6 +76,26 @@ public class AddImportActionTest extends LightJavaCodeInsightFixtureTestCase { """); } + public void testClassNameResolvesToVariableName() { + myFixture.configureByText(JavaFileType.INSTANCE, """ + public class Base { + private URL URL; + + protected void test(URL url) { + } + }"""); + importClass(); + myFixture.checkResult(""" + import java.net.URL; + + public class Base { + private URL URL; + + protected void test(URL url) { + } + }"""); + } + public void testMethodReference() { myFixture.configureByText(JavaFileType.INSTANCE, """ public class Importing {