Esempio n. 1
0
        static void doAnalysis(string[] files, bool relation_flag, bool xml_flag)
        {
            List<Elem> TABLE = new List<Elem>();
            foreach (object file in files)
            {
                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser parser = builder.build();
                try
                {
                    while (semi.getSemi())
                        parser.parse(semi);
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository rep = Repository.getInstance();
                TABLE.AddRange(rep.locations);          // Build a TABLE to store all the elements, provided to be searched for relationshipAnalysis class
                semi.close();
            }

            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");

            // parse all files and store the elements into table for each file
            foreach (object file in files)
            {
                Console.Write("\n Processing file {0}\n", file as string);

                CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
                semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }

                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser parser = builder.build();

                try
                {
                    while (semi.getSemi())
                        parser.parse(semi);
                    Console.Write("\n\n locations table contains:");
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository rep = Repository.getInstance();
                List<Elem> table = rep.locations;

                // display basic information for elements including size and complexity
                Console.Write("\n    type                 name          begin      end       size     complexity");
                foreach (Elem e in table)
                {
                    if (e.type == "function")
                    {
                        ComplexityAnalysis ca = new ComplexityAnalysis();
                        e.complexity = ca.ComplexityAnalyze(e, file);
                    }
                        Console.Write("\n  {0,9}, {1,20}, {2,8}, {3,8}, {4,8}, {5,8}", e.type, e.name, e.begin, e.end, e.end - e.begin + 1, e.complexity);

                }
                //display the relationships between classes
                if (relation_flag == true)
                {
                    foreach (Elem e in table)
                    {
                        e.AggregationFlag = false;
                        e.CompositionFlag = false;
                        e.UsingFlag = false;
                        if (e.type == "class" || e.type == "struct" || e.type == "interface")
                        {
                            Console.Write("\n\n {0} {1}", e.type, e.name);
                            Console.Write("------------------------------------------------------\n");
                            RelationshipAnalysis ra = new RelationshipAnalysis();
                            ra.RelationshipAnalyzer(e, file, TABLE);
                            foreach (Elem ele in TABLE)
                            {
                                ele.AggregationFlag = false;
                                ele.CompositionFlag = false;
                                ele.UsingFlag = false;
                            }
                        }
                    }
                }
                Console.WriteLine();

                //display xml files for each file
                if (xml_flag == true)
                {
                    XML x = new XML();
                    x.XmlBuilder(table, (string)file);
                }
            }
            Console.Write("\n");
            DisplaySummary(TABLE);
        }
Esempio n. 2
0
 static void Main(string[] args)
 {
     XML x = new XML();
     x.XMLWrite(true);
 }
 /// <summary>
 /// //////////////////////////////////////////////////////////////
 /// analyzer call or the executive for analyzer project
 public void analyzercall(clientconnect cc)
 {
       if (analyzeproj_.Count == 0)
       {
       //    Console.Write("Please enter Command Line Arguments.\n\n");
           //return null;
       }
       Console.Write("\n\nCurrent path:\n {0}", Directory.GetCurrentDirectory());
       CommandLine.CommandLineProcessing clp = new CommandLine.CommandLineProcessing();
       string path = Directory.GetCurrentDirectory();
       path += "/Servers/TestProjects";           
       Console.Write("{0}",path);
       if(CodeAnalysis.Repository.getInstance()!=null)
           CodeAnalysis.Repository.clearInstance();  
       CodeAnalysis.FileMgr fm = new CodeAnalysis.FileMgr();
       string str2 = "";
       foreach (string str1 in cc.patt_)
           str2 += str1;
       string[] commandlinestr = {path,"/X",str2};
       clp.ProcessCommandLine(commandlinestr);
       fm.setrecurseflag(cc.recurse_);
       fm.findFiles(path);
       List<string> files = new List<string>();
       foreach (string str in fm.getFiles())
       {
           foreach (string str1 in cc.analproj_)
               if (str.Contains(str1))
                   files.Add(str);
       }            
       CodeAnalysis.Analyzer.doAnalysis(files.ToArray(), true);
       CodeAnalysis.Display dis = new CodeAnalysis.Display();
       dis.Displayfiles(files);     
       try
       {
           CodeAnalysis.XML xml = new CodeAnalysis.XML();
           dis.DisplayData(clp);
           if (clp.getxmlflag())
               xml.XMLWrite(clp.getrelationshipflag());
           var xmldoc = XDocument.Load("Output.xml");
           cc.data_ = xmldoc.ToString();
       }
       catch (Exception ex)
       {
           Console.Write("\n\n  {0}\n", ex.Message);
       }
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Console.Write("\n  Testing XML - XmlBuilder ");
            Console.Write("\n ============================\n");
            List<Elem> test = new List<Elem>();

            Elem ns = new Elem();
            ns.name = "testNameSpace";
            ns.type = "namespace";
            ns.begin = 10;
            ns.end = 100;

            Elem cl = new Elem();
            cl.name = "testClass";
            cl.type = "class";
            cl.begin = 20;
            cl.end = 80;

            Elem func = new Elem();
            func.name = "testFunction";
            func.type = "function";
            func.begin = 30;
            func.end = 60;

            test.Add(ns);
            test.Add(cl);
            test.Add(func);

            XML xb = new XML();
            xb.XmlBuilder(test);
        }