diff options
Diffstat (limited to 'stubs/src')
| -rw-r--r-- | stubs/src/kotlin/proxy/KotlinProxyNoLog.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/stubs/src/kotlin/proxy/KotlinProxyNoLog.java b/stubs/src/kotlin/proxy/KotlinProxyNoLog.java new file mode 100644 index 0000000..8b7e202 --- /dev/null +++ b/stubs/src/kotlin/proxy/KotlinProxyNoLog.java @@ -0,0 +1,51 @@ +package kotlin.proxy; + +public final class KotlinProxyNoLog { + private KotlinProxyNoLog() { + } + + /** + * Return value for stub methods with a reference return type (other than + * String). Asks {@link KotlinProxyOverrides#invoke} first — per-method + * custom implementations, passed the full argument list and the receiver + * (the stub instance the method was called on, null for statics) — and + * falls back to materializing a real no-arg instance of the declared + * return type. The generated body checkcasts the result to the declared + * type. + * + * The generated bytecode pushes the args array FIRST (member, owner, + * return type and receiver last) so its stack stays shallow (peak 5) — + * keep this parameter order in sync with RETURN_VALUE_DESC in + * gen_class.py. + */ + public static Object returnValue(Object[] args, String member, + String ownerDotName, String returnDotName, + Object instance) { + Object v = KotlinProxyOverrides.invoke(member, ownerDotName, + returnDotName, args, instance); + if (v == KotlinProxyOverrides.NO_VALUE) { + return newInstance(returnDotName); + } + return v; + } + + /** + * Default return-value materialization (the fallback of + * {@link #returnValue}). Reflectively instantiates the real, un-stubbed + * class of the declared return type so the caller (the daemon) can keep + * going: e.g. + * K2JVMCompiler.createArguments() returns a genuine K2JVMCompilerArguments, + * which lets parseCommandLineArguments run and doExecute be reached with the + * fully-populated args (the boundary we want to log). Returns null when the + * type has no usable no-arg constructor (interfaces, enums, abstract, etc.). + */ + private static Object newInstance(String dotName) { + try { + Class<?> c = Class.forName(dotName, false, + KotlinProxyNoLog.class.getClassLoader()); + return c.getDeclaredConstructor().newInstance(); + } catch (Throwable t) { + return null; + } + } +} |
