コード例 #1
0
ファイル: Analyzer.cs プロジェクト: prmk/DependencyAnalyzer
        /// <summary>
        /// Starts the part 2 of analysis to find out the package and relationship dependency
        /// </summary>
        public void analyzePartII()
        {
            CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
            semi.displayNewLines = false;

            foreach (object file in files)
            {
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }

                BuildCodeAnalyzerRelationships builderreln = new BuildCodeAnalyzerRelationships(semi);
                CodeAnalysis.Parser            parser      = builderreln.build();

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                semi.close();
            }
        }
コード例 #2
0
        /// <summary>
        /// This is the method where we create the code anlayser object.
        /// There will be only one code analyser object for all the files.
        /// It uses the parser module to find the relationship analysis.
        /// Once the results are generated, it will be stored in the centralised
        /// repo. We use this centralised repo from other module to know
        /// the type and dependency analysis.
        /// </summary>
        /// <param name="serverName"></param>
        public void analyze(string serverName)
        {
            Console.Write("\n  CODE ANALYZER");
            Console.Write("\n ======================\n");

            CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
            semi.displayNewLines = false;

            try
            {
                foreach (object file in files)
                {
                    Console.Write("\n\n  Processing file {0}\n", file as string);

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

                    Console.Write("\n  Type and Function Analysis");
                    Console.Write("\n ----------------------------\n");

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

                    Repository repo = Repository.getInstance();
                    repo.CurrentFileName = file.ToString();
                    Elem elem = getDefaultElemData(file.ToString(), serverName);
                    repo.locations.Add(elem);

                    try
                    {
                        while (semi.getSemi())
                        {
                            parser.parse(semi);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Write("\n\n  {0}\n", ex.Message);
                    }
                    semi.close();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error in the data. Exception thrown, pls check the input");
            }
        }
コード例 #3
0
        //----< build dependency table by parsing for type usage >-------

        public void dependencyAnalysis(List <string> files)
        {
            Repository       repo     = Repository.getInstance();
            ITokenCollection semi     = Factory.create();
            BuildDepAnalyzer builder2 = new BuildDepAnalyzer(semi);
            Parser           parser   = builder2.build();

            repo.locations.Clear();

            foreach (string file in files)
            {
                //Console.Write("\n  file: {0}", file);
                if (file.Contains("TemporaryGeneratedFile") || file.Contains("AssemblyInfo"))
                {
                    continue;
                }

                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    break;
                }
                List <string> deps = new List <string>();
                repo.dependencyTable.addParent(file);

                repo.currentFile = file;

                try
                {
                    while (semi.get().Count > 0)
                    {
                        //semi.show();
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
            }
        }
コード例 #4
0
ファイル: Analyzer.cs プロジェクト: monishalp/CodeAnalyzer
        //*****second parse************//
        public void reldoAnalysis(string[] files)
        {
            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;
                }


                Repository rep_inst = Repository.getInstance();
                Repository.Copy_buffer = typesBetweenFiles;

                BuildCodeAnalyzer_types builder_ty = new BuildCodeAnalyzer_types(semi);
                Parser parser = builder_ty.build();
                // sends every semi again for relationship analysis
                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                //stores all the updation to the type and relationship list back to the repository
                Repository_types    rep   = Repository_types.getInstance();
                List <relationelem> table = rep.classrelations;
                rel_BetweenFiles = (rep.classrelations);
            }
        }
コード例 #5
0
        public void displaysemi(List <string> arguments, string displaytokenfile)
        {
            ITokenCollection  semi    = Factory.create();
            BuildTypeAnalyzer builder = new BuildTypeAnalyzer(semi);
            Parser            parser  = builder.build();
            Repository        repo    = Repository.getInstance();

            foreach (string file in arguments)
            {
                List <string> Semicollection = new List <string>();
                if (file.Contains("TemporaryGeneratedFile"))
                {
                    continue;
                }
                if (!semi.open(file as string))
                {
                    //Console.Write("\n  Can't open {0}\n\n", args[0]);
                    continue;
                }

                repo.currentFile = file;
                repo.locations.Clear();

                try
                {
                    while (semi.get().Count > 0)
                    {
                        Console.WriteLine(semi.ToString());
                        Semicollection.Add(semi.ToString());
                    }
                    parser.parse(semi);
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                WriteFile(displaytokenfile, Semicollection);
            }
        }
コード例 #6
0
        //----< Test Stub >--------------------------------------------------

#if (TEST_PARSER)
        static void Main(string[] args)
        {
            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");
            FileFinder filef = new FileFinder();

            args = filef.get_cs();
            foreach (string file in args)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));
                ITokenCollection semi = Factory.create();
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]); return;
                }
                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------");

                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser            parser  = builder.build();
                try{
                    while (semi.get().Count > 0)
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex) {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                Display.showMetricsTable(table);
                Console.Write("\n");
                semi.close();
            }
            Console.Write("\n\n");
            Console.ReadKey();
        }
コード例 #7
0
        public static void performTypeAnalysis(List <string> files)
        {
            foreach (string file in files)
            {
                // Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));

                Lexer.ITokenCollection semi = Factory.create();
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", files);
                    return;
                }

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

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

                Console.Write("\n");
                rep.nameSpace = "";
                semi.close();
            }
        }
コード例 #8
0
        public List <List <Elem> > generateTypeTable()
        {
            string nameofFile;
            List <List <Elem> > listOfTables = new List <List <Elem> >();

            foreach (string file in files)
            {
                nameofFile = System.IO.Path.GetFileName(file);
                ITokenCollection semi = Factory.create();
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", nameofFile);
                }

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

                try
                {
                    while (semi.get().Count > 0)
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                listOfTables.Add(table);
                semi.close();
            }
            return(listOfTables);
        }
コード例 #9
0
ファイル: Analyzer.cs プロジェクト: nisha-choudhary/Projects
        //---------<parse2 starts here, it identifies relationships betn all the types>------------
        public void doAnalysisRelationship(string[] files)
        {
            foreach (object file in files)
            {
                string filename = Convert.ToString(file);


                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;
                }

                BuildCodeAnalyzerRelation builderForRelationship = new BuildCodeAnalyzerRelation(semi);
                Parser parser = builderForRelationship.build();

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi, filename);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;

                semi.close();
            }
        }
コード例 #10
0
        static void Main(string[] args)
        {
            Console.Write("This project contains 13 packages demonstrating requirement 3:\n");
            Console.Write("1) DemoExecutive\n");
            Console.Write("2) DemoReqs\n");
            Console.Write("3) DependencyAnalysis\n");
            Console.Write("4) Display\n");
            Console.Write("5) Element\n");
            Console.Write("6) FileMgr\n");
            Console.Write("7) Parser\n");
            Console.Write("8) SemiExp\n");
            Console.Write("9) StrongComponent\n");
            Console.Write("10) TestHarness\n");
            Console.Write("11) Toker\n");
            Console.Write("12) TypeTable\n");
            Console.Write("13) AutomatedTestUnit\n");
            Console.Write("\n ======================\n");
            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");

            ShowCommandLine(args);

            List <string> files = ProcessCommandline(args);
            DepAnalysis   da    = new DepAnalysis();

            foreach (string file in files)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));

                ITokenCollection semi = Factory.create();
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }

                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------");

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

                try
                {
                    while (semi.get().Count > 0)
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository          rep   = Repository.getInstance();
                List <Elem>         table = rep.locations;
                TypeTable.TypeTable tt    = new TypeTable.TypeTable();
                ///shows typetable
                foreach (Elem e in table)
                {
                    tt.add(e.type, e.name);
                    if (e.type == "using")
                    {
                        da.add(System.IO.Path.GetFileName(file), e.name);
                    }
                }
                tt.show();
                Console.WriteLine("Showing TypeTables of files demonstrating requirement 5:\n");
                Console.Write("\n  TypeTable contains types: ");
                foreach (var elem in tt.table)
                {
                    Console.Write("{0} ", elem.Key);
                }
                ////Display.showMetricsTable(table);

                Console.Write("\n");
                semi.close();
            }
            var nodes = new List <CsNode <string, string> >();

            foreach (var elem in da.table)
            {
                nodes.Add(new CsNode <string, string>(elem.Key));
                //Console.Write("\n  {0} depends on", elem.Key);
            }
            nodes.ToArray();

            //foreach (var elem in da.table)
            //{
            //    foreach (var item in elem.Value)
            //    {
            //        //nodes[IndexOf(elem.Key)].addChild(nodes[IndexOf(item.file)], "edge" + elem.Key + " " + item.file);
            //        //nodes[0].addChild(item.file, "edge" + elem.Key + " " + item.file);
            //        //nodes[nodes.IndexOf(elem.Value)].addChild(nodes[nodes.IndexOf(item.file)], "edge" + elem.Key + " " + item.file);

            //        Console.Write("\n    {0}.cs", item.file);
            //    }
            //}
            //iterate through list of list elements of a file
            //da.table --gets table,
            for (int i = 0; i < da.table.Count; i++)
            {
                var item = da.table.ElementAt(i);
                for (int j = 0; j < item.Value.Count; j++)
                {
                    //Console.WriteLine(i+"^"+ da.table.Values);
                    nodes[i].addChild(nodes[j], "edge" + i + j);
                }
            }
            Graph <string, string> graph = new Graph <string, string>("Fred");

            for (int i = 0; i < da.table.Count; i++)
            {
                graph.addNode(nodes[i]);
            }

            graph.startNode = nodes[0];
            //Console.WriteLine("\n Showing graph walk starting at node[0]\n");
            //Console.Write("\n\n  starting walk at {0}", graph.startNode.name);
            //Console.Write("\n  not showing backtracks");
            //graph.walk();

            Console.WriteLine("Showing dependencies between files demonstrating requrement 4:\n\n");
            //shows dependency analysis
            da.show();
            Console.Write("\n\n");
            Console.Write("Showing all strong components, if any, in the file collection, based on the dependency analysis demonstrating requirement 6:\n\n");
            graph.startNode = nodes[0];
            graph.Tarjan();
            Console.Write("\n\n");
            Console.WriteLine("This demo executive file demonstrates all the outputs and is well formatted as per requirement 7 and 8\n");
            Console.ReadLine();
        }
コード例 #11
0
ファイル: Parser.cs プロジェクト: SimHuang/RemoteCodeAnalyzer
        //----< Test Stub >--------------------------------------------------

#if (TEST_PARSER)
        static void Main(string[] args)
        {
            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");

            ShowCommandLine(args);

            //THIS RETURNS A LIST OF FILES THAT THE USER PASSED IN
            List <string> files = TestParser.ProcessCommandline(args);

            for (int i = 0; i < files.Count; i++)
            {
                Console.Write(files[i] + "\n");
            }

            //sh - preprocess all user input files to get all user defined types
            UserType.parseUserDefinedTypes(files);
            HashSet <string> definedSet = UserType.getUserDefinedSet();

            Console.Write("Parser size of definedset" + definedSet.Count.ToString());

            foreach (string file in files)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));

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

                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------");

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

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                    Console.Write("\n  locations table contains:");
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                //all data is stored in table object
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}, {8,10}, {9, 10}, {10,6}",
                    "category", "name", "bLine", "eLine", "bScop", "eScop", "size", "cmplx", "coupling", "cohesion", "M-Index"
                    );
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}, {8,10}, {9,10}, {10,6}",
                    "--------", "----", "-----", "-----", "-----", "-----", "----", "-----", "--------", "--------", "-------"
                    );
                foreach (Elem e in table)
                {
                    if (e.type == "class" || e.type == "struct")
                    {
                        Console.Write("\n");

                        //get the maintainibility index
                        e.mIndex = getMaintainibilityIndex(e);

                        Console.Write(
                            "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}, {8,10}, {9,10}, {10,6}",
                            e.type, e.name, e.beginLine, e.endLine, e.beginScopeCount, e.endScopeCount + 1,
                            e.endLine - e.beginLine + 1, e.endScopeCount - e.beginScopeCount + 1, e.coupling, e.cohesion, e.mIndex
                            );
                    }
                    else
                    {
                        Console.Write(
                            "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}, {8,10}, {9,10}",
                            e.type, e.name, e.beginLine, e.endLine, e.beginScopeCount, e.endScopeCount + 1,
                            e.endLine - e.beginLine + 1, e.endScopeCount - e.beginScopeCount + 1, e.coupling, e.cohesion
                            );
                    }
                }

                Console.Write("\n\n");

                semi.close();
            }
            Console.Write("\n\n");
        }
コード例 #12
0
        //----< Test Stub >--------------------------------------------------

#if (TEST_PARSER)
        static void Main(string[] args)
        {
            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");

            ShowCommandLine(args);

            List <string> files = TestParser.ProcessCommandline(args);

            foreach (string file in files)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));

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

                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------");

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

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                    Console.Write("\n  locations table contains:");
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository  rep   = Repository.getInstance();
                List <Elem> table = rep.locations;
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                    "category", "name", "bLine", "eLine", "bScop", "eScop", "size", "cmplx"
                    );
                Console.Write(
                    "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                    "--------", "----", "-----", "-----", "-----", "-----", "----", "-----"
                    );
                foreach (Elem e in table)
                {
                    if (e.type == "class" || e.type == "struct")
                    {
                        Console.Write("\n");
                    }
                    Console.Write(
                        "\n  {0,10}, {1,25}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}",
                        e.type, e.name, e.beginLine, e.endLine, e.beginScopeCount, e.endScopeCount + 1,
                        e.endLine - e.beginLine + 1, e.endScopeCount - e.beginScopeCount + 1
                        );
                }

                Console.Write("\n");
                semi.close();
            }
            Console.Write("\n\n");
        }
コード例 #13
0
        public void Requirement4_5(string[] args)
        {
            Console.Write("\n\t \tOutput of Requirement4\n");
            Console.Write("-----------------------------------------------------------------------------\n");
            Console.Write("This Project3 implements packages that evaluate all the dependencies between files in a specified file set  \n");
            ShowCommandLine(args);

            List<string> files = ProcessCommandline(args);


            foreach (string file in files)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));

                ITokenCollection semi = Factory.create();
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }
                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser parser = builder.build();

                try
                {
                    while (semi.get().Count > 0)
                        parser.parse(semi);
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Console.Write("\n");

                semi.close();
            }


            DepAnalysis.DepAnalysis dep = new DepAnalysis.DepAnalysis();
            StrongComp.filesGraph = files;
            StrongComp.filesGraphs = files;
            StrongComp.filenumber = files.Count();
            StrongComp.setGraph();
            StrongComp.filesGraph = files;
            StrongComp.setGraphDictionary();
            DepAnalysis.DepAnalysis.filesDepAnalysis = files;
            DepAnalysis.DepAnalysis.setDictionary();


            foreach (string file in files)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));

                ITokenCollection semi = Factory.create();
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }


                try
                {
                    while (semi.get().Count > 0)
                        dep.HoldUsingValue(semi);

                }

                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                semi.close();
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }
                try
                {
                    while (semi.get().Count > 0)
                        dep.analyze(semi, file);
                }

                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }

                semi.close();
                StrongComp.addGraph();


            }
            Console.Write("\n\n");
        }
コード例 #14
0
ファイル: Analyzer.cs プロジェクト: prmk/CodeAnalyzer
        //read the list of files, one by one and calls BuildCodeAnalyzer and parser functions
        public void analyze()
        {
            Console.Write("\n  CODE ANALYZER");
            Console.Write("\n ======================\n");

            CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
            semi.displayNewLines = false;

            foreach (object file in files)
            {
                Console.Write("\n\n  Processing file {0}\n", file as string);

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

                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------\n");

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

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                semi.close();

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

                    BuildCodeAnalyzerRelationships builderreln = new BuildCodeAnalyzerRelationships(semi);
                    parser = builderreln.build();

                    try
                    {
                        while (semi.getSemi())
                        {
                            parser.parse(semi);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Write("\n\n  {0}\n", ex.Message);
                    }
                }
                semi.close();
            }
        }
コード例 #15
0
        /* This method is used to call the relationship and complexity analysis
         * for each file in the input set
         */
        public void analyze()
        {
            CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
            semi.displayNewLines = false;

            /* These are the supported file formats in this tool. If input file is not in this format,
             * then analysis will not be done*/
            string[] supportedFileFormatList = { ".cs", ".c", ".cpp", ".java", ".txt", ".bat" };

            foreach (object file in files)
            {
                string fileExtension       = Path.GetExtension(file.ToString());
                bool   supportedFileFormat = false;

                foreach (string currentFileExtension in supportedFileFormatList)
                {
                    if (fileExtension == currentFileExtension)
                    {
                        supportedFileFormat = true;
                    }
                }

                if (!supportedFileFormat)
                {
                    Console.WriteLine("\nThe file {0} is of unsupported format", file.ToString());
                    continue;
                }
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", file);
                    return;
                }

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

                Repository repo = Repository.getInstance();
                Elem       elem = getDefaultElemData(file.ToString());
                repo.locations.Add(elem);

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                semi.close();

                //Only when the user specifies the /R option, we do relationship analysis
                if (findRelationship)
                {
                    semi = new CSsemi.CSemiExp();
                    semi.displayNewLines = false;
                    if (!semi.open(file as string))
                    {
                        Console.Write("\n  Can't open {0}\n\n", file);
                        return;
                    }

                    BuildCodeAnalyzerForRelationshipTypes builderreln = new BuildCodeAnalyzerForRelationshipTypes(semi);
                    parser = builderreln.build();

                    try
                    {
                        while (semi.getSemi())
                        {
                            parser.parse(semi);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Write("\n\n  {0}\n", ex.Message);
                    }
                }
                semi.close();
            }
        }