Supported excluded packages/classes in auto-import quick fix.
#KT-2413 in progress
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.core
|
package org.jetbrains.kotlin.idea.core
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.CodeInsightSettings
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import com.intellij.psi.stubs.StringStubIndexExtension
|
import com.intellij.psi.stubs.StringStubIndexExtension
|
||||||
@@ -198,3 +199,10 @@ public class KotlinIndicesHelper(
|
|||||||
.filter { it.getExtensionReceiverParameter() == null }
|
.filter { it.getExtensionReceiverParameter() == null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun isInExcludedPackage(descriptor: DeclarationDescriptor): Boolean {
|
||||||
|
val fqName = DescriptorUtils.getFqName(descriptor).asString()
|
||||||
|
|
||||||
|
return CodeInsightSettings.getInstance().EXCLUDED_PACKAGES
|
||||||
|
.any { excluded -> fqName == excluded || fqName.startsWith(excluded + ".") }
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.utils.CachedValueProperty
|
import org.jetbrains.kotlin.utils.CachedValueProperty
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
import com.intellij.codeInsight.*
|
||||||
|
import org.jetbrains.kotlin.idea.core.isInExcludedPackage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check possibility and perform fix for unresolved references.
|
* Check possibility and perform fix for unresolved references.
|
||||||
@@ -152,7 +154,7 @@ public class AutoImportFix(element: JetSimpleNameExpression) : JetHintAction<Jet
|
|||||||
|
|
||||||
result.addAll(indicesHelper.getCallableTopLevelExtensions({ it == referenceName }, element, bindingContext))
|
result.addAll(indicesHelper.getCallableTopLevelExtensions({ it == referenceName }, element, bindingContext))
|
||||||
|
|
||||||
return result
|
return result.filter { it -> !isInExcludedPackage(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getClasses(name: String, file: JetFile, searchScope: GlobalSearchScope): Collection<DeclarationDescriptor>
|
private fun getClasses(name: String, file: JetFile, searchScope: GlobalSearchScope): Collection<DeclarationDescriptor>
|
||||||
|
|||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false"
|
||||||
|
// ACTION: Create class 'SomeClass'
|
||||||
|
// ACTION: Create function 'SomeClass'
|
||||||
|
// ERROR: Unresolved reference: SomeClass
|
||||||
|
|
||||||
|
val x = <caret>SomeClass()
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package excludedPackage
|
||||||
|
|
||||||
|
class SomeClass
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false"
|
||||||
|
// ACTION: Create class 'ExcludedClass'
|
||||||
|
// ACTION: Create function 'ExcludedClass'
|
||||||
|
// ERROR: Unresolved reference: ExcludedClass
|
||||||
|
|
||||||
|
val x = <caret>ExcludedClass()
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package somePackage
|
||||||
|
|
||||||
|
class ExcludedClass
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false"
|
||||||
|
// ACTION: Create function 'someFunction'
|
||||||
|
// ERROR: Unresolved reference: someFunction
|
||||||
|
|
||||||
|
val x = <caret>someFunction()
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package excludedPackage
|
||||||
|
|
||||||
|
fun someFunction() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import somePackage.NotExcludedClass
|
||||||
|
|
||||||
|
// "Import" "true"
|
||||||
|
// ERROR: Unresolved reference: NotExcludedClass
|
||||||
|
|
||||||
|
val x = <caret>NotExcludedClass()
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Import" "true"
|
||||||
|
// ERROR: Unresolved reference: NotExcludedClass
|
||||||
|
|
||||||
|
val x = <caret>NotExcludedClass()
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package somePackage
|
||||||
|
|
||||||
|
class NotExcludedClass
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix;
|
package org.jetbrains.kotlin.idea.quickfix;
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.CodeInsightSettings;
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||||
import com.intellij.codeInsight.intention.IntentionAction;
|
import com.intellij.codeInsight.intention.IntentionAction;
|
||||||
@@ -67,6 +68,18 @@ public abstract class AbstractQuickFixMultiFileTest extends KotlinDaemonAnalyzer
|
|||||||
doTest(beforeFileName, true);
|
doTest(beforeFileName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = new String[]{"excludedPackage", "somePackage.ExcludedClass"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
CodeInsightSettings.getInstance().EXCLUDED_PACKAGES = ArrayUtil.EMPTY_STRING_ARRAY;
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
private void doTest(final String beforeFileName, boolean withExtraFile) throws Exception {
|
private void doTest(final String beforeFileName, boolean withExtraFile) throws Exception {
|
||||||
String testDataPath = getTestDataPath();
|
String testDataPath = getTestDataPath();
|
||||||
File mainFile = new File(testDataPath + beforeFileName);
|
File mainFile = new File(testDataPath + beforeFileName);
|
||||||
|
|||||||
@@ -185,6 +185,30 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
|||||||
doTestWithExtraFile(fileName);
|
doTestWithExtraFile(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noImportsForClassInExcludedPackage.before.Main.kt")
|
||||||
|
public void testNoImportsForClassInExcludedPackage() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/noImportsForClassInExcludedPackage.before.Main.kt");
|
||||||
|
doTestWithExtraFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noImportsForExcludedClass.before.Main.kt")
|
||||||
|
public void testNoImportsForExcludedClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/noImportsForExcludedClass.before.Main.kt");
|
||||||
|
doTestWithExtraFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noImportsForFunctionInExcludedPackage.before.Main.kt")
|
||||||
|
public void testNoImportsForFunctionInExcludedPackage() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/noImportsForFunctionInExcludedPackage.before.Main.kt");
|
||||||
|
doTestWithExtraFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("notExcludedClass.before.Main.kt")
|
||||||
|
public void testNotExcludedClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/notExcludedClass.before.Main.kt");
|
||||||
|
doTestWithExtraFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectImport.before.Main.kt")
|
@TestMetadata("objectImport.before.Main.kt")
|
||||||
public void testObjectImport() throws Exception {
|
public void testObjectImport() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/objectImport.before.Main.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/objectImport.before.Main.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user