diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-05 20:41:25 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-05 20:41:25 +0100 |
| commit | aefb3dbf687b46775bca1b600317bc053648b211 (patch) | |
| tree | fc20afdc03ee7cd60bb7fa7bae438fcad033fa5a /stubs/src/kotlin/proxy/KotlinProxyOverrides.java | |
| parent | a22e0810f6473ff9063166f75b7e4e0236324b6b (diff) | |
First steps for overrides
Diffstat (limited to 'stubs/src/kotlin/proxy/KotlinProxyOverrides.java')
| -rw-r--r-- | stubs/src/kotlin/proxy/KotlinProxyOverrides.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/stubs/src/kotlin/proxy/KotlinProxyOverrides.java b/stubs/src/kotlin/proxy/KotlinProxyOverrides.java new file mode 100644 index 0000000..d40417e --- /dev/null +++ b/stubs/src/kotlin/proxy/KotlinProxyOverrides.java @@ -0,0 +1,56 @@ +package kotlin.proxy; + +import org.jetbrains.kotlin.cli.common.ExitCode; +import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments; +import org.jetbrains.kotlin.com.intellij.openapi.Disposable; +import org.jetbrains.kotlin.config.CompilerConfiguration; +import org.jetbrains.kotlin.config.JvmTarget; +import org.jetbrains.kotlin.config.Services; +import org.jetbrains.kotlin.utils.KotlinPaths; + +/** + * Per-method custom return values for the generated stubs. + * + * Every stub method with a reference return type (other than String) asks + * here for its return value (via {@link KotlinProxyLog#returnValue}) before + * falling back to the default — a real no-arg instance of the declared return + * type, or null. Implement the methods you want the stub to actually do + * something for; return {@link #NO_VALUE} for everything else. + * + * args[i] is the i-th parameter of the call: reference types as-is, + * primitives boxed (Integer, Long, Boolean, ...). A param-less method gets + * args == null. Rebuild the jar (steps 2-3) after editing. + */ +public final class KotlinProxyOverrides { + + /** Return this from invoke() to keep the default return value. */ + public static final Object NO_VALUE = new Object(); + + private static ProxyPerformanceManager sPerformanceManager; + + private KotlinProxyOverrides() { + } + + public static Object invoke(String member, String ownerDotName, + String returnDotName, Object[] args) { + if ("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler".equals(ownerDotName)) { + if ("createPerformanceManager".equals(member)) { + K2JVMCompilerArguments compilerArgs = (K2JVMCompilerArguments) args[0]; + // Services services = (Services) args[1]; + sPerformanceManager = new ProxyPerformanceManager(JvmTarget.Companion.fromString(compilerArgs.getJvmTarget())); + return sPerformanceManager; + } + if ("getPlatform".equals(member)) { + return sPerformanceManager.getTargetPlatform(); + } + if ("doExecute".equals(member)) { + K2JVMCompilerArguments compilerArgs = (K2JVMCompilerArguments) args[0]; + CompilerConfiguration config = (CompilerConfiguration) args[1]; + Disposable disposable = (Disposable) args[2]; + KotlinPaths paths = (KotlinPaths) args[3]; + return ExitCode.COMPILATION_ERROR; + } + } + return NO_VALUE; + } +} |
