示例#1
0
 public void AddMethod(Method m)
 {
     Methods.Add(m);
 }
        internal override void WriteMethodBody(Method method, TextWriter writer, string indent, CodeGenerationOptions opt)
        {
            writer.WriteLine("{0}if ({1} == IntPtr.Zero)", indent, method.EscapedIdName);
            writer.WriteLine("{0}\t{1} = JNIEnv.Get{2}MethodID (class_ref, \"{3}\", \"{4}\");", indent, method.EscapedIdName, method.IsStatic ? "Static" : String.Empty, method.JavaName, method.JniSignature);
            bool use_non_virtual = method.IsVirtual && !method.IsAbstract;

            foreach (string prep in method.Parameters.GetCallPrep(opt))
            {
                writer.WriteLine("{0}{1}", indent, prep);
            }
            writer.WriteLine("{0}try {{", indent);
            var oldindent = indent;

            indent += "\t";
            method.Parameters.WriteCallArgs(writer, indent, opt, invoker: false);
            if (method.IsStatic)
            {
                GenerateJNICall(method, writer, indent, opt, "JNIEnv.CallStatic" + method.RetVal.CallMethodPrefix + "Method  (class_ref, " + method.EscapedIdName + method.Parameters.GetCallArgs(opt, invoker: false) + ")", true);
            }
            else if (use_non_virtual)
            {
                writer.WriteLine();
                if (!method.IsVoid && method.Parameters.HasCleanup)
                {
                    writer.WriteLine("{0}{1} __ret;", indent, opt.GetOutputName(method.RetVal.FullName));
                }
                writer.WriteLine("{0}if (((object) this).GetType () == ThresholdType)", indent);
                GenerateJNICall(method, writer, indent + "\t", opt,
                                "JNIEnv.Call" + method.RetVal.CallMethodPrefix + "Method (" +
                                method.DeclaringType.GetObjectHandleProperty("this") +
                                ", " + method.EscapedIdName + method.Parameters.GetCallArgs(opt, invoker: false) + ")",
                                declare_ret: false);
                writer.WriteLine("{0}else", indent);
                GenerateJNICall(method, writer, indent + "\t", opt,
                                "JNIEnv.CallNonvirtual" + method.RetVal.CallMethodPrefix + "Method (" +
                                method.DeclaringType.GetObjectHandleProperty("this") +
                                ", ThresholdClass, " +
                                string.Format("JNIEnv.GetMethodID (ThresholdClass, \"{0}\", \"{1}\")", method.JavaName, method.JniSignature) +
                                method.Parameters.GetCallArgs(opt, invoker: false) + ")",
                                false);
            }
            else
            {
                GenerateJNICall(
                    method,
                    writer,
                    indent,
                    opt,
                    "JNIEnv.Call" + method.RetVal.CallMethodPrefix + "Method (" +
                    method.DeclaringType.GetObjectHandleProperty("this") +
                    ", " + method.EscapedIdName +
                    method.Parameters.GetCallArgs(opt, invoker: false) + ")",
                    declare_ret: true);
            }

            if (!method.IsVoid && method.Parameters.HasCleanup)
            {
                writer.WriteLine("{0}return __ret;", indent);
            }
            indent = oldindent;
            writer.WriteLine("{0}}} finally {{", indent);
            foreach (string cleanup in method.Parameters.GetCallCleanup(opt))
            {
                writer.WriteLine("{0}\t{1}", indent, cleanup);
            }
            writer.WriteLine("{0}}}", indent);
        }
示例#3
0
 public bool ContainsMethod(Method method, bool check_ifaces) => ContainsMethod(method, check_ifaces, true);
 internal override void WriteMethodIdField(Method method, TextWriter writer, string indent, CodeGenerationOptions opt)
 {
     writer.WriteLine("{0}static IntPtr {1};", indent, method.EscapedIdName);
 }