From afcd1fac36329137d36ec86d545fc6fb48da9f0d Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 13 Feb 2021 16:37:04 +0000 Subject: [PATCH] Add workaround for IDEA-256707 Signed-off-by: Graham --- README.md | 7 ------- .../openrs2/deob/processor/NameMapProcessor.kt | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2f195b9d31..a6b3be5315 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,6 @@ material from being accidentally included in the repository. Run `./gradlew` to download the dependencies, build the code, run the unit tests and package it. -IDEA 2020.3's built-in build system breaks with a cryptic -`java: java.lang.IllegalArgumentException` error message when compiling modules -that use the `deob-annotations` processor. A workaround is to add -`-Djps.track.ap.dependencies=false` to the 'Shared build process VM options' in -File -> Settings -> Build, Execution and Deployment -> Compiler. See -[IDEA-256707][idea-bug] for more information. - ## Links * [Discord][discord] diff --git a/deob-processor/src/main/kotlin/org/openrs2/deob/processor/NameMapProcessor.kt b/deob-processor/src/main/kotlin/org/openrs2/deob/processor/NameMapProcessor.kt index f53ec6e7fb..8630ef4e80 100644 --- a/deob-processor/src/main/kotlin/org/openrs2/deob/processor/NameMapProcessor.kt +++ b/deob-processor/src/main/kotlin/org/openrs2/deob/processor/NameMapProcessor.kt @@ -14,6 +14,7 @@ import org.openrs2.deob.util.map.Method import org.openrs2.deob.util.map.NameMap import org.openrs2.util.io.useAtomicBufferedWriter import org.openrs2.yaml.Yaml +import java.lang.reflect.Proxy import java.nio.file.Files import java.nio.file.Path import java.util.TreeMap @@ -51,10 +52,22 @@ public class NameMapProcessor : AbstractProcessor() { override fun init(env: ProcessingEnvironment) { super.init(env) - trees = Trees.instance(env) + trees = Trees.instance(unwrap(env)) localScanner = LocalVariableScanner(trees) } + // see https://youtrack.jetbrains.com/issue/IDEA-256707 + private fun unwrap(env: ProcessingEnvironment): ProcessingEnvironment { + if (!Proxy.isProxyClass(env.javaClass)) { + return env + } + + val invocationHandler = Proxy.getInvocationHandler(env) + val field = invocationHandler.javaClass.getDeclaredField("val\$delegateTo") + field.isAccessible = true + return field.get(invocationHandler) as ProcessingEnvironment + } + private fun getPath(): Path? { val map = processingEnv.options["map"] ?: return null return Path.of(map)