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; } } }