From b9466151690bddce688d1ebdab0850438428df78 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 7 Jun 2020 09:55:33 +0100 Subject: [PATCH] Combine the new name map with the previous map This fixes a bug where classes disappeared from the map if they did not need to be re-compiled when incremental compilation is enabled. Signed-off-by: Graham --- .../deob/processor/NameMapProcessor.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/deob-processor/src/main/java/dev/openrs2/deob/processor/NameMapProcessor.kt b/deob-processor/src/main/java/dev/openrs2/deob/processor/NameMapProcessor.kt index 10de2146..67458869 100644 --- a/deob-processor/src/main/java/dev/openrs2/deob/processor/NameMapProcessor.kt +++ b/deob-processor/src/main/java/dev/openrs2/deob/processor/NameMapProcessor.kt @@ -37,9 +37,7 @@ import javax.lang.model.element.VariableElement "map" ) class NameMapProcessor : AbstractProcessor() { - private val classes = TreeMap() - private val fields = TreeMap() - private val methods = TreeMap() + private val map = NameMap() private val mapper: ObjectMapper private lateinit var trees: Trees private lateinit var localScanner: LocalVariableScanner @@ -67,7 +65,7 @@ class NameMapProcessor : AbstractProcessor() { check(element is TypeElement) val originalClass = element.getAnnotation(OriginalClass::class.java)!! - classes[originalClass.value] = element.qualifiedName.toString().toInternalClassName() + map.classes[originalClass.value] = element.qualifiedName.toString().toInternalClassName() } for (element in env.getElementsAnnotatedWith(OriginalMember::class.java)) { @@ -79,7 +77,7 @@ class NameMapProcessor : AbstractProcessor() { val ref = MemberRef(originalMember.owner, originalMember.name, originalMember.descriptor) when (element) { - is VariableElement -> fields[ref] = Field(owner, name) + is VariableElement -> map.fields[ref] = Field(owner, name) is ExecutableElement -> { val arguments = element.parameters.map { parameter -> val originalArg = parameter.getAnnotation(OriginalArg::class.java)!! @@ -89,7 +87,7 @@ class NameMapProcessor : AbstractProcessor() { val locals = TreeMap() localScanner.scan(path, locals) - methods[ref] = Method(owner, name, arguments, locals) + map.methods[ref] = Method(owner, name, arguments, locals) } else -> error("Unexpected element type") } @@ -98,8 +96,18 @@ class NameMapProcessor : AbstractProcessor() { if (env.processingOver()) { Files.createDirectories(mapPath.parent) + val combinedMap: NameMap + if (Files.exists(mapPath)) { + combinedMap = Files.newBufferedReader(mapPath).use { reader -> + mapper.readValue(reader, NameMap::class.java) + } + combinedMap.add(map) + } else { + combinedMap = map + } + Files.newBufferedWriter(mapPath).use { writer -> - mapper.writeValue(writer, NameMap(classes, fields, methods)) + mapper.writeValue(writer, combinedMap) } }