aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorJonas Herzig <jonas@spark-squared.com>2021-11-11 20:59:47 +0100
committerJonas Herzig <jonas@spark-squared.com>2021-11-12 15:23:25 +0100
commitf1224518f86b0160149544dc8d56505a37a186e2 (patch)
tree23d3a40362df3dde498e69ad9ac8ee7727cbd8fd /src/main/kotlin
parent1aa8b425982a6d30a177bc25a70a325652209ee0 (diff)
downloadRemap-f1224518f86b0160149544dc8d56505a37a186e2.tar.gz
Remap-f1224518f86b0160149544dc8d56505a37a186e2.tar.bz2
Remap-f1224518f86b0160149544dc8d56505a37a186e2.zip
Fix loss of changes when multiple target the same start point
While one might at first think that multiple changes should conflict if they target that same start point, that is not necessarily true as long as no more than one of them includes deletions: There may be an arbitrary number of insertions at the same position (regular remapping never just inserts but patterns can).
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
index a8d9f2a..c620c4c 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
@@ -31,7 +31,7 @@ internal class PsiMapper(
) {
private val mixinMappings = mutableMapOf<String, ClassMapping<*, *>>()
private val errors = mutableListOf<Pair<Int, String>>()
- private val changes = TreeMap<TextRange, String>(Comparator.comparing<TextRange, Int> { it.startOffset })
+ private val changes = TreeMap<TextRange, String>(compareBy<TextRange> { it.startOffset }.thenBy { it.endOffset })
private fun error(at: PsiElement, message: String) {
val line = StringUtil.offsetToLineNumber(file.text, at.textOffset)
@@ -40,7 +40,13 @@ internal class PsiMapper(
private fun replace(e: PsiElement, with: String) = replace(e.textRange, with)
private fun replace(textRange: TextRange, with: String) {
- changes[textRange] = with
+ changes.compute(textRange) { _, replacement ->
+ if (replacement != null) {
+ replacement + with
+ } else {
+ with
+ }
+ }
}
private fun replaceIdentifier(parent: PsiElement, with: String) {