예제 #1
0
            public string ToCSharp(TypeName javaType)              // java name could be ns-less, or even partial ("import foo.Bar;" + "Bar.Baz" => "foo.Bar.Baz")
            {
                string java   = javaType.ToJavaString();
                string suffix = javaType.ArrayDimension > 0 ? " []" : "";

                java = javaType.ArrayDimension > 0 ? java.Substring(0, java.Length - 3) : java;
                string cs;
                Func <string, string> filter = (ret) => ret == "sbyte []" ? "byte []" : ret;

                if (cache.TryGetValue(java, out cs))
                {
                    return(filter(cs + suffix));
                }
                if (IsSupportedPrimitiveJavaType(java))
                {
                    return(filter((java == "boolean" ? "bool" : java == "byte" ? "sbyte" : java) + suffix));
                }
                var javaFullName = ToFullJavaName(javaType);

                javaFullName = javaFullName.Substring(0, javaFullName.Length - suffix.Length);
                if (database.RegisteredTypes.TryGetValue(javaFullName, out cs))
                {
//Console.WriteLine ("Found in lookup " + javaFullName + " / " + cs);
                    cache [java] = cs;

                    return(filter(cs + suffix));
                }

                var p = parcelable_names.FirstOrDefault(pp => pp.ToJavaString() == javaFullName);

                if (p != null)
                {
                    var decentNS = GetCSharpNamespace(p);
                    var stupidNS = p.GetNamespace();
                    cache [java] = cs = (stupidNS != decentNS ? p.ToString().Replace(stupidNS, decentNS) : p.ToString());
//Console.WriteLine ("Found in parcelable lookup " + java + " / " + cs);
                    return(filter(cs + suffix));
                }

                string csns = javaFullName != java?GetCSharpNamespace(javaType) : String.Empty;

                cache [java] = cs = csns + (string.IsNullOrEmpty(csns) ? "" : ".") + javaType.Identifiers.Last();
//Console.WriteLine ("NOT Found in lookup " + java + " / " + cs);
                return(filter(cs + suffix));
            }
예제 #2
0
            public string ToFullJavaName(TypeName javaType)
            {
                string java   = javaType.ToJavaString();
                string suffix = javaType.ArrayDimension > 0 ? " []" : "";

                java = javaType.ArrayDimension > 0 ? java.Substring(0, java.Length - 3) : java;
                if (IsSupportedPrimitiveJavaType(java))
                {
                    return(java);
                }
                foreach (var imp in unit.Imports)
                {
                    int    idx  = java.IndexOf('.');
                    string head = idx < 0 ? java : java.Substring(0, idx);
                    if (imp.Identifiers.Length > 0 && head == imp.Identifiers.Last())
                    {
                        return(imp.ToJavaString() + (idx < 0 ? "" : java.Substring(idx)) + suffix);
                    }
                }
                // FIXME: implement lookup with wildcard import

                // not found.
                return((unit.Package != null ? unit.Package.ToJavaString() + '.' : null) + java + suffix);
            }
예제 #3
0
            public string ToCSharpNamespace(TypeName package)
            {
                string dummy, javapkg = package != null?package.ToJavaString() : String.Empty;

                return(package == null ? String.Empty : database.NamespaceMappings.TryGetValue(javapkg, out dummy) ? dummy : package.ToString());
            }
            public string ToFullJavaName(TypeName javaType)
            {
                string java = javaType.ToJavaString ();
                string suffix = javaType.ArrayDimension > 0 ? " []" : "";
                java = javaType.ArrayDimension > 0 ? java.Substring (0, java.Length - 3) : java;
                if (IsSupportedPrimitiveJavaType (java))
                    return java;
                foreach (var imp in unit.Imports) {
                    int idx = java.IndexOf ('.');
                    string head = idx < 0 ? java : java.Substring (0, idx);
                    if (imp.Identifiers.Length > 0 && head == imp.Identifiers.Last ())
                        return imp.ToJavaString () + (idx < 0 ? "" : java.Substring (idx)) + suffix;
                }
                // FIXME: implement lookup with wildcard import

                // not found.
                return (unit.Package != null ? unit.Package.ToJavaString () + '.' : null) + java + suffix;
            }
 public string ToCSharpNamespace(TypeName package)
 {
     string dummy, javapkg = package != null ? package.ToJavaString () : String.Empty;
     return package == null ? String.Empty : database.NamespaceMappings.TryGetValue (javapkg, out dummy) ? dummy : package.ToString ();
 }
            // java name could be ns-less, or even partial ("import foo.Bar;" + "Bar.Baz" => "foo.Bar.Baz")
            public string ToCSharp(TypeName javaType)
            {
                string java = javaType.ToJavaString ();
                string suffix = javaType.ArrayDimension > 0 ? " []" : "";
                java = javaType.ArrayDimension > 0 ? java.Substring (0, java.Length - 3) : java;
                string cs;
                Func<string,string> filter = (ret) => ret == "sbyte []" ? "byte []" : ret;

                if (cache.TryGetValue (java, out cs))
                    return filter (cs + suffix);
                if (IsSupportedPrimitiveJavaType (java))
                    return filter ((java == "boolean" ? "bool" : java == "byte" ? "sbyte" : java) + suffix);
                var javaFullName = ToFullJavaName (javaType);
                javaFullName = javaFullName.Substring (0, javaFullName.Length - suffix.Length);
                if (database.RegisteredTypes.TryGetValue (javaFullName, out cs)) {
                //Console.WriteLine ("Found in lookup " + javaFullName + " / " + cs);
                    cache [java] = cs;

                    return filter (cs + suffix);
                }

                var p = parcelable_names.FirstOrDefault (pp => pp.ToJavaString () == javaFullName);
                if (p != null) {
                    var decentNS = GetCSharpNamespace (p);
                    var stupidNS = p.GetNamespace ();
                    cache [java] = cs = (stupidNS != decentNS ? p.ToString ().Replace (stupidNS, decentNS) : p.ToString ());
                //Console.WriteLine ("Found in parcelable lookup " + java + " / " + cs);
                    return filter (cs + suffix);
                }

                string csns = javaFullName != java ? GetCSharpNamespace (javaType) : String.Empty;
                cache [java] = cs = csns + (string.IsNullOrEmpty (csns) ? "" : ".") + javaType.Identifiers.Last ();
                //Console.WriteLine ("NOT Found in lookup " + java + " / " + cs);
                return filter (cs + suffix);
            }