fun findParentOf()

in robot-server-core/src/main/kotlin/com/intellij/remoterobot/services/IdeRobot.kt [81:105]


    fun findParentOf(containerId: String, lambdaContainer: ObjectContainer): Result<RemoteComponent> {
        val lambda = lambdaLoader.getFunction(lambdaContainer) as RobotContext.(c: Component) -> Boolean
        val component = componentContextCache[containerId]?.component
            ?: throw IllegalStateException("Unknown component id $containerId")

        return getResult(RobotContext(robot)) { ctx ->
            var c: Component
            c = component
            var parent: Component? = null
            while (c.parent != null) {
                c = c.parent
                if (lambda(ctx, c)) {
                    parent = c
                    break
                }
            }

            if (parent == null) {
                throw ComponentLookupException("Unable to find parent of component ($component)")
            }

            val id = addComponentToStorage(parent)
            RemoteComponent(id, parent)
        }
    }