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

org.jetbrains.kotlin.incremental.DirtyFilesContainer.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
/*
 * Copyright 2010-2018 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

import org.jetbrains.kotlin.build.report.ICReporter
import org.jetbrains.kotlin.name.FqName
import java.io.File

class DirtyFilesContainer(
    private val caches: IncrementalCachesManager<*>,
    private val reporter: ICReporter,
    private val sourceFilesExtensions: List
) {
    private val myDirtyFiles = HashSet()

    fun isEmpty() = myDirtyFiles.isEmpty()

    fun toMutableLinkedSet(): LinkedHashSet =
        LinkedHashSet(myDirtyFiles)

    fun add(files: Iterable, reason: String?) {
        val existingKotlinFiles = files.filter { it.isKotlinFile(sourceFilesExtensions) }
        if (existingKotlinFiles.isNotEmpty()) {
            myDirtyFiles.addAll(existingKotlinFiles)
            if (reason != null) {
                reporter.reportMarkDirty(existingKotlinFiles, reason)
            }
        }
    }

    fun addByDirtySymbols(lookupSymbols: Collection) {
        if (lookupSymbols.isEmpty()) return

        val dirtyFilesFromLookups = mapLookupSymbolsToFiles(caches.lookupCache, lookupSymbols, reporter)
        // reason is null, because files are reported in mapLookupSymbolsToFiles
        add(dirtyFilesFromLookups, reason = null)
    }

    fun addByDirtyClasses(dirtyClassesFqNames: Collection) {
        if (dirtyClassesFqNames.isEmpty()) return

        val fqNamesWithSubtypes = dirtyClassesFqNames.flatMap {
            withSubtypes(
                it,
                listOf(caches.platformCache)
            )
        }
        val dirtyFilesFromFqNames =
            mapClassesFqNamesToFiles(listOf(caches.platformCache), fqNamesWithSubtypes, reporter)
        // reason is null, because files are reported in mapClassesFqNamesToFiles
        add(dirtyFilesFromFqNames, reason = null)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy