KT-11308 Hide kotlin.jvm.internal package contents from completion and auto-import
#KT-11308 fixed
This commit is contained in:
@@ -158,7 +158,7 @@ abstract class CompletionSession(
|
||||
|
||||
private fun isVisibleDescriptor(descriptor: DeclarationDescriptor, completeNonAccessible: Boolean): Boolean {
|
||||
if (!configuration.javaClassesNotToBeUsed && descriptor is ClassDescriptor) {
|
||||
if (descriptor.importableFqName?.let { isJavaClassNotToBeUsedInKotlin(it) } == true) return false
|
||||
if (descriptor.importableFqName?.let(::isJavaClassNotToBeUsedInKotlin) == true) return false
|
||||
}
|
||||
|
||||
if (descriptor is TypeParameterDescriptor && !isTypeParameterVisible(descriptor)) return false
|
||||
@@ -169,6 +169,8 @@ abstract class CompletionSession(
|
||||
return completeNonAccessible && (!descriptor.isFromLibrary() || isDebuggerContext)
|
||||
}
|
||||
|
||||
if (descriptor.isExcludedFromAutoImport(project)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun some() {
|
||||
kotlin.jvm.<caret>
|
||||
}
|
||||
|
||||
// ABSENT: internal
|
||||
+6
@@ -572,6 +572,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoCompletionForExcluded.kt")
|
||||
public void testNoCompletionForExcluded() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/NoCompletionForExcluded.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoEmptyPackage.kt")
|
||||
public void testNoEmptyPackage() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/NoEmptyPackage.kt");
|
||||
|
||||
+6
@@ -572,6 +572,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoCompletionForExcluded.kt")
|
||||
public void testNoCompletionForExcluded() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/NoCompletionForExcluded.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NoEmptyPackage.kt")
|
||||
public void testNoEmptyPackage() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/NoEmptyPackage.kt");
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.core
|
||||
|
||||
import com.intellij.codeInsight.JavaProjectCodeInsightSettings
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiMember
|
||||
@@ -32,7 +31,6 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.caches.KotlinShortNamesCache
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.*
|
||||
import org.jetbrains.kotlin.idea.core.extension.KotlinIndicesHelperExtension
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.search.excludeKotlinSources
|
||||
@@ -73,7 +71,7 @@ class KotlinIndicesHelper(
|
||||
private val descriptorFilter: (DeclarationDescriptor) -> Boolean = filter@ {
|
||||
if (it.isHiddenInResolution(resolutionFacade.frontendService<LanguageVersionSettings>())) return@filter false
|
||||
if (!visibilityFilter(it)) return@filter false
|
||||
if (applyExcludeSettings && isExcludedFromAutoImport(it)) return@filter false
|
||||
if (applyExcludeSettings && it.isExcludedFromAutoImport(project)) return@filter false
|
||||
true
|
||||
}
|
||||
|
||||
@@ -429,11 +427,6 @@ class KotlinIndicesHelper(
|
||||
}
|
||||
}
|
||||
|
||||
private fun isExcludedFromAutoImport(descriptor: DeclarationDescriptor): Boolean {
|
||||
val fqName = descriptor.importableFqName?.asString() ?: return false
|
||||
return JavaProjectCodeInsightSettings.getSettings(project).isExcluded(fqName)
|
||||
}
|
||||
|
||||
private inline fun <reified TDescriptor : Any> KtNamedDeclaration.resolveToDescriptors(): Collection<TDescriptor> {
|
||||
return resolveToDescriptorsWithHack({ true }).filterIsInstance<TDescriptor>()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.core
|
||||
|
||||
import com.intellij.codeInsight.JavaProjectCodeInsightSettings
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
|
||||
|
||||
private val exclusions =
|
||||
listOf(
|
||||
"kotlin.jvm.internal",
|
||||
"kotlin.coroutines.intrinsics"
|
||||
)
|
||||
|
||||
private fun shouldBeHiddenAsInternalImplementationDetail(fqName: String) = exclusions.any { fqName.startsWith(it) }
|
||||
|
||||
fun DeclarationDescriptor.isExcludedFromAutoImport(project: Project): Boolean {
|
||||
val fqName = importableFqName?.asString() ?: return false
|
||||
return JavaProjectCodeInsightSettings.getSettings(project).isExcluded(fqName) ||
|
||||
shouldBeHiddenAsInternalImplementationDetail(fqName)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Import" "false"
|
||||
// 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
|
||||
// ERROR: Unresolved reference: FunctionReference
|
||||
|
||||
fun some() {
|
||||
FunctionReference<caret>::class
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Import" "false"
|
||||
// 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
|
||||
// ERROR: Unresolved reference: FunctionReference
|
||||
|
||||
fun some() {
|
||||
FunctionReference<caret>::class
|
||||
}
|
||||
@@ -734,6 +734,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("excludedFromImport.kt")
|
||||
public void testExcludedFromImport() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/excludedFromImport.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("infixCallAndObject.kt")
|
||||
public void testInfixCallAndObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/infixCallAndObject.kt");
|
||||
|
||||
Reference in New Issue
Block a user