mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix onDemand check for classes resolved to default imports like 'java.lang' (IDEA-141782)
This commit is contained in:
@@ -412,7 +412,7 @@ public class ImportHelper{
|
||||
useOnDemand = false;
|
||||
}
|
||||
// name of class we try to import is the same as of the class defined in this file
|
||||
if (curRefClass != null) {
|
||||
if (containsInCurrentFile(file, curRefClass)) {
|
||||
useOnDemand = true;
|
||||
}
|
||||
// check conflicts
|
||||
@@ -428,10 +428,9 @@ public class ImportHelper{
|
||||
}
|
||||
|
||||
if (useOnDemand &&
|
||||
curRefClass != null &&
|
||||
refClass.getContainingClass() != null &&
|
||||
mySettings.INSERT_INNER_CLASS_IMPORTS &&
|
||||
"java.lang".equals(StringUtil.getPackageName(curRefClass.getQualifiedName()))) {
|
||||
containsInCurrentFile(file, curRefClass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -465,6 +464,17 @@ public class ImportHelper{
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean containsInCurrentFile(@NotNull PsiJavaFile file, PsiClass curRefClass) {
|
||||
if (curRefClass != null) {
|
||||
final String curRefClassQualifiedName = curRefClass.getQualifiedName();
|
||||
if (curRefClassQualifiedName != null &&
|
||||
ArrayUtil.find(file.getImplicitlyImportedPackages(), StringUtil.getPackageName(curRefClassQualifiedName)) < 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void calcClassesToReimport(PsiJavaFile file, JavaPsiFacade facade, PsiResolveHelper helper, String packageName, List<PsiClass> classesToReimport,
|
||||
Collection<String> onDemandRefs) {
|
||||
if (onDemandRefs.isEmpty()) {
|
||||
|
||||
+4
-1
@@ -17,8 +17,11 @@ package com.intellij.codeInsight.intention
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.psi.impl.source.codeStyle.ImportHelper
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
|
||||
@@ -74,7 +77,7 @@ public class Foo {
|
||||
}
|
||||
'''
|
||||
importClass()
|
||||
myFixture.checkResult '''import foo.*;
|
||||
myFixture.checkResult '''import foo.StringValue;
|
||||
|
||||
public class Foo {
|
||||
String<caret>Value sv;
|
||||
|
||||
Reference in New Issue
Block a user