Inject ObjectMapper in NameMapProcessor

We have to create the Injector in the constructor as it's instantiated
by javac, not our own code.

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent 9441527c61
commit d32ea82032
  1. 3
      deob-processor/build.gradle.kts
  2. 11
      deob-processor/src/main/java/dev/openrs2/deob/processor/NameMapProcessor.kt

@ -6,8 +6,7 @@ plugins {
dependencies {
implementation(project(":deob-annotations"))
implementation(project(":deob-map"))
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${Versions.jackson}")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${Versions.jackson}")
implementation(project(":yaml"))
}
publishing {

@ -1,8 +1,7 @@
package dev.openrs2.deob.processor
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import com.google.inject.Guice
import com.sun.source.util.Trees
import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.toInternalClassName
@ -12,6 +11,7 @@ import dev.openrs2.deob.annotation.OriginalMember
import dev.openrs2.deob.map.Field
import dev.openrs2.deob.map.Method
import dev.openrs2.deob.map.NameMap
import dev.openrs2.yaml.YamlModule
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
@ -41,9 +41,15 @@ class NameMapProcessor : AbstractProcessor() {
private val classes = TreeMap<String, String>()
private val fields = TreeMap<MemberRef, Field>()
private val methods = TreeMap<MemberRef, Method>()
private val mapper: ObjectMapper
private lateinit var trees: Trees
private lateinit var localScanner: LocalVariableScanner
init {
val injector = Guice.createInjector(YamlModule())
mapper = injector.getInstance(ObjectMapper::class.java)
}
override fun init(env: ProcessingEnvironment) {
super.init(env)
trees = Trees.instance(env)
@ -92,7 +98,6 @@ class NameMapProcessor : AbstractProcessor() {
if (env.processingOver()) {
Files.newBufferedWriter(mapPath).use { writer ->
val mapper = ObjectMapper(YAMLFactory()).registerKotlinModule()
mapper.writeValue(writer, NameMap(classes, fields, methods))
}
}

Loading…
Cancel
Save