aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/replaymod/gradle/remap
diff options
context:
space:
mode:
authorJonas Herzig <me@johni0702.de>2019-12-08 10:58:30 +0100
committerJonas Herzig <me@johni0702.de>2019-12-08 11:11:51 +0100
commit4db7bcc523ed8adb32c98cff8785c1351132d7cf (patch)
tree26ee5c990aeb44ddf1d5282af63564db4b88644f /src/main/kotlin/com/replaymod/gradle/remap
parentff84669a02e8ffd3e634db4321dbc199b35effce (diff)
downloadRemap-4db7bcc523ed8adb32c98cff8785c1351132d7cf.tar.gz
Remap-4db7bcc523ed8adb32c98cff8785c1351132d7cf.tar.bz2
Remap-4db7bcc523ed8adb32c98cff8785c1351132d7cf.zip
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.
Diffstat (limited to 'src/main/kotlin/com/replaymod/gradle/remap')
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt14
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt13
2 files changed, 9 insertions, 18 deletions
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<String, ClassMapping<*, *>>()
- private var error: Boolean = false
+ private val errors = mutableListOf<Pair<Int, String>>()
private val changes = TreeMap<TextRange, String>(Comparator.comparing<TextRange, Int> { 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<String, List<Pair<Int, String>>> {
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<String, List<Pair<Int, String>>> {
file.accept(object : JavaRecursiveElementVisitor() {
override fun visitClass(psiClass: PsiClass) {
val annotation = psiClass.getAnnotation(CLASS_MIXIN) ?: return
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt b/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt
index 90296d3..8df1f68 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt
@@ -40,10 +40,9 @@ import kotlin.system.exitProcess
class Transformer(private val map: MappingSet) {
var classpath: Array<String>? = null
- private var fail: Boolean = false
@Throws(IOException::class)
- fun remap(sources: Map<String, String>): Map<String, String> {
+ fun remap(sources: Map<String, String>): Map<String, Pair<String, List<Pair<Int, String>>>> {
val tmpDir = Files.createTempDirectory("remap")
try {
for ((unitName, source) in sources) {
@@ -84,7 +83,7 @@ class Transformer(private val map: MappingSet) {
{ scope: GlobalSearchScope -> environment.createPackagePartProvider(scope) }
)
- val results = HashMap<String, String>()
+ val results = HashMap<String, Pair<String, List<Pair<Int, String>>>>()
for (name in sources.keys) {
val file = vfs.findFileByIoFile(tmpDir.resolve(name).toFile())!!
val psiFile = psiManager.findFile(file)!!
@@ -94,10 +93,6 @@ class Transformer(private val map: MappingSet) {
} catch (e: Exception) {
throw RuntimeException("Failed to map file \"$name\".", e)
}
- if (mapped == null) {
- fail = true
- continue
- }
results[name] = mapped
}
return results
@@ -142,14 +137,14 @@ class Transformer(private val map: MappingSet) {
for (name in sources.keys) {
println(name)
- val lines = results.getValue(name).split("\n").dropLastWhile { it.isEmpty() }.toTypedArray()
+ val lines = results.getValue(name).first.split("\n").dropLastWhile { it.isEmpty() }.toTypedArray()
println(lines.size)
for (line in lines) {
println(line)
}
}
- if (transformer.fail) {
+ if (results.any { it.value.second.isNotEmpty() }) {
exitProcess(1)
}
}