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

org.jetbrains.kotlin.incremental.storage.SourceToJsOutputMap.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
/*
 * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package org.jetbrains.kotlin.incremental.storage

import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
import org.jetbrains.kotlin.incremental.dumpCollection
import java.io.File

class SourceToJsOutputMap(
    storageFile: File,
    icContext: IncrementalCompilationContext,
) : AppendableBasicStringMap>(storageFile, StringCollectionExternalizer, icContext) {
    override fun dumpValue(value: Collection): String = value.dumpCollection()

    @Synchronized
    fun add(key: File, value: File) {
        storage.append(pathConverter.toPath(key), listOf(pathConverter.toPath(value)))
    }

    operator fun get(sourceFile: File): Collection =
        storage[pathConverter.toPath(sourceFile)]?.map { pathConverter.toFile(it) } ?: setOf()


    @Synchronized
    operator fun set(key: File, values: Collection) {
        if (values.isEmpty()) {
            remove(key)
            return
        }

        storage[pathConverter.toPath(key)] = values.map { pathConverter.toPath(it) }
    }

    @Synchronized
    fun remove(key: File) {
        storage.remove(pathConverter.toPath(key))
    }

    @Synchronized
    fun removeValues(key: File, removed: Set) {
        val notRemoved = this[key].filter { it !in removed }
        this[key] = notRemoved
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy