All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlinx.jupyter.libraries.ChainedLibraryResolver.kt Maven / Gradle / Ivy

Go to download

Implementation of REPL compiler and preprocessor for Jupyter dialect of Kotlin (IDE-compatible)

There is a newer version: 0.12.0-250
Show newest version
package org.jetbrains.kotlinx.jupyter.libraries

import org.jetbrains.kotlinx.jupyter.api.libraries.LibraryDefinition
import org.jetbrains.kotlinx.jupyter.api.libraries.LibraryReference
import org.jetbrains.kotlinx.jupyter.api.libraries.Variable

abstract class ChainedLibraryResolver(private val parent: LibraryResolver? = null) : LibraryResolver {
    protected abstract fun tryResolve(reference: LibraryReference, arguments: List): LibraryDefinition?
    protected open fun save(reference: LibraryReference, definition: LibraryDefinition) {}
    protected open fun shouldResolve(reference: LibraryReference): Boolean = true

    override fun resolve(reference: LibraryReference, arguments: List): LibraryDefinition? {
        val shouldBeResolved = shouldResolve(reference)
        if (shouldBeResolved) {
            val result = tryResolve(reference, arguments)
            if (result != null) return result
        }

        val parentResult = parent?.resolve(reference, arguments) ?: return null
        if (shouldBeResolved) {
            save(reference, parentResult)
        }

        return parentResult
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy