Exemplo n.º 1
0
        public static TypeReference MapDatatype(TypeReference t)
        {
            var m = t.MemberOf;
            var g = t.Container;
            t = t.Clone() as TypeReference;
            t.MemberOf = m;
            t.Container = g;
            TypeReference retVal = t.Clone() as TypeReference;

            // Create a type reference
            var type = s_heuristicData.Datatypes.Find(o => o.MifDatatype == t.Name + (t.Flavor != null ? "." + t.Flavor : ""));

            if(type == null && !String.IsNullOrEmpty(t.Flavor ))
                type = s_heuristicData.Datatypes.Find(o => o.MifDatatype == t.Name);

            if (t is TypeParameter)
                return t;
            else if (t.Name == null)
                retVal.Name = "java.lang.Object";
            else if (type != null)
            {
                retVal.Name = type.JavaType;
                //if (!String.IsNullOrEmpty(type.TemplateParameter))
                //    retVal.Name = String.Format("{0}.datatypes.generic.{1}", s_apiNs, retVal.Name);
                //else
                //    retVal.Name = String.Format("{0}.datatypes.{1}", s_apiNs, retVal.Name);

                retVal.MemberOf = t.MemberOf;
                retVal.GenericSupplier = t.GenericSupplier;

                if (t.Name != retVal.Name)
                    retVal.Flavor = null; // Clear flavors if pointing to a new type

                // Default binding information
                var tParm = type.DefaultBind;
                if ((t.GenericSupplier == null || t.GenericSupplier.Count == 0) && !String.IsNullOrEmpty(tParm))
                {
                    retVal.AddGenericSupplier("def", MapDatatype(new TypeReference() { Name = tParm }));
                }

            }
            // Default member?
            return retVal;

        }
Exemplo n.º 2
0
        public static TypeReference MapDatatype(TypeReference t)
        {

            var m = t.MemberOf;
            var g = t.Container;
            TypeReference retVal = t.Clone() as TypeReference;
            retVal.MemberOf = m;
            retVal.Container = g;

            if (t is TypeParameter)
                return t;
            else if (t.Name == null)
                retVal.Name = "System.Object";
            else if (flavMaps.ContainsKey(t.Name + "." + t.Flavor))
            {
                // Create a type reference
                Type type = flavMaps[t.Name + "." + t.Flavor];
                retVal.Name = type.Name;
                if (type.IsInterface)
                    retVal.Name = type.FullName;

                if (retVal.Name.Contains("`"))
                    retVal.Name = retVal.Name.Substring(0, retVal.Name.IndexOf("`"));
                retVal.MemberOf = t.MemberOf;
                retVal.GenericSupplier = t.GenericSupplier;

                if (t.Name != retVal.Name)
                    retVal.Flavor = null; // Clear flavors if pointing to a new type
            }
            else if (typeMaps.ContainsKey(String.Format("{0}#{1}", t.Name, t.GenericSupplier != null && t.GenericSupplier.Count > 0 ? t.GenericSupplier[0].Name : null))) // Maps types 
            {
                Type type = typeMaps[String.Format("{0}#{1}", t.Name, t.GenericSupplier != null && t.GenericSupplier.Count > 0 ? t.GenericSupplier[0].Name : null)];
                retVal.Name = type.Name;
                if (type.IsInterface)
                    retVal.Name = type.FullName;
                if (retVal.Name.Contains("`"))
                    retVal.Name = retVal.Name.Substring(0, retVal.Name.IndexOf("`"));
                retVal.MemberOf = t.MemberOf;

                if (type.IsGenericTypeDefinition)
                    retVal.GenericSupplier = t.GenericSupplier;
                else
                    retVal.GenericSupplier = null;

            }
            else if(typeMaps.ContainsKey(String.Format("{0}#", t.Name))) // Maps types 
            {
                Type type = typeMaps[String.Format("{0}#", t.Name)];
                retVal.Name = type.Name;
                if (type.IsInterface)
                    retVal.Name = type.FullName;
                if (retVal.Name.Contains("`"))
                    retVal.Name = retVal.Name.Substring(0, retVal.Name.IndexOf("`"));
                retVal.MemberOf = t.MemberOf;
                retVal.GenericSupplier = t.GenericSupplier;

            }

            // Type parm info
            var tParm = defaultTypeParms.Find(o => o.StructureAttribute.Name.Equals(t.Name));
            if (tParm != null && (t.GenericSupplier == null || t.GenericSupplier.Count == 0) && tParm.DefaultTypeParameter != null)
            {
                // Create the type parm
                var staParm = tParm.DefaultTypeParameter.GetCustomAttributes(typeof(StructureAttribute), false);
                for(int i = 0; i < tParm.Type.GetGenericArguments().Length; i++)
                    if (staParm.Length > 0)
                        retVal.AddGenericSupplier(i.ToString(), MapDatatype(new TypeReference() { Name = (staParm[0] as StructureAttribute).Name }));
                    else
                        retVal.AddGenericSupplier(i.ToString(), new TypeReference() { Name = tParm.DefaultTypeParameter.FullName });
            }
            
            // Default member?
            return retVal;
        }