Internal Kotlin packages now should be completable in parent packages
Internal packages which are hard-excluded from completion and imports now should be visible there if file package are parent of excluded one e.g kotlin.jvm.internal.* now visible from kotlin and kotlin.jvm #KT-16214 fixed
This commit is contained in:
@@ -153,7 +153,8 @@ abstract class CompletionSession(
|
|||||||
searchScope,
|
searchScope,
|
||||||
filter,
|
filter,
|
||||||
filterOutPrivate = !mayIncludeInaccessible,
|
filterOutPrivate = !mayIncludeInaccessible,
|
||||||
declarationTranslator = { toFromOriginalFileMapper.toSyntheticFile(it) })
|
declarationTranslator = { toFromOriginalFileMapper.toSyntheticFile(it) },
|
||||||
|
file = file)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isVisibleDescriptor(descriptor: DeclarationDescriptor, completeNonAccessible: Boolean): Boolean {
|
private fun isVisibleDescriptor(descriptor: DeclarationDescriptor, completeNonAccessible: Boolean): Boolean {
|
||||||
@@ -169,7 +170,7 @@ abstract class CompletionSession(
|
|||||||
return completeNonAccessible && (!descriptor.isFromLibrary() || isDebuggerContext)
|
return completeNonAccessible && (!descriptor.isFromLibrary() || isDebuggerContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor.isExcludedFromAutoImport(project)) return false
|
if (descriptor.isExcludedFromAutoImport(project, file)) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package kotlin
|
||||||
|
|
||||||
|
fun some() {
|
||||||
|
kotlin.jvm.<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: internal
|
||||||
+6
@@ -2789,6 +2789,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("CompletionForExcludedWhenInternalUse.kt")
|
||||||
|
public void testCompletionForExcludedWhenInternalUse() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/java/CompletionForExcludedWhenInternalUse.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ExtensionFromStandardLibrary.kt")
|
@TestMetadata("ExtensionFromStandardLibrary.kt")
|
||||||
public void testExtensionFromStandardLibrary() throws Exception {
|
public void testExtensionFromStandardLibrary() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/java/ExtensionFromStandardLibrary.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/java/ExtensionFromStandardLibrary.kt");
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ class KotlinIndicesHelper(
|
|||||||
visibilityFilter: (DeclarationDescriptor) -> Boolean,
|
visibilityFilter: (DeclarationDescriptor) -> Boolean,
|
||||||
private val declarationTranslator: (KtDeclaration) -> KtDeclaration? = { it },
|
private val declarationTranslator: (KtDeclaration) -> KtDeclaration? = { it },
|
||||||
applyExcludeSettings: Boolean = true,
|
applyExcludeSettings: Boolean = true,
|
||||||
private val filterOutPrivate: Boolean = true
|
private val filterOutPrivate: Boolean = true,
|
||||||
|
private val file: KtFile? = null
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val moduleDescriptor = resolutionFacade.moduleDescriptor
|
private val moduleDescriptor = resolutionFacade.moduleDescriptor
|
||||||
@@ -68,7 +69,7 @@ class KotlinIndicesHelper(
|
|||||||
private val descriptorFilter: (DeclarationDescriptor) -> Boolean = filter@ {
|
private val descriptorFilter: (DeclarationDescriptor) -> Boolean = filter@ {
|
||||||
if (it.isHiddenInResolution(resolutionFacade.frontendService<LanguageVersionSettings>())) return@filter false
|
if (it.isHiddenInResolution(resolutionFacade.frontendService<LanguageVersionSettings>())) return@filter false
|
||||||
if (!visibilityFilter(it)) return@filter false
|
if (!visibilityFilter(it)) return@filter false
|
||||||
if (applyExcludeSettings && it.isExcludedFromAutoImport(project)) return@filter false
|
if (applyExcludeSettings && it.isExcludedFromAutoImport(project, file)) return@filter false
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.JavaProjectCodeInsightSettings
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
|
||||||
|
|
||||||
private val exclusions =
|
private val exclusions =
|
||||||
@@ -30,10 +31,12 @@ private val exclusions =
|
|||||||
"kotlin.reflect.jvm.internal"
|
"kotlin.reflect.jvm.internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun shouldBeHiddenAsInternalImplementationDetail(fqName: String) = exclusions.any { fqName.startsWith(it) }
|
private fun shouldBeHiddenAsInternalImplementationDetail(fqName: String, locationFqName: String) =
|
||||||
|
exclusions.any { fqName.startsWith(it) }
|
||||||
|
&& (locationFqName.isBlank() || !fqName.startsWith(locationFqName))
|
||||||
|
|
||||||
fun DeclarationDescriptor.isExcludedFromAutoImport(project: Project): Boolean {
|
fun DeclarationDescriptor.isExcludedFromAutoImport(project: Project, inFile: KtFile?): Boolean {
|
||||||
val fqName = importableFqName?.asString() ?: return false
|
val fqName = importableFqName?.asString() ?: return false
|
||||||
return JavaProjectCodeInsightSettings.getSettings(project).isExcluded(fqName) ||
|
return JavaProjectCodeInsightSettings.getSettings(project).isExcluded(fqName) ||
|
||||||
shouldBeHiddenAsInternalImplementationDetail(fqName)
|
shouldBeHiddenAsInternalImplementationDetail(fqName, inFile?.packageFqName?.asString() ?: "")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ internal abstract class ImportFixBase<T : KtExpression> protected constructor(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
val indicesHelper = KotlinIndicesHelper(resolutionFacade, searchScope, ::isVisible)
|
val indicesHelper = KotlinIndicesHelper(resolutionFacade, searchScope, ::isVisible, file = file)
|
||||||
|
|
||||||
var result = fillCandidates(nameStr, callTypeAndReceiver, bindingContext, indicesHelper)
|
var result = fillCandidates(nameStr, callTypeAndReceiver, bindingContext, indicesHelper)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// "Import" "true"
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// ACTION: Create local variable 'FunctionReference'
|
||||||
|
// ACTION: Create object 'FunctionReference'
|
||||||
|
// ACTION: Create parameter 'FunctionReference'
|
||||||
|
// ACTION: Create property 'FunctionReference'
|
||||||
|
// ACTION: Introduce local variable
|
||||||
|
// ACTION: Rename reference
|
||||||
|
|
||||||
|
package kotlin
|
||||||
|
|
||||||
|
fun some() {
|
||||||
|
FunctionReference<caret>::class
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
// "Import" "true"
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// ACTION: Create local variable 'FunctionReference'
|
||||||
|
// ACTION: Create object 'FunctionReference'
|
||||||
|
// ACTION: Create parameter 'FunctionReference'
|
||||||
|
// ACTION: Create property 'FunctionReference'
|
||||||
|
// ACTION: Introduce local variable
|
||||||
|
// ACTION: Rename reference
|
||||||
|
|
||||||
|
package kotlin
|
||||||
|
|
||||||
|
import kotlin.jvm.internal.FunctionReference
|
||||||
|
|
||||||
|
fun some() {
|
||||||
|
FunctionReference::class
|
||||||
|
}
|
||||||
@@ -824,6 +824,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("notExcludedFromImportWhenInternalUse.kt")
|
||||||
|
public void testNotExcludedFromImportWhenInternalUse() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/notExcludedFromImportWhenInternalUse.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("notForThisLabel.kt")
|
@TestMetadata("notForThisLabel.kt")
|
||||||
public void testNotForThisLabel() throws Exception {
|
public void testNotForThisLabel() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/notForThisLabel.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/notForThisLabel.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user