[uast] IDEA-330019 UAST: withUastParentOrSelf patterns are visible in highlighting

GitOrigin-RevId: 83a276ddbcd4d0f287a0015373852846394cbec2
This commit is contained in:
Yuriy Artamonov
2023-08-16 22:43:14 +02:00
committed by intellij-monorepo-bot
parent 358c1ab00a
commit 6c893c44ed

View File

@@ -18,6 +18,7 @@ import com.intellij.util.containers.ContainerUtil
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.NotNull
import org.jetbrains.uast.*
import org.jetbrains.uast.expressions.UInjectionHost
fun literalExpression(): ULiteralExpressionPattern = ULiteralExpressionPattern()
@@ -90,6 +91,17 @@ open class UElementPattern<T : UElement, Self : UElementPattern<T, Self>>(clazz:
parentPattern.accepts(it, context) || it.uastParent?.let { parentPattern.accepts(it, context) } ?: false
}
fun withStringRoomExpressionOrSelf(parentPattern: ElementPattern<out UElement>): Self = filterWithContext { it, context ->
if (it !is UInjectionHost) return@filterWithContext false
if (parentPattern.accepts(it, context)) return@filterWithContext true
val room = it.getStringRoomExpression()
if (room === it) return@filterWithContext false
parentPattern.accepts(room, context)
}
class Capture<T : UElement>(clazz: Class<T>) : UElementPattern<T, Capture<T>>(clazz)
}