From 10370dd3b2606e38af56b10777f6a176db888c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kozie=C5=82?= Date: Wed, 22 Feb 2023 12:37:47 +0100 Subject: [PATCH] Fixes after review --- .../core/replacement/PythonFunctionCallHeuristic.kt | 4 ++-- .../core/replacement/VersionReplacementHeuristic.kt | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/kotlin/org/virtuslab/bazelsteward/core/replacement/PythonFunctionCallHeuristic.kt b/core/src/main/kotlin/org/virtuslab/bazelsteward/core/replacement/PythonFunctionCallHeuristic.kt index f3d5b53b..ae2a1c9b 100644 --- a/core/src/main/kotlin/org/virtuslab/bazelsteward/core/replacement/PythonFunctionCallHeuristic.kt +++ b/core/src/main/kotlin/org/virtuslab/bazelsteward/core/replacement/PythonFunctionCallHeuristic.kt @@ -19,7 +19,7 @@ object PythonFunctionCallHeuristic : VersionReplacementHeuristic { } val currentVersion = updateSuggestion.currentLibrary.version.value - val (parentMatch, matchedVersion) = functionCallsWithAssociatedStrings.firstNotNullOfOrNull { call -> + val matchedVersion = functionCallsWithAssociatedStrings.firstNotNullOfOrNull { call -> Regex.fromLiteral(currentVersion).find(call.matchedText)?.let { call.subMatch(it) } } ?: return null @@ -28,7 +28,7 @@ object PythonFunctionCallHeuristic : VersionReplacementHeuristic { listOf( FileChange( matchedVersion.origin, - parentMatch.offset + matchedVersion.offset, + matchedVersion.offset, updateSuggestion.currentLibrary.version.value.length, updateSuggestion.suggestedVersion.value ) diff --git a/core/src/main/kotlin/org/virtuslab/bazelsteward/core/replacement/VersionReplacementHeuristic.kt b/core/src/main/kotlin/org/virtuslab/bazelsteward/core/replacement/VersionReplacementHeuristic.kt index 5955b2b9..e332d9ea 100644 --- a/core/src/main/kotlin/org/virtuslab/bazelsteward/core/replacement/VersionReplacementHeuristic.kt +++ b/core/src/main/kotlin/org/virtuslab/bazelsteward/core/replacement/VersionReplacementHeuristic.kt @@ -12,17 +12,18 @@ data class LibraryUpdate( data class MatchedText( val match: MatchResult, - val origin: Path + val origin: Path, + val baseOffset: Int = 0 ) { val offset: Int - get() = match.range.start + get() = match.range.start + baseOffset val offsetLastMatchGroup: Int? get() = match.groups.last()?.range?.start val matchedText: String get() = match.value - fun subMatch(other: MatchResult): Pair = this to MatchedText(other, origin) + fun subMatch(subMatch: MatchResult): MatchedText = MatchedText(subMatch, origin, baseOffset = offset) } interface VersionReplacementHeuristic {