示例#1
0
文件: JavaClass.cs 项目: mortend/uno
            public void AddForeignMethod(ForeignMethod fm, ExpandInterceptor expandInterceptor)
            {
                var jmtd = new JavaMethod(fm, _helpers, _convert, expandInterceptor, _environment);

                _methods.Add(jmtd);
                _blockHost.NativeJavaMethods.Add(jmtd.GenJavaEntrypointMethod(this));
            }
示例#2
0
        public UnoCallToForeignMethod(ForeignMethod fm, Converters.Converter convert, string javaMethodName)
        {
            var jniSignature = fm.JniSignature;

            // gen code for getting class, methods and potentially casting vars
            var tearDown      = new List <string>();
            var jniVarStrings = new List <string> {
                "__cls", "__mtd"
            };
            var safeVarPrefix = fm.GetSafeVarPrefixForCpp();
            var setup         = new List <string>
            {
                "INIT_JNI;",
                "jclass __cls = JniHelper::GetNativeExternClass();",
                "WITH_STATIC_JAVA_METHOD(__mtd, __cls, \"" + javaMethodName + "\", \"" + jniSignature + "\");"
            };

            if (!fm.IsStatic)
            {
                var thisCast = convert.Type.CastUnoToJni(convert.Essentials.Object, Converters.Converter.JniFreeingTechnique.Default, safeVarPrefix + "this_", safeVarPrefix + "uthis");
                setup.Add(thisCast.UnoTmpVarLet("@IL$$"));
                setup.Add(thisCast.CastLet);
                jniVarStrings.Add(thisCast.JniVarName);
                tearDown.Add(thisCast.Free);
            }

            for (var i = 0; i < fm.InitialUnoMethod.Parameters.Length; i++)
            {
                var p    = fm.InitialUnoMethod.Parameters[i];
                var jvar = convert.Type.CastUnoToJni(p.Type, Converters.Converter.JniFreeingTechnique.Default, safeVarPrefix + p.Name, safeVarPrefix + "u" + p.Name);
                setup.Add(jvar.UnoTmpVarLet("@IL$" + i));
                setup.Add(jvar.CastLet);
                jniVarStrings.Add(jvar.JniVarName);
                tearDown.Add(jvar.Free);
            }

            if (fm.UnoReturnType == convert.Essentials.String)
            {
                tearDown.Add("if (__jresult!=nullptr && U_JNIVAR->GetObjectRefType(__jresult) == JNILocalRefType) U_JNIVAR->DeleteLocalRef(__jresult);");
            }

            //--------------------------

            var call = "U_JNIVAR->" + GetJniCallFunction(fm) + "(" + string.Join(",", jniVarStrings) + ")";

            SetUp = setup;

            Recieve = convert.Type.IsVoid(fm.UnoReturnType)
                                                         ? call + ";"
                                         : convert.Type.UnoToJniType(fm.UnoReturnType) + " __jresult = " + call + ";";


            Convert = fm.UnoReturnType.IsVoid
                                                ? "" : "@{" + fm.UnoReturnType.FullName + "} __result = " + convert.Type.CastJniToUno(fm.UnoReturnType, "__jresult", false) + ";";

            TearDown = tearDown;

            Return = convert.Type.IsVoid(fm.UnoReturnType) ? "" : "return __result;";
        }
示例#3
0
 public JavaMethod(ForeignMethod fm, ForeignHelpers helpers, Converters.Converter convert, ExpandInterceptor expandInterceptor, IEnvironment env)
 {
     _convert       = convert;
     _helpers       = helpers;
     _environment   = env;
     _foreignMethod = fm;
     _argsWithTypes = JavaMethodArgs(fm.InitialUnoMethod);
     _argsNoTypes   = JavaMethodArgs(fm.InitialUnoMethod, false);
     Source         = GenJavaMethod(fm.InitialUnoMethod, fm.JavaName, expandInterceptor);
 }
示例#4
0
        static string GetJniCallFunction(ForeignMethod fm)
        {
            var returnTypeName = fm.UnoReturnType.IsEnum
                                ? fm.UnoReturnType.Base.FullName
                                : fm.UnoReturnType.FullName;

            string result;

            if (!_jniCallFunc.TryGetValue(returnTypeName, out result))
            {
                result = "Object";
            }
            return("CallStatic" + result + "Method");
        }
示例#5
0
        protected override void OnForeignFunction(Function f, List <string> annotations)
        {
            // Setup
            EnsureInitialized();
            Helpers.CacheContext(null, f.Source);

            var fm = new ForeignMethod(f, Essentials, Convert, Helpers, annotations);

            GenDelegatePlumbing(f);

            // Generate new java code
            var jcls = GetJavaClass(f.DeclaringType, Environment);

            jcls.AddForeignMethod(fm, ExpandInterceptor);

            // replace the extern body string with the jni calls
            Helpers.ReplaceBody(f, fm.GetCallFromUno());

            // add c++ headers to type
            Helpers.SourceInclude(fm.CppHeadersForDeclaringType, ((Method)f).DeclaringType);
        }