Exemple #1
0
        public static List <ConvertedClass> readClass(string p)
        {
            string s = File.ReadAllText(p);

            List <ConvertedClass> toReturn = new List <ConvertedClass>();
            var syntaxTree = CSharpSyntaxTree.ParseText(s);

            var classes = syntaxTree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>();

            foreach (ClassDeclarationSyntax c in classes)
            {
                string[] identifierNames = c.DescendantNodes()
                                           .OfType <PropertyDeclarationSyntax>().Select(v => v.Identifier.Text)
                                           .ToArray();

                object[] identifierTypes = c.DescendantNodes()
                                           .OfType <PropertyDeclarationSyntax>().Select(v => v.Type)
                                           .ToArray();
                //Console.WriteLine(c.BaseList.ToString());
                loadedClasses.Add(c.Identifier.ToString());

                ConvertedClass cc = new ConvertedClass();

                if (c.BaseList != null)
                {
                    string clean = c.BaseList.ToString();
                    clean = clean.Replace(" ", "");
                    clean = clean.Replace(":", "");
                    Console.WriteLine("adding " + clean);
                    cc.dependencies.Add(clean);
                }
                cc.name = c.Identifier.ToString();


                for (int i = 0; i < identifierNames.Count(); i++)
                {
                    string tS = "";
                    tS = identifierTypes[i].ToString();
                    TypeSyntax t = identifierTypes[i] as TypeSyntax;
                    bool       l = false;
                    if (t.GetFirstToken().ToString() == "List")
                    {
                        tS = t.GetFirstToken().GetNextToken().GetNextToken().ToString();
                        l  = true;
                        Console.WriteLine("DEFINITELY A LIST");
                    }

                    cc.fields.Add(new fieldHelper(identifierNames[i], tS, l));
                }

                cc.linkedFilePath = p;

                cc.registerWatcher();

                toReturn.Add(cc);
            }

            return(toReturn);
        }
 protected static void ReportBadRefToken(TypeSyntax returnTypeSyntax, DiagnosticBag diagnostics)
 {
     if (!returnTypeSyntax.HasErrors)
     {
         var refKeyword = returnTypeSyntax.GetFirstToken();
         diagnostics.Add(ErrorCode.ERR_UnexpectedToken, refKeyword.GetLocation(), refKeyword.ToString());
     }
 }
Exemple #3
0
        private static Location GetLocationWithToken(TypeSyntax type, SeparatedSyntaxList <BaseTypeSyntax> baseTypes)
        {
            int start;
            int end;

            if (baseTypes.Count == 1 ||
                baseTypes.First().Type != type)
            {
                start = type.GetFirstToken().GetPreviousToken().Span.Start;
                end   = type.Span.End;
            }
            else
            {
                start = type.SpanStart;
                end   = type.GetLastToken().GetNextToken().Span.End;
            }

            return(Location.Create(type.SyntaxTree, new TextSpan(start, end - start)));
        }