mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Uast: findUSwitchClauseBody dont throw exception if there is no clause
(EA-114369)
This commit is contained in:
@@ -76,7 +76,7 @@ private fun JavaAbstractUElement.unwrapSwitch(uParent: UElement): UElement {
|
||||
}
|
||||
val uSwitchExpression = codeBlockParent.uastParent as? JavaUSwitchExpression ?: return uParent
|
||||
val psiElement = psi ?: return uParent
|
||||
return findUSwitchClauseBody(uSwitchExpression, psiElement)
|
||||
return findUSwitchClauseBody(uSwitchExpression, psiElement) ?: return codeBlockParent
|
||||
}
|
||||
if (codeBlockParent is JavaUSwitchExpression) {
|
||||
return unwrapSwitch(codeBlockParent)
|
||||
|
||||
+2
-2
@@ -71,11 +71,11 @@ internal fun findUSwitchEntry(body: UExpressionList, el: PsiSwitchLabelStatement
|
||||
body.also { require(it.kind == JavaSpecialExpressionKinds.SWITCH) }
|
||||
.expressions.find { (it as? JavaUSwitchEntry)?.labels?.contains(el) ?: false } as? JavaUSwitchEntry
|
||||
|
||||
internal fun findUSwitchClauseBody(switch: JavaUSwitchExpression, psi: PsiElement): UExpressionList {
|
||||
internal fun findUSwitchClauseBody(switch: JavaUSwitchExpression, psi: PsiElement): UExpressionList? {
|
||||
val bodyExpressions = switch.body.expressions
|
||||
val uExpression = bodyExpressions.find {
|
||||
(it as JavaUSwitchEntry).body.expressions.any { it.psi == psi }
|
||||
} ?: throw IllegalStateException("${psi.javaClass} not found in ${bodyExpressions.map { it.asLogString() }}")
|
||||
} ?: return null
|
||||
return (uExpression as JavaUSwitchEntry).body
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
|
||||
void foo(int a){
|
||||
switch (a){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -165,4 +165,10 @@ class JavaUastApiTest : AbstractJavaUastTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCanFindAWayFromBrokenSwitch() = doTest("BrokenCode/Switch.java") { name, file ->
|
||||
val testClass = file.findElementByTextFromPsi<UElement>("""return;""")
|
||||
TestCase.assertEquals(7, testClass.withContainingElements.count())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user