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:
Simon Ogorodnik
2017-03-03 16:11:21 +03:00
parent 27bf51c73f
commit 3bf7223448
9 changed files with 62 additions and 8 deletions
@@ -153,7 +153,8 @@ abstract class CompletionSession(
searchScope,
filter,
filterOutPrivate = !mayIncludeInaccessible,
declarationTranslator = { toFromOriginalFileMapper.toSyntheticFile(it) })
declarationTranslator = { toFromOriginalFileMapper.toSyntheticFile(it) },
file = file)
}
private fun isVisibleDescriptor(descriptor: DeclarationDescriptor, completeNonAccessible: Boolean): Boolean {
@@ -169,7 +170,7 @@ abstract class CompletionSession(
return completeNonAccessible && (!descriptor.isFromLibrary() || isDebuggerContext)
}
if (descriptor.isExcludedFromAutoImport(project)) return false
if (descriptor.isExcludedFromAutoImport(project, file)) return false
return true
}
@@ -0,0 +1,7 @@
package kotlin
fun some() {
kotlin.jvm.<caret>
}
// EXIST: internal
@@ -2789,6 +2789,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
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")
public void testExtensionFromStandardLibrary() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/java/ExtensionFromStandardLibrary.kt");
@@ -58,7 +58,8 @@ class KotlinIndicesHelper(
visibilityFilter: (DeclarationDescriptor) -> Boolean,
private val declarationTranslator: (KtDeclaration) -> KtDeclaration? = { it },
applyExcludeSettings: Boolean = true,
private val filterOutPrivate: Boolean = true
private val filterOutPrivate: Boolean = true,
private val file: KtFile? = null
) {
private val moduleDescriptor = resolutionFacade.moduleDescriptor
@@ -68,7 +69,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 && it.isExcludedFromAutoImport(project)) return@filter false
if (applyExcludeSettings && it.isExcludedFromAutoImport(project, file)) return@filter false
true
}
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.JavaProjectCodeInsightSettings
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.psi.KtFile
private val exclusions =
@@ -30,10 +31,12 @@ private val exclusions =
"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
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
}
val indicesHelper = KotlinIndicesHelper(resolutionFacade, searchScope, ::isVisible)
val indicesHelper = KotlinIndicesHelper(resolutionFacade, searchScope, ::isVisible, file = file)
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
}
@@ -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);
}
@TestMetadata("notExcludedFromImportWhenInternalUse.kt")
public void testNotExcludedFromImportWhenInternalUse() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/notExcludedFromImportWhenInternalUse.kt");
doTest(fileName);
}
@TestMetadata("notForThisLabel.kt")
public void testNotForThisLabel() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/notForThisLabel.kt");