From 4db7bcc523ed8adb32c98cff8785c1351132d7cf Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sun, 8 Dec 2019 10:58:30 +0100 Subject: Move remap error handling to the caller This e.g. allows the preprocessor to ignore errors in lines which it would have commented out anyway. --- src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt') diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt index 1e5b5ad..35d4fd5 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -23,13 +23,12 @@ import java.util.* internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) { private val mixinMappings = mutableMapOf>() - private var error: Boolean = false + private val errors = mutableListOf>() private val changes = TreeMap(Comparator.comparing { it.startOffset }) private fun error(at: PsiElement, message: String) { val line = StringUtil.offsetToLineNumber(file.text, at.textOffset) - System.err.println(file.name + ":" + line + ": " + message) - error = true + errors.add(Pair(line, message)) } private fun replace(e: PsiElement, with: String) { @@ -54,15 +53,12 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) return before == null || !before.intersects(range) } - private fun getResult(text: String): String? { - if (error) { - return null - } + private fun getResult(text: String): Pair>> { var result = text for ((key, value) in changes.descendingMap()) { result = key.replace(result, value) } - return result + return Pair(result, errors) } private fun map(expr: PsiElement, field: PsiField) { @@ -427,7 +423,7 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) }) } - fun remapFile(bindingContext: BindingContext): String? { + fun remapFile(bindingContext: BindingContext): Pair>> { file.accept(object : JavaRecursiveElementVisitor() { override fun visitClass(psiClass: PsiClass) { val annotation = psiClass.getAnnotation(CLASS_MIXIN) ?: return -- cgit