REPL: Fix completion for protected members
This commit is contained in:
+33
@@ -442,6 +442,39 @@ class ReplCompletionAndErrorsAnalysisTest : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testProtectedInheritedMemberCompletion() = test {
|
||||
run {
|
||||
code = """
|
||||
open class Base {
|
||||
private val xyz1: Float = 7.0f
|
||||
protected val xyz2: Int = 42
|
||||
internal val xyz3: String = ""
|
||||
public val xyz4: Byte = 8
|
||||
}
|
||||
""".trimIndent()
|
||||
doCompile
|
||||
}
|
||||
|
||||
run {
|
||||
val definition = "val c = x"
|
||||
code = """
|
||||
object : Base() {
|
||||
fun g() {
|
||||
$definition
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
cursor = code.indexOf(definition) + definition.length
|
||||
|
||||
expect {
|
||||
addCompletion("xyz2", "xyz2", "Int", "property")
|
||||
addCompletion("xyz3", "xyz3", "String", "property")
|
||||
addCompletion("xyz4", "xyz4", "Byte", "property")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Should be fixed by KT-39314")
|
||||
@Test
|
||||
fun ignore_testDefaultImportsNotFirst() = test {
|
||||
|
||||
+9
-2
@@ -14,6 +14,8 @@ import java.util.concurrent.atomic.AtomicInteger
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.KProperty0
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.jvm.impl.KJvmCompiledScript
|
||||
import kotlin.script.experimental.util.LinkedSnippet
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
class TestConf {
|
||||
@@ -249,8 +251,13 @@ private suspend fun evaluateInRepl(
|
||||
|
||||
if (doCompile) {
|
||||
val codeLineForCompilation = nextCodeLine(code, lineCounter)
|
||||
|
||||
val timeMillis = measureTimeMillis { compiler.compile(codeLineForCompilation, newCompilationConfiguration) }
|
||||
val compilationResult: ResultWithDiagnostics<LinkedSnippet<KJvmCompiledScript>>
|
||||
val timeMillis = measureTimeMillis {
|
||||
compilationResult = compiler.compile(codeLineForCompilation, newCompilationConfiguration)
|
||||
}
|
||||
if (compilationResult is ResultWithDiagnostics.Failure) {
|
||||
System.err.println(compilationResult.reports.joinToString("\n", "Compilation failed:\n") { it.toString() })
|
||||
}
|
||||
|
||||
loggingInfo?.compile?.writeValue(timeMillis)
|
||||
}
|
||||
|
||||
+8
-2
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities.ALWAYS_SUITABLE_RECEIVER
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
@@ -370,11 +371,16 @@ private class KJvmReplCompleter(
|
||||
private val inDescriptor: DeclarationDescriptor
|
||||
) : (DeclarationDescriptor) -> Boolean {
|
||||
override fun invoke(descriptor: DeclarationDescriptor): Boolean {
|
||||
if (descriptor is TypeParameterDescriptor && !isTypeParameterVisible(descriptor)) return false
|
||||
if (descriptor is TypeParameterDescriptor) return isTypeParameterVisible(descriptor)
|
||||
|
||||
if (descriptor is DeclarationDescriptorWithVisibility) {
|
||||
return try {
|
||||
descriptor.visibility.isVisible(null, descriptor, inDescriptor, useSpecialRulesForPrivateSealedConstructors = true)
|
||||
descriptor.visibility.isVisible(
|
||||
ALWAYS_SUITABLE_RECEIVER,
|
||||
descriptor,
|
||||
inDescriptor,
|
||||
useSpecialRulesForPrivateSealedConstructors = true,
|
||||
)
|
||||
} catch (e: IllegalStateException) {
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user