[LL FIR] getSelectedElement should return PsiElement

^KT-60518
This commit is contained in:
Dmitrii Gridin
2023-07-18 15:23:00 +02:00
committed by Space Team
parent 5f1e2764c3
commit c2fd245ca1
4 changed files with 8 additions and 9 deletions
@@ -124,14 +124,13 @@ class ExpressionMarkerProvider : TestService {
}
fun getSelectedElement(file: KtFile): KtElement {
val range = selected[file.name]
?: error("No selected expression found in file")
fun getSelectedElement(file: KtFile): PsiElement {
val range = selected[file.name] ?: error("No selected expression found in file")
val elements = file.elementsInRange(range).trimWhitespaces()
if (elements.size != 1) {
error("Expected one element at rage but found ${elements.size} [${elements.joinToString { it::class.simpleName + ": " + it.text }}]")
}
return elements.single() as KtElement
return elements.single()
}
fun getSelectedElementOfTypeByDirective(ktFile: KtFile, module: TestModule): PsiElement {
@@ -150,7 +149,7 @@ class ExpressionMarkerProvider : TestService {
inline fun <reified E : KtElement> getSelectedElementOfType(file: KtFile): E {
return when (val selected = getSelectedElement(file)) {
is E -> selected
else -> generateSequence(selected as PsiElement) { current ->
else -> generateSequence(selected) { current ->
current.children.singleOrNull()?.takeIf { it.textRange == current.textRange }
}.firstIsInstance()
}