Ejemplo n.º 1
0
        public static Field CreateField(XElement elem)
        {
            var field = new Field {
                DeprecatedComment = elem.XGetAttribute("deprecated"),
                IsAcw             = true,
                IsDeprecated      = elem.XGetAttribute("deprecated") != "not deprecated",
                IsDeprecatedError = elem.XGetAttribute("deprecated-error") == "true",
                IsFinal           = elem.XGetAttribute("final") == "true",
                IsStatic          = elem.XGetAttribute("static") == "true",
                JavaName          = elem.XGetAttribute("name"),
                NotNull           = elem.XGetAttribute("not-null") == "true",
                SetterParameter   = CreateParameter(elem),
                TypeName          = elem.XGetAttribute("type"),
                Value             = elem.XGetAttribute("value"),      // do not trim
                Visibility        = elem.XGetAttribute("visibility")
            };

            field.SetterParameter.Name = "value";

            if (elem.XGetAttribute("enumType") != null)
            {
                field.IsEnumified = true;
                field.TypeName    = elem.XGetAttribute("enumType");
            }

            if (elem.Attribute("managedName") != null)
            {
                field.Name = elem.XGetAttribute("managedName");
            }
            else
            {
                field.Name = TypeNameUtilities.StudlyCase(char.IsLower(field.JavaName [0]) || field.JavaName.ToLowerInvariant().ToUpperInvariant() != field.JavaName ? field.JavaName : field.JavaName.ToLowerInvariant());
                field.Name = EnsureValidIdentifer(field.Name);
            }

            return(field);
        }
Ejemplo n.º 2
0
 public string[] PreCallback(CodeGenerationOptions opt, string var_name, bool owned)
 {
     return(new string[] { String.Format("var {1} = ({0}[]{4}) global::Java.Util.InteroperableArrays.GetArray<{3}> ({2}, JniHandleOwnership.DoNotTransfer);", opt.GetOutputName(ElementType), opt.GetSafeIdentifier(var_name), opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)), opt.GetOutputName(sym.FullName), opt.NullableOperator) });
 }
Ejemplo n.º 3
0
 public string[] PostCallback(CodeGenerationOptions opt, string var_name)
 {
     string[] result = new string [2];
     result [0] = String.Format("if ({0} != null)", opt.GetSafeIdentifier(var_name));
     result [1] = String.Format("\tglobal::Java.Util.InteroperableArrays.ArrayCopy({0}, {1});", opt.GetSafeIdentifier(var_name), opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)));
     return(result);
 }
Ejemplo n.º 4
0
        public ISymbol Lookup(string java_type, GenericParameterDefinitionList in_params)
        {
            string type_params;
            int    arrayRank;
            bool   has_ellipsis;
            string key = GetSymbolInfo(java_type, out type_params, out arrayRank, out has_ellipsis);

            // FIXME: we should make sure to differentiate those ref types IF we use those modifiers in the future.
            switch (key [key.Length - 1])
            {
            case '&':             // managed ref type
            case '*':             // managed (well, unmanaged...) pointer type
                key = key.Substring(0, key.Length - 1);
                break;
            }
            key = TypeNameUtilities.FilterPrimitiveFullName(key) ?? key;

            switch (key)
            {
            case "android.content.res.XmlResourceParser":
                return(CreateArray(xmlresourceparser_sym, arrayRank, has_ellipsis));

            case "org.xmlpull.v1.XmlPullParser":
                return(CreateArray(xmlpullparser_sym, arrayRank, has_ellipsis));

            case "java.io.FileInputStream":
                return(CreateArray(fileinstream_sym, arrayRank, has_ellipsis));

            case "java.io.FileOutputStream":
                return(CreateArray(fileoutstream_sym, arrayRank, has_ellipsis));

            case "java.io.InputStream":
                return(CreateArray(instream_sym, arrayRank, has_ellipsis));

            case "java.io.OutputStream":
                return(CreateArray(outstream_sym, arrayRank, has_ellipsis));

            case "java.lang.CharSequence":
                return(CreateArray(char_seq, arrayRank, has_ellipsis));

            case "java.lang.String":
                return(CreateArray(string_sym, arrayRank, has_ellipsis));

            case "java.util.List":
            case "java.util.ArrayList":
            case "System.Collections.IList":
                return(CreateArray(new CollectionSymbol(key, "IJavaList", "JavaList", type_params), arrayRank, has_ellipsis));

            case "java.util.Map":
            case "java.util.HashMap":
            case "java.util.SortedMap":
            case "System.Collections.IDictionary":
                return(CreateArray(new CollectionSymbol(key, "IJavaDictionary", "JavaDictionary", type_params), arrayRank, has_ellipsis));

            case "java.util.Set":
                return(CreateArray(new CollectionSymbol(key, "IJavaCollection", "JavaSet", type_params), arrayRank, has_ellipsis));

            case "java.util.Collection":
            case "System.Collections.ICollection":
                return(CreateArray(new CollectionSymbol(key, "IJavaCollection", "JavaCollection", type_params), arrayRank, has_ellipsis));

            default:
                break;
            }

            ISymbol result;
            var     gpd = in_params != null?in_params.FirstOrDefault(t => t.Name == key) : null;

            if (gpd != null)
            {
                result = new GenericTypeParameter(gpd);
            }
            else
            {
                result = Lookup(key + type_params);
            }

            return(CreateArray(result, arrayRank, has_ellipsis));
        }
Ejemplo n.º 5
0
 public string[] PreCallback(CodeGenerationOptions opt, string var_name, bool owned)
 {
     return(new string[] { String.Format("var {0} = JniEnvironment.Strings.ToString ({1});", opt.GetSafeIdentifier(var_name), opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name))) });
 }
 public string[] PreCallback(CodeGenerationOptions opt, string var_name, bool owned)
 {
     return(new string[] { String.Format("var {0} = global::Android.Runtime.XmlResourceParserReader.FromJniHandle ({1}, JniHandleOwnership.DoNotTransfer);", opt.GetSafeIdentifier(var_name), opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name))) });
 }
 public string Call(CodeGenerationOptions opt, string var_name)
 {
     return(opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)));
 }
 public string[] PreCallback(CodeGenerationOptions opt, string var_name, bool owned)
 {
     return(new string[] { String.Format("global::Java.Lang.ICharSequence {0} = global::Java.Lang.Object.GetObject<global::Java.Lang.ICharSequence> ({1}, JniHandleOwnership.DoNotTransfer);", var_name, TypeNameUtilities.GetNativeName(var_name)) });
 }
Ejemplo n.º 9
0
 public string[] PreCallback(CodeGenerationOptions opt, string var_name, bool owned)
 {
     return(new string[] { String.Format("string {0} = JNIEnv.GetString ({1}, JniHandleOwnership.DoNotTransfer);", opt.GetSafeIdentifier(var_name), opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name))) });
 }
Ejemplo n.º 10
0
 public string[] PreCallback(CodeGenerationOptions opt, string var_name, bool owned)
 {
     return(new string[] { String.Format("var {1} = ({0}[]) JNIEnv.GetArray ({2}, JniHandleOwnership.DoNotTransfer, typeof ({3}));", opt.GetOutputName(ElementType), opt.GetSafeIdentifier(var_name), opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)), opt.GetOutputName(sym.FullName)) });
 }
Ejemplo n.º 11
0
 public string[] PostCallback(CodeGenerationOptions opt, string var_name)
 {
     string[] result = new string [2];
     result [0] = String.Format("if ({0} != null)", opt.GetSafeIdentifier(var_name));
     result [1] = String.Format("\tJNIEnv.CopyArray ({0}, {1});", opt.GetSafeIdentifier(var_name), opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)));
     return(result);
 }
Ejemplo n.º 12
0
        public string[] PreCall(CodeGenerationOptions opt, string var_name)
        {
            string managed_name = opt.GetSafeIdentifier(var_name);
            string native_name  = opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name));

            if (opt.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1)
            {
                return(new[] {
                    $"var {native_name} = global::{GetJavaInterop1MarshalMethod ()} ({managed_name});",
                });
            }
            return(new string[] { String.Format("IntPtr {0} = JNIEnv.NewArray ({1});", opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)), opt.GetSafeIdentifier(var_name)) });
        }
Ejemplo n.º 13
0
 public string ToInteroperableJavaObject(string var_name)
 {
     return(GetGenericJavaObjectTypeOverride() != null?TypeNameUtilities.GetNativeName(var_name) : var_name);
 }
Ejemplo n.º 14
0
 public string[] PreCall(CodeGenerationOptions opt, string var_name)
 {
     return(new string[] { String.Format("JniObjectReference {0} = JniEnvironment.Strings.NewString ({1});", opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)), opt.GetSafeIdentifier(var_name)) });
 }
Ejemplo n.º 15
0
 public string[] PreCall(CodeGenerationOptions opt, string var_name)
 {
     return(new string[] { String.Format("var {0} = global::Java.Util.InteroperableArrays.NewArray ({1});", opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)), opt.GetSafeIdentifier(var_name)) });
 }
Ejemplo n.º 16
0
        public static Parameter CreateParameter(XElement elem)
        {
            string managedName = elem.XGetAttribute("managedName");
            string name        = !string.IsNullOrEmpty(managedName) ? managedName : EnsureValidIdentifer(TypeNameUtilities.MangleName(elem.XGetAttribute("name")));
            string java_type   = elem.XGetAttribute("type");
            string enum_type   = elem.Attribute("enumType") != null?elem.XGetAttribute("enumType") : null;

            string managed_type = elem.Attribute("managedType") != null?elem.XGetAttribute("managedType") : null;

            // FIXME: "enum_type ?? java_type" should be extraneous. Somewhere in generator uses it improperly.
            var result = new Parameter(name, enum_type ?? java_type, enum_type ?? managed_type, enum_type != null, java_type);

            if (elem.Attribute("sender") != null)
            {
                result.IsSender = true;
            }
            return(result);
        }
Ejemplo n.º 17
0
 public string[] PreCall(CodeGenerationOptions opt, string var_name)
 {
     return(new string[] { String.Format("IntPtr {0} = JNIEnv.NewString ({1});", opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)), opt.GetSafeIdentifier(var_name)) });
 }
 public string[] PreCall(CodeGenerationOptions opt, string var_name)
 {
     return(new string[] { String.Format("IntPtr {0} = CharSequence.ToLocalJniHandle ({1});", opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)), opt.GetSafeIdentifier(var_name)) });
 }
Ejemplo n.º 19
0
 public string GetGenericJavaObjectTypeOverride()
 {
     return(TypeNameUtilities.GetGenericJavaObjectTypeOverride(managed_name, parms != null ? parms.ToString() : null));
 }
Ejemplo n.º 20
0
 public string[] PostCall(CodeGenerationOptions opt, string var_name)
 {
     return(new string [] {
         string.Format("JNIEnv.DeleteLocalRef ({0});", opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name))),
     });
 }
Ejemplo n.º 21
0
 public string ToInteroperableJavaObject(string var_name)
 {
     return(TypeNameUtilities.GetNativeName(var_name));
 }
Ejemplo n.º 22
0
 public string[] PreCall(CodeGenerationOptions opt, string var_name)
 {
     return(new string[] { String.Format("IntPtr {0} = global::Android.Runtime.XmlReaderResourceParser.ToLocalJniHandle ({1});", opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name)), opt.GetSafeIdentifier(var_name)) });
 }
Ejemplo n.º 23
0
 public string[] PostCall(CodeGenerationOptions opt, string var_name)
 {
     return(new string[] {
         string.Format("JniObjectReference.Dispose (ref {0}, JniObjectReferenceOptions.CopyAndDispose);", opt.GetSafeIdentifier(TypeNameUtilities.GetNativeName(var_name))),
     });
 }