public JniValueCast(DataType dt, JniFreeingTechnique free, string jniTmpVarName, string unoTmpVarName, Converter convert, IEssentials essentials, ForeignHelpers helpers) { JniVarName = jniTmpVarName; UnoTmpVarName = unoTmpVarName; UnoTmpVarLet = line => "@{" + dt.FullName + "} " + unoTmpVarName + "=" + line + ";"; var typeUsuallyFreed = true; string cast; if (helpers.IsPrimitive(dt) || dt.IsEnum) { cast = "(" + convert.Type.UnoToJniType(dt) + ")" + unoTmpVarName; typeUsuallyFreed = false; } else if (dt == essentials.String) { cast = "JniHelper::UnoToJavaString(" + unoTmpVarName + ")"; } else if (convert.Type.IsJavaObject(dt)) { cast = "(" + unoTmpVarName + "==NULL ? NULL : U_JNIVAR->NewLocalRef(@{global::Android.Base.Wrappers.IJWrapper:Of((@{global::Android.Base.Wrappers.IJWrapper})" + unoTmpVarName + ")._GetJavaObject():Call()}))"; } else if (dt.IsSubclassOfOrEqual(essentials.Delegate)) { var d = (DelegateType)dt; cast = "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + ".BoxDelegate(object,global::Android.Base.Primitives.ConstCharPtr):Call((@{object})" + unoTmpVarName + ", \"" + convert.Name.JavaDelegateName(d, true) + "\")}"; } else if (convert.Type.HasJavaEquivalent(dt)) { cast = "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + ".Box(" + dt.FullName + "):Call(" + unoTmpVarName + ")}"; } else if (dt.IsStruct) { cast = "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + ".Box(object):Call(" + helpers.BoxStruct(dt, unoTmpVarName) + ")}"; } else { cast = "@{" + ForeignJavaPass.UnoToJavaBoxingClass.FullName + ".Box(object):Call(" + unoTmpVarName + ")}"; } if (typeUsuallyFreed) { switch (free) { case JniFreeingTechnique.Default: Free = "if (" + JniVarName + "!=NULL) { U_JNIVAR->DeleteLocalRef(" + JniVarName + "); }"; break; case JniFreeingTechnique.WithScope: if (dt.IsStruct) // no null check needed if is uno struct { cast = "U_JNIVAR->NewLocalRef((" + cast + "))"; } else { cast = "(" + unoTmpVarName + "==NULL ? NULL : U_JNIVAR->NewLocalRef((" + cast + ")))"; } Free = ""; break; case JniFreeingTechnique.None: Free = ""; break; default: throw new ArgumentOutOfRangeException(nameof(free), free, null); } } CastSet = jniTmpVarName + " = " + cast + ";"; CastLet = convert.Type.UnoToJniType(dt, true) + " " + CastSet; }
public JniValueCast CastUnoToJni(DataType dt, JniFreeingTechnique free, string jniTmpVarName, string unoTmpVarName = null) { return(new JniValueCast(dt, free, jniTmpVarName, unoTmpVarName ?? "_tmp_" + (_uniqueVarNum += 1), _convert, _essentials, _helpers)); }