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

.kotlin.kotlin-compiler.1.3.11.source-code.CacheAttributesDiff.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
/*
 * Copyright 2010-2018 JetBrains s.r.o. 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.version

/**
 * Diff between actual and expected cache attributes.
 * [status] are calculated based on this diff (see [CacheStatus]).
 * Based on that [status] system may perform required actions (i.e. rebuild something, clearing caches, etc...).
 *
 * [CacheAttributesDiff] can be used to cache current attribute values and as facade for version operations.
 */
data class CacheAttributesDiff(
    val manager: CacheAttributesManager,
    val actual: Attrs?,
    val expected: Attrs?
) {
    val status: CacheStatus
        get() =
            if (expected != null) {
                if (actual != null && manager.isCompatible(actual, expected)) CacheStatus.VALID
                else CacheStatus.INVALID
            } else {
                if (actual != null) CacheStatus.SHOULD_BE_CLEARED
                else CacheStatus.CLEARED
            }

    fun saveExpectedIfNeeded() {
        if (expected != actual) manager.writeActualVersion(expected)
    }

    override fun toString(): String {
        return "$status: actual=$actual -> expected=$expected"
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy