public void GenerateCode(CompilationUnit unit, IList<TypeName> parcelableNames, ConverterOptions opts)
        {
            w.WriteLine ("// This file is automatically generated and not supposed to be modified.");
            w.WriteLine ("using System;");
            w.WriteLine ("using Boolean = System.Boolean;");
            w.WriteLine ("using String = System.String;");
            w.WriteLine ("using List = Android.Runtime.JavaList;");
            w.WriteLine ("using Map = Android.Runtime.JavaDictionary;");

            this.unit = unit;
            name_cache = new NameResoltionCache (database, unit, parcelableNames);
            self_ns = name_cache.ToCSharpNamespace (unit.Package);

            if (unit.Imports != null) {
                var nss = new List<string> ();
                foreach (var imp in unit.Imports) {
                    string dummy, pkg = imp.GetPackage ();
                    string ns = database.NamespaceMappings.TryGetValue (pkg, out dummy) ? dummy : imp.GetNamespace ();
                    if (nss.Contains (ns))
                        continue;
                    nss.Add (ns);
                    w.WriteLine ("using " + ns + ";");
                }
            }
            if (unit.Package != null) {
                w.WriteLine ();
                w.WriteLine ("namespace {0}", self_ns);
                w.WriteLine ("{");
            }

            foreach (var type in unit.Types) {
                if (type is Parcelable) {
                    if (type is Parcelable) {
                        switch (opts.ParcelableHandling) {
                        case ParcelableHandling.Ignore:
                            continue;
                        case ParcelableHandling.Error:
                            throw new InvalidOperationException ("Parcelable AIDL cannot be converted to C#");
                        case ParcelableHandling.Stub:
                            StubParcelable ((Parcelable) type);
                            break;
                        }
                    }
                }
                else if (type is Interface)
                    GenerateCode ((Interface) type);
            }

            if (unit.Package != null)
                w.WriteLine ("}");

            this.unit = null;
        }
예제 #2
0
        string ToOutputTypeName(string name)
        {
            if (cs_units == null)
            {
                cs_units = unit.Package == null ? new string [0] : name_cache.ToCSharpNamespace(unit.Package).Split('.');
            }
            int idx = name.IndexOf('.');

            if (idx < 0)
            {
                return(name);
            }
            if (Array.IndexOf(cs_units, name.Substring(0, idx)) < 0)
            {
                return(name);
            }
            return("global::" + name);
        }
예제 #3
0
        public void GenerateCode(CompilationUnit unit, IList <TypeName> parcelableNames, ConverterOptions opts)
        {
            w.WriteLine("// This file is automatically generated and not supposed to be modified.");
            w.WriteLine("using System;");
            w.WriteLine("using Boolean = System.Boolean;");
            w.WriteLine("using String = System.String;");
            w.WriteLine("using List = Android.Runtime.JavaList;");
            w.WriteLine("using Map = Android.Runtime.JavaDictionary;");

            this.unit  = unit;
            name_cache = new NameResoltionCache(database, unit, parcelableNames);
            self_ns    = name_cache.ToCSharpNamespace(unit.Package);

            if (unit.Imports != null)
            {
                var nss = new List <string> ();
                foreach (var imp in unit.Imports)
                {
                    string dummy, pkg = imp.GetPackage();
                    string ns = database.NamespaceMappings.TryGetValue(pkg, out dummy) ? dummy : imp.GetNamespace();
                    if (nss.Contains(ns))
                    {
                        continue;
                    }
                    nss.Add(ns);
                    w.WriteLine("using " + ns + ";");
                }
            }
            if (unit.Package != null)
            {
                w.WriteLine();
                w.WriteLine("namespace {0}", self_ns);
                w.WriteLine("{");
            }

            foreach (var type in unit.Types)
            {
                if (type is Parcelable)
                {
                    if (type is Parcelable)
                    {
                        switch (opts.ParcelableHandling)
                        {
                        case ParcelableHandling.Ignore:
                            continue;

                        case ParcelableHandling.Error:
                            throw new InvalidOperationException("Parcelable AIDL cannot be converted to C#");

                        case ParcelableHandling.Stub:
                            StubParcelable((Parcelable)type);
                            break;
                        }
                    }
                }
                else if (type is Interface)
                {
                    GenerateCode((Interface)type);
                }
            }

            if (unit.Package != null)
            {
                w.WriteLine("}");
            }

            this.unit = null;
        }