Skip to content

Commit 3bf7223

Browse files
committed
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
1 parent 27bf51c commit 3bf7223

File tree

9 files changed

+62
-8
lines changed

9 files changed

+62
-8
lines changed

idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ abstract class CompletionSession(
153153
searchScope,
154154
filter,
155155
filterOutPrivate = !mayIncludeInaccessible,
156-
declarationTranslator = { toFromOriginalFileMapper.toSyntheticFile(it) })
156+
declarationTranslator = { toFromOriginalFileMapper.toSyntheticFile(it) },
157+
file = file)
157158
}
158159

159160
private fun isVisibleDescriptor(descriptor: DeclarationDescriptor, completeNonAccessible: Boolean): Boolean {
@@ -169,7 +170,7 @@ abstract class CompletionSession(
169170
return completeNonAccessible && (!descriptor.isFromLibrary() || isDebuggerContext)
170171
}
171172

172-
if (descriptor.isExcludedFromAutoImport(project)) return false
173+
if (descriptor.isExcludedFromAutoImport(project, file)) return false
173174

174175
return true
175176
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package kotlin
2+
3+
fun some() {
4+
kotlin.jvm.<caret>
5+
}
6+
7+
// EXIST: internal

idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmBasicCompletionTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,6 +2789,12 @@ public void testAutoForceCompletion() throws Exception {
27892789
doTest(fileName);
27902790
}
27912791

2792+
@TestMetadata("CompletionForExcludedWhenInternalUse.kt")
2793+
public void testCompletionForExcludedWhenInternalUse() throws Exception {
2794+
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/java/CompletionForExcludedWhenInternalUse.kt");
2795+
doTest(fileName);
2796+
}
2797+
27922798
@TestMetadata("ExtensionFromStandardLibrary.kt")
27932799
public void testExtensionFromStandardLibrary() throws Exception {
27942800
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/java/ExtensionFromStandardLibrary.kt");

idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class KotlinIndicesHelper(
5858
visibilityFilter: (DeclarationDescriptor) -> Boolean,
5959
private val declarationTranslator: (KtDeclaration) -> KtDeclaration? = { it },
6060
applyExcludeSettings: Boolean = true,
61-
private val filterOutPrivate: Boolean = true
61+
private val filterOutPrivate: Boolean = true,
62+
private val file: KtFile? = null
6263
) {
6364

6465
private val moduleDescriptor = resolutionFacade.moduleDescriptor
@@ -68,7 +69,7 @@ class KotlinIndicesHelper(
6869
private val descriptorFilter: (DeclarationDescriptor) -> Boolean = filter@ {
6970
if (it.isHiddenInResolution(resolutionFacade.frontendService<LanguageVersionSettings>())) return@filter false
7071
if (!visibilityFilter(it)) return@filter false
71-
if (applyExcludeSettings && it.isExcludedFromAutoImport(project)) return@filter false
72+
if (applyExcludeSettings && it.isExcludedFromAutoImport(project, file)) return@filter false
7273
true
7374
}
7475

idea/idea-core/src/org/jetbrains/kotlin/idea/core/excludedFromImportsAndCompletion.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.JavaProjectCodeInsightSettings
2020
import com.intellij.openapi.project.Project
2121
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
2222
import org.jetbrains.kotlin.idea.imports.importableFqName
23+
import org.jetbrains.kotlin.psi.KtFile
2324

2425

2526
private val exclusions =
@@ -30,10 +31,12 @@ private val exclusions =
3031
"kotlin.reflect.jvm.internal"
3132
)
3233

33-
private fun shouldBeHiddenAsInternalImplementationDetail(fqName: String) = exclusions.any { fqName.startsWith(it) }
34+
private fun shouldBeHiddenAsInternalImplementationDetail(fqName: String, locationFqName: String) =
35+
exclusions.any { fqName.startsWith(it) }
36+
&& (locationFqName.isBlank() || !fqName.startsWith(locationFqName))
3437

35-
fun DeclarationDescriptor.isExcludedFromAutoImport(project: Project): Boolean {
38+
fun DeclarationDescriptor.isExcludedFromAutoImport(project: Project, inFile: KtFile?): Boolean {
3639
val fqName = importableFqName?.asString() ?: return false
3740
return JavaProjectCodeInsightSettings.getSettings(project).isExcluded(fqName) ||
38-
shouldBeHiddenAsInternalImplementationDetail(fqName)
41+
shouldBeHiddenAsInternalImplementationDetail(fqName, inFile?.packageFqName?.asString() ?: "")
3942
}

idea/src/org/jetbrains/kotlin/idea/quickfix/ImportFix.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ internal abstract class ImportFixBase<T : KtExpression> protected constructor(
175175
return true
176176
}
177177

178-
val indicesHelper = KotlinIndicesHelper(resolutionFacade, searchScope, ::isVisible)
178+
val indicesHelper = KotlinIndicesHelper(resolutionFacade, searchScope, ::isVisible, file = file)
179179

180180
var result = fillCandidates(nameStr, callTypeAndReceiver, bindingContext, indicesHelper)
181181

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// "Import" "true"
2+
// WITH_RUNTIME
3+
// ACTION: Create local variable 'FunctionReference'
4+
// ACTION: Create object 'FunctionReference'
5+
// ACTION: Create parameter 'FunctionReference'
6+
// ACTION: Create property 'FunctionReference'
7+
// ACTION: Introduce local variable
8+
// ACTION: Rename reference
9+
10+
package kotlin
11+
12+
fun some() {
13+
FunctionReference<caret>::class
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// "Import" "true"
2+
// WITH_RUNTIME
3+
// ACTION: Create local variable 'FunctionReference'
4+
// ACTION: Create object 'FunctionReference'
5+
// ACTION: Create parameter 'FunctionReference'
6+
// ACTION: Create property 'FunctionReference'
7+
// ACTION: Introduce local variable
8+
// ACTION: Rename reference
9+
10+
package kotlin
11+
12+
import kotlin.jvm.internal.FunctionReference
13+
14+
fun some() {
15+
FunctionReference::class
16+
}

idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,12 @@ public void testNoImportForIndex() throws Exception {
824824
doTest(fileName);
825825
}
826826

827+
@TestMetadata("notExcludedFromImportWhenInternalUse.kt")
828+
public void testNotExcludedFromImportWhenInternalUse() throws Exception {
829+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/notExcludedFromImportWhenInternalUse.kt");
830+
doTest(fileName);
831+
}
832+
827833
@TestMetadata("notForThisLabel.kt")
828834
public void testNotForThisLabel() throws Exception {
829835
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/notForThisLabel.kt");

0 commit comments

Comments
 (0)