WhatItIs() public static method

public static WhatItIs ( MsgsFile parent, string s, string extraindent ) : SingleType
parent MsgsFile
s string
extraindent string
return SingleType
Beispiel #1
0
 MsgsFile(string filename, bool isrequest, List <string> lines, string extraindent)
 {
     if (resolver == null)
     {
         resolver = new Dictionary <string, List <string> >();
     }
     serviceMessageType = isrequest ? ServiceMessageType.Request : ServiceMessageType.Response;
     filename           = filename.Replace(".srv", ".msg");
     if (!filename.Contains(".msg"))
     {
         throw new Exception("" + filename + " IS NOT A VALID SRV FILE!");
     }
     string[] sp = filename.Replace(Program.inputdir, "").Replace(".msg", "").Split('\\');
     classname  = sp[sp.Length - 1];
     Namespace += "." + filename.Replace(Program.inputdir, "").Replace(".msg", "");
     Namespace  = Namespace.Replace("\\", ".").Replace("..", ".");
     string[] sp2 = Namespace.Split('.');
     Namespace = "";
     for (int i = 0; i < sp2.Length - 2; i++)
     {
         Namespace += sp2[i] + ".";
     }
     Namespace += sp2[sp2.Length - 2];
     //THIS IS BAD!
     classname  = classname.Replace("/", ".");
     Name       = Namespace.Replace("Messages", "").TrimStart('.') + "." + classname;
     Name       = Name.TrimStart('.');
     classname  = Name.Split('.').Length > 1 ? Name.Split('.')[1] : Name;
     classname += (isrequest ? "Request" : "Response");
     Namespace  = Namespace.Trim('.');
     def        = new List <string>();
     for (int i = 0; i < lines.Count; i++)
     {
         if (lines[i].Trim().Length == 0)
         {
             continue;
         }
         def.Add(lines[i]);
         if (Name.ToLower() == "string")
         {
             lines[i].Replace("String", "string");
         }
         SingleType test = KnownStuff.WhatItIs(this, lines[i], extraindent);
         if (test != null)
         {
             Stuff.Add(test);
         }
     }
 }
Beispiel #2
0
        public void ParseAndResolveTypes()
        {
            def   = new List <string>();
            Stuff = new List <SingleType>();
            foreach (var l in lines)
            {
                if (string.IsNullOrWhiteSpace(l))
                {
                    continue;
                }

                def.Add(l);
                SingleType test = KnownStuff.WhatItIs(this, l, extraindent);
                if (test != null)
                {
                    Stuff.Add(test);
                }
            }
        }
Beispiel #3
0
        public static void Resolve(MsgFile parent, SingleType st)
        {
            if (st.Type == null)
            {
                KnownStuff.WhatItIs(parent, st);
            }

            if (st.IsPrimitve)
            {
                return;
            }

            List <string> prefixes = new List <string>(new[] { "", "std_msgs", "geometry_msgs", "actionlib_msgs" });

            if (st.Type.Contains("/"))
            {
                string[] pieces = st.Type.Split('/');
                st.Package = pieces[0];
                st.Type    = pieces[1];
            }

            prefixes[0] = !string.IsNullOrEmpty(st.Package) ? st.Package : parent.Package;
            foreach (string p in prefixes)
            {
                if (resolver.Keys.Contains(p))
                {
                    if (resolver[p].ContainsKey(st.Type))
                    {
                        if (resolver[p][st.Type].Count == 1)
                        {
                            st.Package = p;
                            st.Definer = resolver[p][st.Type][0].Definer;
                        }
                        else if (resolver[p][st.Type].Count > 1)
                        {
                            throw new ArgumentException($"Could not resolve: {st.Type}");
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public MsgsFile(string filename, string extraindent)
        {
            if (resolver == null)
            {
                resolver = new Dictionary <string, List <string> >();
            }
            if (!filename.Contains(".msg"))
            {
                throw new Exception("" + filename + " IS NOT A VALID MSG FILE!");
            }
            string[] sp = filename.Replace(Program.inputdir, "").Replace(".msg", "").Split('\\');
            classname  = sp[sp.Length - 1];
            Namespace += "." + filename.Replace(Program.inputdir, "").Replace(".msg", "");
            Namespace  = Namespace.Replace("\\", ".").Replace("..", ".");
            string[] sp2 = Namespace.Split('.');
            Namespace = "";
            for (int i = 0; i < sp2.Length - 2; i++)
            {
                Namespace += sp2[i] + ".";
            }
            Namespace += sp2[sp2.Length - 2];
            //THIS IS BAD!
            classname = classname.Replace("/", ".");
            Name      = Namespace.Replace("Messages", "").TrimStart('.') + "." + classname;
            Name      = Name.TrimStart('.');
            classname = Name.Split('.').Length > 1 ? Name.Split('.')[1] : Name;
            Namespace = Namespace.Trim('.');
            if (!resolver.Keys.Contains(classname) && Namespace != "Messages.std_msgs")
            {
                resolver.Add(classname, new List <string> {
                    Namespace + "." + classname
                });
            }
            else if (Namespace != "Messages.std_msgs")
            {
                resolver[classname].Add(Namespace + "." + classname);
            }
            List <string> lines = new List <string>(File.ReadAllLines(filename));

            lines = lines.Where(st => (!st.Contains('#') || st.Split('#')[0].Length != 0)).ToList();
            for (int i = 0; i < lines.Count; i++)
            {
                lines[i] = lines[i].Split('#')[0].Trim();
            }
            //lines = lines.Where((st) => (st.Length > 0)).ToList();

            lines.ForEach(s =>
            {
                if (s.Contains('#') && s.Split('#')[0].Length != 0)
                {
                    s = s.Split('#')[0];
                }
                if (s.Contains('#'))
                {
                    s = "";
                }
            });
            lines = lines.Where(st => (st.Length > 0)).ToList();


            def = new List <string>();
            for (int i = 0; i < lines.Count; i++)
            {
                def.Add(lines[i]);
                if (Name.ToLower() == "string")
                {
                    lines[i].Replace("String", "string");
                }
                SingleType test = KnownStuff.WhatItIs(this, lines[i], extraindent);
                if (test != null)
                {
                    Stuff.Add(test);
                }
            }
        }