Esempio n. 1
0
        public UmlAttribute(Tag tag, UmlClass classobj)
            : base(tag)
        {
            type = tag.ParseType();

            commentsKey = Comments.Key(classobj.Name, name);
        }
Esempio n. 2
0
        public IEnumerable <IUmlObject> Parse(IEnumerable <string> lines)
        {
            char[] chars = StripComments(lines).Where(FilterEmptyLines).ToCharacters().ToArray();

            int i = 0;

            CSharpBlock[] blocks = Parse(chars, ref i);
            foreach (CSharpBlock np in blocks)
            {
                if (np.Name.Contains("namespace"))
                {
                    foreach (CSharpBlock block in np.Content)
                    {
                        if (UmlClass.Matches(block))
                        {
                            yield return(new UmlClass(block));
                        }
                        else if (UmlEnum.Matches(block))
                        {
                            yield return(new UmlEnum(block));
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public UmlMethod(Tag tag, UmlClass classobj)
            : base(tag)
        {
            Tag[] paramtags = VSParser.ExtractTags(ref tag.Content, "parameter");

            returntype = "void";

            List <string> parameterlist = new List <string> ();

            foreach (Tag proptag in paramtags)
            {
                string type = proptag.ParseType();
                if (proptag.Params.ContainsKey("direction") && proptag.Params ["direction"].ToLower() == "return")
                {
                    returntype = type;
                }
                else
                {
                    if (type == "void")
                    {
                        parameterlist.Add(proptag.Name);
                    }
                    else
                    {
                        parameterlist.Add(type + " " + proptag.Name);
                    }
                }
            }
            parameters = parameterlist.ToArray();

            commentsKey = Comments.Key(classobj.Name, name, parameters.Unique() + returntype);
        }
Esempio n. 4
0
        public UmlMethod(CSharpBlock block, UmlClass classobj)
            : base(block)
        {
            parseParams();

            if (name.Contains(" "))
            {
                string[] p = name.CleanGenerics()
                             .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                returntype = p [0];
                name       = "";
                for (int i = 0; i < p.Length; ++i)
                {
                    name += i == 0 ? "" : " " + p [i];
                }
            }
            if (name == "")
            {
                name       = returntype;
                returntype = "";
            }
            if (returntype == "void")
            {
                returntype = "";
            }
            name = name.TrimAll();

            commentsKey = Comments.Key(classobj.Name, name, parameters.Unique() + returntype);
        }
Esempio n. 5
0
        public UmlAttribute(UmlBlock block, UmlClass classobj)
            : base(block)
        {
            if (name.Contains(":"))
            {
                string[] p = name.Split(":").TrimAll().ToArray();
                name = p [0];
                type = p [1];
            }

            Comments.AddTo(commentsKey = Comments.Key(classobj.Name, name), block.comments);
        }
Esempio n. 6
0
        public string ToCSharpCode(int padding, Virtuality virt, UmlClass inClass)
        {
            if (virt == CSharpUML.Virtuality.None)
            {
                virt = Virtuality;
            }
            string        paddingStr = String.Concat(Enumerable.Repeat(" ", padding));
            List <string> lines      = new List <string> ();

            lines.AddRange(Comments.CSharpComments(commentsKey, paddingStr));
            string uml = paddingStr
                         + ((inClass != null && inClass.type == ClassType.Interface)
                ? ""
                : Publicity.ToCode("", " ") + Virtuality.ToCode("", " "));

            uml += type.ToCSharpType() + " " + name + " { get; set; }";
            lines.Add(uml);
            return(string.Join("\n", lines));
        }
Esempio n. 7
0
        public UmlMethod(UmlBlock block, UmlClass classobj)
            : base(block)
        {
            parseParams();

            if (name.Contains(":"))
            {
                string[] p = name.Split(":").TrimAll().ToArray();
                name       = p [0];
                returntype = p [1];
            }
            else
            {
                returntype = "";
            }

            Comments.AddTo(commentsKey = Comments.Key(classobj.Name, name, parameters.Unique() + returntype),
                           block.comments);
        }
Esempio n. 8
0
        public UmlAttribute(CSharpBlock block, UmlClass classobj)
            : base(block)
        {
            name = name.Split('=') [0].TrimAll();

            if (name.Contains(" "))
            {
                string[] p = name.CleanGenerics()
                             .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                type = p [0];
                name = "";
                for (int i = 0; i < p.Length; ++i)
                {
                    name += i == 0 ? "" : " " + p [i];
                }
            }
            name = name.TrimAll();

            commentsKey = Comments.Key(classobj.Name, name);
        }
Esempio n. 9
0
        public IEnumerable <IUmlObject> Parse(IEnumerable <string> lines)
        {
            if (lines.Count() > 0)
            {
                int        i      = 0;
                UmlBlock[] blocks = ParseBlocks(lines.Where(FilterIgnoreLines).ToArray(), ref i, -1);

                foreach (UmlBlock block in blocks)
                {
                    if (UmlClass.Matches(block))
                    {
                        yield return(new UmlClass(block));
                    }
                    else if (UmlEnum.Matches(block))
                    {
                        yield return(new UmlEnum(block));
                    }
                }
            }
        }
Esempio n. 10
0
        public static void From(IUmlObject[] objects, out List <Inheritance> inhs, out List <string> unknownObjects)
        {
            Dictionary <string, IUmlObject> names = new Dictionary <string, IUmlObject> ();

            foreach (IUmlObject obj in objects)
            {
                names [obj.Name.Clean().ToLower()] = obj;
            }

            inhs           = new List <Inheritance> ();
            unknownObjects = new List <string> ();

            foreach (IUmlObject obj in objects)
            {
                if (obj is UmlClass)
                {
                    UmlClass cl = obj as UmlClass;
                    foreach (string _basename in cl.bases)
                    {
                        string basename = _basename.ToCSharpType();
                        // Console.WriteLine("basename="+basename);
                        IUmlObject baseobj;
                        if (names.ContainsKey(basename.Clean().ToLower()))
                        {
                            baseobj = names [basename.Clean().ToLower()];
                        }
                        else
                        {
                            baseobj = new UmlClass(new UmlBlock(name: "+ " + basename, comments: new string[] {}));
                            unknownObjects.Add(basename);
                        }
                        Inheritance inh = new Inheritance(baseobj: baseobj, derivedobj: obj);
                        if (!inhs.Contains(inh))
                        {
                            inhs.Add(inh);
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        public string ToCSharpCode(int padding, Virtuality virt, UmlClass inClass)
        {
            if (virt == CSharpUML.Virtuality.None)
            {
                virt = Virtuality;
            }
            string        paddingStr = String.Concat(Enumerable.Repeat(" ", padding));
            List <string> lines      = new List <string> ();

            lines.AddRange(Comments.CSharpComments(commentsKey, paddingStr));
            string uml = paddingStr;

            // public, virtual
            string _keywords = Comments.GetCommentParameter(commentsKey, "keywords");

            if (_keywords != null)
            {
                uml += _keywords.TrimAll().ToCode("", " ");
            }
            else if (inClass != null && inClass.type == ClassType.Interface)
            {
                uml += "";
            }
            else
            {
                uml += Publicity.ToCode("", " ") + virt.ToCode("", " ");
            }

            // return type
            string _returntype = Comments.GetCommentParameter(commentsKey, "returntype");

            if (_returntype != null)
            {
                uml += _returntype.ToCSharpType() + " ";
            }
            else if (IsContructor)
            {
                uml += "";
            }
            else if (returntype.Length > 0)
            {
                uml += returntype.ToCSharpType().ToCode("", " ");
            }
            else
            {
                uml += "void ";
            }

            // name
            string _name = Comments.GetCommentParameter(commentsKey, "name");

            if (_name != null)
            {
                uml += _name;
            }
            else
            {
                uml += name;
            }

            // index operator [ ]
            if (name == "this")
            {
                uml += " [" + string.Join(", ", parameters) + "]";
                lines.Add(uml);
                lines.Add(paddingStr + "{");
                lines.Add(paddingStr + "    " + "get { throw new System.NotImplementedException(); }");
                lines.Add(paddingStr + "    " + "set { throw new System.NotImplementedException(); }");
                lines.Add(paddingStr + "}");
            }
            // normal method
            else
            {
                uml += " (";
                string _parameters = Comments.GetCommentParameter(commentsKey, "parameters");
                if (_parameters != null)
                {
                    uml += _parameters;
                }
                else
                {
                    for (int i = 0; i < parameters.Length; ++i)
                    {
                        if (i > 0)
                        {
                            uml += ", ";
                        }
                        if (parameters [i].Contains(" "))
                        {
                            String[] p = parameters [i].Split(new char[] { ' ' }, 2);
                            uml += p [0].ToCSharpType() + " " + p [1];
                        }
                        else
                        {
                            uml += parameters [i].ToCSharpType() + " " + parameters [i].ToLower();
                        }
                    }
                }
                uml += ")";
                if (uml.Contains("ModelFactory") && uml.Contains("Func<"))
                {
                    uml = paddingStr + "public ModelFactory (Func<GameScreen, GameModelInfo, GameModel> createModel)";
                }

                string _base = Comments.GetCommentParameter(commentsKey, "base");
                if (_base != null)
                {
                    uml += "\n" + paddingStr + "    : base(" + _base.TrimAll() + ")";
                }

                if (inClass.type == ClassType.Interface)
                {
                    lines.Add(uml + ";");
                }
                else
                {
                    lines.Add(uml);
                    lines.Add(paddingStr + "{");
                    lines.Add(paddingStr + "    " + "throw new System.NotImplementedException();");
                    lines.Add(paddingStr + "}");
                }
            }
            return(string.Join("\n", lines));
        }