From f4ca1daa65c3bdccdf33d2e39be2e427b4f958a1 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Fri, 11 Oct 2024 22:09:21 +0200 Subject: [PATCH] fix: Cache removed, part of #536 --- .../SnakemakeFrameworkAPIProvider.kt | 86 ++++++------------- 1 file changed, 27 insertions(+), 59 deletions(-) diff --git a/src/main/kotlin/com/jetbrains/snakecharm/framework/SnakemakeFrameworkAPIProvider.kt b/src/main/kotlin/com/jetbrains/snakecharm/framework/SnakemakeFrameworkAPIProvider.kt index e5355634..15303776 100644 --- a/src/main/kotlin/com/jetbrains/snakecharm/framework/SnakemakeFrameworkAPIProvider.kt +++ b/src/main/kotlin/com/jetbrains/snakecharm/framework/SnakemakeFrameworkAPIProvider.kt @@ -12,7 +12,6 @@ import com.jetbrains.snakecharm.lang.SnakemakeNames.CHECKPOINT_KEYWORD import com.jetbrains.snakecharm.lang.SnakemakeNames.RULE_KEYWORD import com.jetbrains.snakecharm.lang.SnakemakeNames.USE_KEYWORD import io.ktor.util.* -import kotlinx.collections.immutable.toImmutableMap import org.jetbrains.annotations.TestOnly import org.yaml.snakeyaml.LoaderOptions import org.yaml.snakeyaml.Yaml @@ -35,14 +34,6 @@ class SnakemakeFrameworkAPIProvider( private lateinit var topLevelName2Introduction: Map> private lateinit var subsectionName2Introduction: Map, TreeMap> - private lateinit var subsectionIntroduction: Map, SmkLanguageVersion?> - private lateinit var topLevelIntroduction: Map - - private lateinit var subsectionRemoval: Map, SmkLanguageVersion?> - private lateinit var topLevelRemoval: Map - private lateinit var subsectionDeprecation: Map, SmkLanguageVersion?> - private lateinit var topLevelDeprecation: Map - private lateinit var defaultVersion: String init { @@ -113,39 +104,6 @@ class SnakemakeFrameworkAPIProvider( topLevelName2Introduction = topLevelIntroductionInfo subsectionName2Introduction = subsectionIntroductionInfo - - // Cached first (intro) and last deprecated/removed infos: - topLevelIntroduction = topLevelIntroductionInfo.map { (name, changes) -> - name to changes.firstEntry().key - }.toMap().toImmutableMap() - - subsectionIntroduction = subsectionIntroductionInfo.map { (nameAndCtx, changes) -> - nameAndCtx to changes.firstEntry().key - }.toMap().toImmutableMap() - - topLevelRemoval = topLevelDeprecationInfo.map { (name, deprecations) -> - val latestDeprecated = - deprecations.descendingMap().asIterable().firstOrNull() { it.value.type == SmkAPIAnnDeprecationType.REMOVED } - name to latestDeprecated?.key - }.toMap().toImmutableMap() - - topLevelDeprecation = topLevelDeprecationInfo.map { (name, deprecations) -> - val latestDeprecated = - deprecations.descendingMap().asIterable().firstOrNull() { it.value.type == SmkAPIAnnDeprecationType.DEPRECATED } - name to latestDeprecated?.key - }.toMap().toImmutableMap() - - subsectionDeprecation = subsectionDeprecationInfo.map { (nameAndCtx, deprecations) -> - val latestDeprecated = - deprecations.descendingMap().asIterable().firstOrNull() { it.value.type == SmkAPIAnnDeprecationType.DEPRECATED } - nameAndCtx to latestDeprecated?.key - }.toMap().toImmutableMap() - - subsectionRemoval = subsectionDeprecationInfo.map { (nameAndCtx, deprecations) -> - val latestDeprecated = - deprecations.descendingMap().asIterable().firstOrNull() { it.value.type == SmkAPIAnnDeprecationType.REMOVED } - nameAndCtx to latestDeprecated?.key - }.toMap().toImmutableMap() } private fun filIntroductionData( @@ -269,25 +227,35 @@ class SnakemakeFrameworkAPIProvider( ) } - fun getTopLevelIntroductionVersion(name: String): SmkLanguageVersion? { - return topLevelIntroduction[name] - } - fun getTopLevelRemovedVersion(name: String): SmkLanguageVersion? { - return topLevelRemoval[name] - } - fun getTopLevelDeprecationVersion(name: String): SmkLanguageVersion? { - return topLevelDeprecation[name] - } + fun getTopLevelIntroductionVersion(name: String): SmkLanguageVersion? = + topLevelName2Introduction[name]?.firstEntry()?.key + + fun getTopLevelRemovedVersion(name: String): SmkLanguageVersion? = + topLevelName2Deprecations[name]?.let { deprecations -> + val latestDeprecated = deprecations.descendingMap().asIterable().firstOrNull() { it.value.type == SmkAPIAnnDeprecationType.REMOVED } + latestDeprecated?.key + } + + fun getTopLevelDeprecationVersion(name: String): SmkLanguageVersion? = + topLevelName2Deprecations[name]?.let { deprecations -> + val latestDeprecated = deprecations.descendingMap().asIterable().firstOrNull() { it.value.type == SmkAPIAnnDeprecationType.DEPRECATED } + latestDeprecated?.key + } fun getSubSectionIntroductionVersion(name: String, contextSectionKeyword: String): SmkLanguageVersion? = - subsectionIntroduction[name to contextSectionKeyword] + subsectionName2Introduction[name to contextSectionKeyword]?.firstEntry()?.key - fun getSubSectionDeprecationVersion(name: String, contextSectionKeyword: String): SmkLanguageVersion? { - return subsectionDeprecation[name to contextSectionKeyword] - } - fun getSubSectionRemovalVersion(name: String, contextSectionKeyword: String): SmkLanguageVersion? { - return subsectionRemoval[name to contextSectionKeyword] - } + fun getSubSectionDeprecationVersion(name: String, contextSectionKeyword: String): SmkLanguageVersion? = + subsectionName2Deprecations[name to contextSectionKeyword]?.let { deprecations -> + val latestDeprecated = deprecations.descendingMap().asIterable().firstOrNull() { it.value.type == SmkAPIAnnDeprecationType.DEPRECATED } + latestDeprecated?.key + } + + fun getSubSectionRemovalVersion(name: String, contextSectionKeyword: String): SmkLanguageVersion? = + subsectionName2Deprecations[name to contextSectionKeyword]?.let { deprecations -> + val latestDeprecated = deprecations.descendingMap().asIterable().firstOrNull() { it.value.type == SmkAPIAnnDeprecationType.REMOVED } + latestDeprecated?.key + } fun collectAllPossibleUseSubsectionKeywords() = collectAllPossibleSubsectionKeywords { type -> type == USE_KEYWORD @@ -305,7 +273,7 @@ class SnakemakeFrameworkAPIProvider( val mutableSet = mutableSetOf() // Collect all sections ignoring deprecation/removal/introduction marks: - listOf(subsectionIntroduction.keys, subsectionDeprecation.keys, subsectionRemoval.keys).forEach { keys -> + listOf(subsectionName2Introduction.keys, subsectionName2Deprecations.keys).forEach { keys -> mutableSet.addAll( keys.filter { (_, type) -> ctxTypeFilter(type) } .map { (name, _) -> name }