コード例 #1
0
ファイル: XML.cs プロジェクト: DiyaChen/DependencyAnalyzer
        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);
        }
コード例 #2
0
        public override void doAction(ITokenCollection semi)
        {
            Display.displayActions(actionDelegate, "action PushStack");
            ++repo_.scopeCount;
            Elem elem = new Elem();

            elem.type            = semi[0]; // expects type, i.e., namespace, class, struct, ..
            elem.name            = semi[1]; // expects name
            elem.beginLine       = repo_.semi.lineCount() - 1;
            elem.endLine         = 0;       // will be set by PopStack action
            elem.beginScopeCount = repo_.scopeCount;
            elem.endScopeCount   = 0;       // will be set by PopStack action
            repo_.stack.push(elem);

            // display processing details if requested

            if (AAction.displayStack)
            {
                repo_.stack.display();
            }
            if (AAction.displaySemi)
            {
                Console.Write("\n  line# {0,-5}", repo_.semi.lineCount() - 1);
                Console.Write("entering ");
                string indent = new string(' ', 2 * repo_.stack.count);
                Console.Write("{0}", indent);
                this.display(semi); // defined in abstract action
            }

            // add starting location if namespace, type, or function

            if (elem.type == "control" || elem.name == "anonymous")
            {
                return;
            }
            repo_.locations.Add(elem);
        }
コード例 #3
0
        static void Main()
        {
            Console.Write("\n  Test ScopeStack");
            Console.Write("\n =================\n");

            ScopeStack <Elem> mystack = new ScopeStack <Elem>();

            Test.Elem e;
            e.type  = "namespace";
            e.name  = "foobar";
            e.place = 14;
            mystack.push(e);
            e.make("class", "feebar", 21);
            mystack.push(e);
            e.make("function", "doTest", 44);
            mystack.push(e);
            e.make("control", "for", 56);
            mystack.push(e);

            mystack.display();
            Console.ReadLine();

            Elem test = mystack.lastPopped();

            Console.Write("\n  last popped:\n  {0}\n", test);

            e = mystack.pop();
            Console.Write("\n  popped:\n  {0}", e);
            e = mystack.pop();
            Console.Write("\n  popped:\n  {0}\n", e);
            Console.Write("\n  last popped:\n  {0}\n", mystack.lastPopped());

            mystack.display();

            Console.Write("\n\n");
        }
コード例 #4
0
ファイル: XMLOutput.cs プロジェクト: nisha-choudhary/Projects
        // ------------------------<TestStub for XML Output>-------------------------
#if (TEST_XMLOUTPUT)
        static void Main(string[] args)
        {
            ElemRelation e = new ElemRelation();

            e.fromClass    = "Derived";
            e.toClass      = "Original";
            e.relationType = "Inheritance";

            RelationshipRepository.relationship_.Add(e);

            Elem elem = new Elem();

            elem.type  = "function";
            elem.name  = "Derived";
            elem.begin = 1;
            elem.end   = 10;
            elem.functionComplexity = 2;
            OutputRepository.output_.Add(elem);
            XMLOutput xml = new XMLOutput();

            xml.displaySummary();
            xml.displayFunctionAnalysis();
            xml.displayRelation();
        }
コード例 #5
0
        /// <summary>
        /// Test Stub for Display package
        /// </summary>
        /// <param name="args"></param>
#if (TEST_DISPLAY)
        static void Main(string[] args)
        {
            Console.Write("\n  Testing Display Package");
            Console.Write("\n ===========================\n");
            Dictionary <string, HashSet <string> > dependencies = new Dictionary <string, HashSet <string> >();
            HashSet <string> lst = new HashSet <string> {
                "file2.cs", "file3.cs"
            };

            dependencies.Add("file1.cs", lst);
            Elem oElem = new Elem();

            oElem.type = "class";
            oElem.name = "testclass";
            Dictionary <string, List <Elem> > dicMetrics = new Dictionary <string, List <Elem> >();
            List <Elem> repoLoc = new List <Elem> {
                oElem
            };

            dicMetrics.Add("file1.cs", repoLoc);
            Console.Write("\n  showMetricsTable method\n");
            Display.showMetricsTable("file1.cs", repoLoc);
            Console.Write("\n  ShowTypeTables method\n");
            Display.ShowTypeTables(dicMetrics);
            Console.Write("\n  ShowDependencies method");
            Display.ShowDependencies(dependencies);
            HashSet <List <string> > lstScc = new HashSet <List <string> >();
            List <string>            lstcc  = new List <string> {
                "file1", "file2", "file3"
            };

            Console.Write("\n  ShowSCC method\n");
            lstScc.Add(lstcc);
            Display.ShowSCC(lstScc);
            Console.ReadLine();
        }
コード例 #6
0
ファイル: RulesAndActions.cs プロジェクト: prmk/CodeAnalyzer
        public override void doActionAggregation(CSsemi.CSemiExp semi)
        {
            AggregationElem aggregationelem    = new AggregationElem();
            Elem            elem               = new Elem();
            bool            existingAggregator = false;

            for (int i = 0; i < repo_.analyzedata.Count; i++)
            {
                elem = repo_.analyzedata[i];
                if (elem.type == "class" && semi[0] == elem.name)
                {
                    for (int j = 0; j < repo_.aggregationdata.Count; j++)
                    {
                        aggregationelem = repo_.aggregationdata[j];
                        if (semi[2] == aggregationelem.aggregator)
                        {
                            existingAggregator = true;
                            int index = repo_.aggregationdata.IndexOf(aggregationelem);
                            aggregationelem.aggregated.Add(semi[1]);
                            aggregationelem.type = semi[0];
                            repo_.aggregationdata.Remove(aggregationelem);
                            repo_.aggregationdata.Insert(index, aggregationelem);
                        }
                    }

                    if (!existingAggregator)
                    {
                        aggregationelem = new AggregationElem();
                        aggregationelem.aggregated.Add(semi[1]);
                        aggregationelem.aggregator = semi[2];
                        aggregationelem.type       = semi[0];
                        repo_.aggregationdata.Add(aggregationelem);
                    }
                }
            }
        }
 //------------<Private help function, extract the type information to type table
 private void extractType(Elem elem)
 {
     if (elem.type == "class" || elem.type == "struct" || elem.type == "enum" || elem.type == "interface" || elem.type == "delegate")
     {
         TypeInfo tempT = new TypeInfo();
         tempT.file = file_;
         StringBuilder type = new StringBuilder();
         for (int i = repo_.stack.count - 1; i >= 0; --i)
         {
             if (repo_.stack[i].type != "namespace")
             {
                 type.Insert(0, ".");
                 type.Insert(0, repo_.stack[i].name);
             }
             else
             {
                 tempT.nameSpace = repo_.stack[i].name;
                 break;
             }
         }
         type.Append(elem.name);
         repo_.addType(tempT, type.ToString());
     }
 }
コード例 #8
0
ファイル: RulesAndActions.cs プロジェクト: prmk/CodeAnalyzer
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Elem elem = new Elem();

            elem.type  = semi[0]; // expects type
            elem.name  = semi[1]; // expects name
            elem.begin = repo_.semi.lineCount - 1;
            elem.end   = 0;
            repo_.stack.push(elem);
            repo_.analyzedata.Add(elem);

            if (AAction.displaySemi)
            {
                Console.Write("\n  line# {0,-5}", repo_.semi.lineCount - 1);
                Console.Write("entering ");
                string indent = new string(' ', 2 * repo_.stack.count);
                Console.Write("{0}", indent);
                this.display(semi); // defined in abstract action
            }
            if (AAction.displayStack)
            {
                repo_.stack.display();
            }
        }
コード例 #9
0
ファイル: RulesAndActions.cs プロジェクト: prmk/CodeAnalyzer
        public override void doActionComposition(CSsemi.CSemiExp semi)
        {
            CompositionElem compositionelem    = new CompositionElem();
            Elem            elem               = new Elem();
            bool            existingCompositor = false;

            for (int i = 0; i < repo_.analyzedata.Count; i++)
            {
                elem = repo_.analyzedata[i];
                if ((elem.type == "struct" && semi[0] == elem.name) || (elem.type == "enum" && semi[0] == elem.name))
                {
                    for (int j = 0; j < repo_.compositiondata.Count; j++)
                    {
                        compositionelem = repo_.compositiondata[j];
                        if (semi[2] == compositionelem.compositor)
                        {
                            existingCompositor = true;
                            int index = repo_.compositiondata.IndexOf(compositionelem);
                            compositionelem.composedelement.Add(semi[1]);
                            compositionelem.type = semi[0];
                            repo_.compositiondata.Remove(compositionelem);
                            repo_.compositiondata.Insert(index, compositionelem);
                        }
                    }

                    if (!existingCompositor)
                    {
                        compositionelem = new CompositionElem();
                        compositionelem.composedelement.Add(semi[1]);
                        compositionelem.compositor = semi[2];
                        compositionelem.type       = semi[0];
                        repo_.compositiondata.Add(compositionelem);
                    }
                }
            }
        }
コード例 #10
0
ファイル: RulesAndActions.cs プロジェクト: ravisjce/Programs
        //The action performed whenever a inheritance type is detected in the current semi expression
        public override void doActionForInheritance(CSsemi.CSemiExp semi)
        {
            InheritanceElement inheritanceelem = new InheritanceElement();
            Elem elem           = new Elem();
            bool existingParent = false;

            for (int i = 0; i < repo_.locations.Count; i++)
            {
                elem = repo_.locations[i];
                if (elem.type == "class" && semi[1] == elem.name)
                {
                    for (int j = 0; j < repo_.inheritancedataList.Count; j++)
                    {
                        inheritanceelem = repo_.inheritancedataList[j];
                        if (semi[1] == inheritanceelem.parent)
                        {
                            existingParent = true;
                            int index = repo_.inheritancedataList.IndexOf(inheritanceelem);
                            inheritanceelem.children.Add(semi[0]);
                            inheritanceelem.childcount++;
                            repo_.inheritancedataList.Remove(inheritanceelem);
                            repo_.inheritancedataList.Insert(index, inheritanceelem);
                        }
                    }

                    if (!existingParent)
                    {
                        inheritanceelem = new InheritanceElement();
                        inheritanceelem.children.Add(semi[0]);
                        inheritanceelem.parent = semi[1];
                        inheritanceelem.childcount++;
                        repo_.inheritancedataList.Add(inheritanceelem);
                    }
                }
            }
        }
コード例 #11
0
 public override void doAction(CSsemi.CSemiExp semi)
 {
     Display.displayActions(actionDelegate, "action SaveDeclar");
       Elem elem = new Elem();
       elem.type = semi[0];  // expects type
       elem.name = semi[1];  // expects name
       elem.beginLine = repo_.semi.lineCount;
       elem.endLine = elem.beginLine;
       elem.beginScopeCount = repo_.scopeCount;
       elem.endScopeCount = elem.beginScopeCount;
       if (AAction.displaySemi)
       {
     Console.Write("\n  line# {0,-5}", repo_.semi.lineCount - 1);
     Console.Write("entering ");
     string indent = new string(' ', 2 * repo_.stack.count);
     Console.Write("{0}", indent);
     this.display(semi); // defined in abstract action
       }
       repo_.locations.Add(elem);
 }
コード例 #12
0
ファイル: RulesAndActions.cs プロジェクト: WaverV/Projects
 //----<detects if it is a class and pushes onto the stack to check for last pushed class >-----
 public void doActionClass(CSsemi.CSemiExp semi, string file, ElemRelation elem)
 {
     if (semi[0].Equals("class"))
     {
         Elem elemcl = new Elem();
         elemcl.type = semi[0];  // expects type
         elemcl.name = semi[1];  // expects name
         elemcl.begin = repo_.semi.lineCount - 1;
         elemcl.end = 0;
         elemcl.fileName = file;
         repo_.stack.push(elemcl);
         repo_.locations.Add(elemcl);
     }
 }
コード例 #13
0
        static public string getClassName(int lineno)
        {
            string classname = "";
            Repository repo_ = Repository.getInstance();
            Elem elem = new Elem();
            int begin = 0;

            for (int i = 0; i < repo_.analyzedata.Count; i++)
            {
                elem = repo_.analyzedata[i];
                if (elem.type == "class")
                {
                    if (elem.begin > begin && elem.begin < lineno && elem.end > lineno)
                    {
                        begin = elem.begin;
                        classname = elem.name;
                    }
                }
            }

            return classname;
        }
コード例 #14
0
        // function detect aggregation
        public void aggregation(CSsemi.CSemiExp semi, Elem e, List<Elem> fileSetInfo)
        {
            int indexNW = semi.Contains("new");
              if (indexNW != -1)
              {
              if (isSelfDefine(semi[indexNW + 1], fileSetInfo))     // is class defined in other file
              {
                  if (semi[indexNW + 2] != ".") // like "= new class ();"
                  {
                      if ((e.aggregation).IndexOf(semi[indexNW + 1]) < 0)
                      {
                          e.aggregation += semi[indexNW + 1] + " ";
                      }
                  }
                  else // like "= new namespace.class();"
                  {
                      if (e.aggregation.IndexOf(semi[indexNW + 3]) < 0)
                      {
                          e.aggregation += semi[indexNW + 3] + " ";
                      }
                  }

              }
              }
        }
コード例 #15
0
ファイル: Display.cs プロジェクト: WaverV/Projects
        //--------------------------<Test Stub for Display>------------------------

#if(TEST_DISPLAY)

        static void Main(string[] args)
        {
            string path = "../../";
            string[] arg = { "../../", "*.cs" };
            List<string> patterns = new List<string>();
            patterns.Add("*.cs");
            List<string> options = new List<string>();
            string[] files = getFiles(path, patterns);

            foreach (string f in files)                  //to populate element Relation
            {
                ElemRelation e = new ElemRelation();
                e.fromClass = "Derived";
                e.toClass = "Original";
                e.relationType = "Inheritance";
                e.fileName = f;
                RelationshipRepository.relationship_.Add(e);
            }
            foreach (string f1 in files)         //to populate types
            {
                Elem elem = new Elem();
                elem.fileName = f1;
                elem.type = "function";
                elem.name = "Derived";
                elem.begin = 1;
                elem.end = 10;
                elem.functionComplexity = 2;
                OutputRepository.output_.Add(elem);
            }

            options.Add("/S");
            patterns.Add("*.cs");
            Display d = new Display();
            d.display(files, path, patterns, options);
            d.displaySummary(files);
            d.displayFunctionComplexity(files);
            d.displayRelation(files);
        }
コード例 #16
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Elem elem   = new Elem();
            bool isFunc = false;

            try
            {
                elem = repo_.stack.pop();
                if (elem.type == "delegate")
                {
                    return;
                }
                if (semi[0] == "control" || semi[0] == "anonymous")
                {
                    elem.prog_complexity = elem.prog_complexity + 1;
                }
                if (elem.type == "function")
                {
                    elem.prog_complexity  = repo_.prog_comp_count + 1;
                    repo_.prog_comp_count = 0;
                    Console.WriteLine("complexity: {0}", elem.prog_complexity);
                    isFunc = false;
                }

                // calculates the line count and sets the line count in the repository//
                for (int i = 0; i < repo_.locations.Count; ++i)
                {
                    Elem temp = repo_.locations[i];
                    if (elem.type == temp.type)
                    {
                        if (elem.name == temp.name)
                        {
                            if ((repo_.locations[i]).end == 0)
                            {
                                (repo_.locations[i]).end = repo_.semi.lineCount;
                                if (isFunc)
                                {
                                    (repo_.locations[i]).prog_complexity = elem.prog_complexity;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                Console.Write("popped empty stack on semiExp: ");
                semi.display();
                return;
            }
            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            local.Add(elem.type).Add(elem.name);
            if (local[0] == "control")
            {
                return;
            }

            if (AAction.displaySemi)
            {
                elem.end  = repo_.semi.lineCount;
                elem.size = elem.end - elem.begin;
                string indent = new string(' ', 2 * (repo_.stack.count + 1));
                this.display(local); // defined in abstract action
            }
        }
コード例 #17
0
 public override void doAction(CSsemi.CSemiExp semi)
 {
   Elem elem = new Elem();
   elem.filename = repo_.filename;  
   elem.type = semi[0];  // expects type
   elem.name = semi[1];
   elem.begin = repo_.semi.lineCount - 1;
   elem.end = 0;
   if (elem.type == "array")
   {
       elem.end = elem.begin;
   }
   if (elem.type == "struct" || elem.type == "enum")
       repo_.composed_relations.Add(elem.name);
   if (repo_.getcomplexflag())
       repo_.incrementcomplex();
   if (elem.type == "braceless")
       return;
     repo_.stack.push(elem);
   if (elem.type == "function")
   {
       repo_.resetcomplex();
       repo_.setcomplexflag(true);
   }
     if (elem.type == "control" || elem.name == "anonymous")
   {
       return;
   }
   repo_.locations.Add(elem);
   if (AAction.displaySemi)
   {
     Console.Write("\n  line# {0,-5}", repo_.semi.lineCount - 1);
     Console.Write("entering ");
     string indent = new string(' ', 2 * repo_.stack.count);
     Console.Write("{0}", indent);
     this.display(semi); // defined in abstract action
   }
   if(AAction.displayStack)
     repo_.stack.display();
 }
コード例 #18
0
        /// <summary>
        /// stores the semi into the using element
        /// </summary>
        /// <param name="semi">the semi to be stored</param>
        public override void doActionUsing(CSsemi.CSemiExp semi)
        {
            UsingElem usingelem = new UsingElem();
            Elem elem = new Elem();
            bool existingfunction = false;
            string classname = semi[0];
            string functionname = semi[1];
            string type = semi[2];
            string typename = semi[3];

            for (int i = 0; i < repo_.analyzedata.Count; i++)
            {
                elem = repo_.analyzedata[i];
                if ((elem.type == "struct" || elem.type == "enum" || elem.type == "class" || elem.type == "interface") && type == elem.name)
                {
                    for (int j = 0; j < repo_.usingdata.Count; j++)
                    {
                        usingelem = repo_.usingdata[j];
                        if (functionname == usingelem.containingfunction)
                        {
                            existingfunction = true;
                            TypeDetails typeDetails = new TypeDetails();
                            usingelem.parent = classname;
                            usingelem.containingfunction = functionname;
                            typeDetails.type = type;
                            typeDetails.usedtypename = typename;
                            usingelem.typeslist.Add(typeDetails);
                            int index = repo_.usingdata.IndexOf(usingelem);
                            repo_.usingdata.Remove(usingelem);
                            repo_.usingdata.Insert(index, usingelem);
                        }
                    }
                    if (!existingfunction)
                    {
                        TypeDetails typeDetails = new TypeDetails();
                        usingelem = new UsingElem();
                        usingelem.parent = classname;
                        usingelem.containingfunction = functionname;
                        typeDetails.type = type;
                        typeDetails.usedtypename = typename;
                        usingelem.typeslist.Add(typeDetails);
                        repo_.usingdata.Add(usingelem);
                    }
                    createPackageAnalysisList("Using", semi, i);
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// stores the semi into the composition element
        /// </summary>
        /// <param name="semi">the semi to be stored</param>
        public override void doActionComposition(CSsemi.CSemiExp semi)
        {
            CompositionElem compositionelem = new CompositionElem();
            Elem elem = new Elem();
            bool existingCompositor = false;

            for (int i = 0; i < repo_.analyzedata.Count; i++)
            {
                elem = repo_.analyzedata[i];
                if ((elem.type == "struct" && semi[0] == elem.name) || (elem.type == "enum" && semi[0] == elem.name))
                {
                    for (int j = 0; j < repo_.compositiondata.Count; j++)
                    {
                        compositionelem = repo_.compositiondata[j];
                        if (semi[2] == compositionelem.compositor)
                        {
                            existingCompositor = true;
                            int index = repo_.compositiondata.IndexOf(compositionelem);
                            compositionelem.composedelement.Add(semi[1]);
                            compositionelem.type = semi[0];
                            repo_.compositiondata.Remove(compositionelem);
                            repo_.compositiondata.Insert(index, compositionelem);
                        }
                    }

                    if (!existingCompositor)
                    {
                        compositionelem = new CompositionElem();
                        compositionelem.composedelement.Add(semi[1]);
                        compositionelem.compositor = semi[2];
                        compositionelem.type = semi[0];
                        repo_.compositiondata.Add(compositionelem);
                    }

                    createPackageAnalysisList("Composition", semi, i);
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// stores the semi into the Aggregation element
        /// </summary>
        /// <param name="semi">the semi to be stored</param>
        public override void doActionAggregation(CSsemi.CSemiExp semi)
        {
            AggregationElem aggregationelem = new AggregationElem();
            Elem elem = new Elem();
            bool existingAggregator = false;

            for (int i = 0; i < repo_.analyzedata.Count; i++)
            {
                elem = repo_.analyzedata[i];
                if (elem.type == "class" && semi[0] == elem.name)
                {
                    for (int j = 0; j < repo_.aggregationdata.Count; j++)
                    {
                        aggregationelem = repo_.aggregationdata[j];
                        if (semi[2] == aggregationelem.aggregator)
                        {
                            existingAggregator = true;
                            int index = repo_.aggregationdata.IndexOf(aggregationelem);
                            aggregationelem.aggregated.Add(semi[1]);
                            aggregationelem.type = semi[0];
                            repo_.aggregationdata.Remove(aggregationelem);
                            repo_.aggregationdata.Insert(index, aggregationelem);
                        }
                    }

                    if (!existingAggregator)
                    {
                        aggregationelem = new AggregationElem();
                        aggregationelem.aggregated.Add(semi[1]);
                        aggregationelem.aggregator = semi[2];
                        aggregationelem.type = semi[0];
                        repo_.aggregationdata.Add(aggregationelem);
                    }

                    createPackageAnalysisList("Aggregation", semi, i);
                }
            }
        }
コード例 #21
0
        /// <summary>
        /// stores the semi into the Inheritance element
        /// </summary>
        /// <param name="semi">the semi to be stored</param>
        public override void doActionInheritance(CSsemi.CSemiExp semi)
        {
            InheritanceElem inheritanceelem = new InheritanceElem();
            PackageDependencyElem packageelem = new PackageDependencyElem();
            Elem elem = new Elem();
            bool existingParent = false;

            for (int i = 0; i < repo_.analyzedata.Count; i++)
            {
                elem = repo_.analyzedata[i];

                if (elem.type == "class" && semi[1] == elem.name)
                {
                    for (int j = 0; j < repo_.inheritancedata.Count; j++)
                    {
                        inheritanceelem = repo_.inheritancedata[j];
                        if (semi[1] == inheritanceelem.parent)
                        {
                            existingParent = true;
                            int index = repo_.inheritancedata.IndexOf(inheritanceelem);
                            inheritanceelem.children.Add(semi[0]);
                            inheritanceelem.childcount++;
                            repo_.inheritancedata.Remove(inheritanceelem);
                            repo_.inheritancedata.Insert(index, inheritanceelem);
                        }
                    }

                    if (!existingParent)
                    {
                        inheritanceelem = new InheritanceElem();
                        inheritanceelem.children.Add(semi[0]);
                        inheritanceelem.parent = semi[1];
                        inheritanceelem.childcount++;
                        repo_.inheritancedata.Add(inheritanceelem);
                    }

                    createPackageAnalysisList("Inheritance", semi, i);
                }
            }
        }
コード例 #22
0
        // function detect inheritance relationship
        public void inheritance(CSsemi.CSemiExp semi, Elem e)
        {
            int indexCL = semi.Contains("class");
              int indexIF = semi.Contains("interface");
              int indexST = semi.Contains("struct");

              int index = Math.Max(indexCL, indexIF);
              index = Math.Max(index, indexST);
              if (index != -1)
              {
              if (semi[index + 2] == ":")
              {
                  if (semi[index + 4] != ".")   // like A: B
                      e.inheritance += semi[index + 3] + " ";
                  else // like A: namespace.B
                      e.inheritance += semi[index + 5] + " ";
              }
              }
        }
コード例 #23
0
 public int complexityAnalysis(Elem e, object file, List<Elem> fileSetInfo)
 {
     int count = 0;
       CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
       semi.open(file as string);
       do
       {
       semi.getSemi();
       } while (semi.lineCount < e.begin);       // ignore all the semi before function begin
       while (semi.lineCount <= e.end)
       {
       if (semi.Contains("if") != -1)
           count++;
       if (semi.Contains("else") != -1)
           count++;
       if (semi.Contains("for") != -1)
           count++;
       if (semi.Contains("foreach") != -1)
           count++;
       if (semi.Contains("while") != -1 && semi[semi.count - 1] != ";")
           count++;
       if (semi.Contains("do") != -1)
           count++;
       if (semi.Contains("case") != -1)
           count++;
       if (semi.Contains("try") != -1)
           count++;
       if (semi.Contains("catch") != -1)
           count++;
       if (specialCB(semi))      // special curly brace
           count++;
       semi.getSemi();
       }
       return count;
 }
コード例 #24
0
 // fucntion detect using
 public void usingRelationship(CSsemi.CSemiExp semi, Elem e, List<Elem> fileSetInfo)
 {
     if(containFunctionName(semi)) // the semi contain name of function
       {
       foreach(Elem ele in fileSetInfo)
           if (semi.Contains(ele.name) > -1 && ele.name != e.name && ele.type == "class" || semi.Contains(ele.name) > -1 && ele.name != e.name && ele.type == "struct" || semi.Contains(ele.name) > -1 && ele.name != e.name && ele.type == "enum")
               if (e.usingrelationship.IndexOf(ele.name) < 0)
               {
                   e.usingrelationship += ele.name + " ";
               }
       }
 }
コード例 #25
0
 // function detect composition
 public void composition(CSsemi.CSemiExp semi, Elem e, List<Elem> fileSetInfo)
 {
     foreach (Elem elem in fileSetInfo)
       {
       if (semi.Contains(elem.name) != -1 && semi.Contains("=") != -1 && elem.type == "class" || semi.Contains(elem.name) != -1 && semi.Contains("=") != -1 && elem.type == "struct" || semi.Contains(elem.name) != -1 && semi.Contains("=") != -1 && elem.type == "enum")
           if (semi.Contains("new") == -1)
           {
               if (e.composition.IndexOf(elem.name) < 0 )
               {
                   e.composition += elem.name + " ";
               }
           }
       }
 }
コード例 #26
0
ファイル: XMLOutput.cs プロジェクト: WaverV/Projects
        // ------------------------<TestStub for XML Output>-------------------------
#if(TEST_XMLOUTPUT)

        static void Main(string[] args)
        {

            ElemRelation e = new ElemRelation();
            e.fromClass = "Derived";
            e.toClass = "Original";
            e.relationType = "Inheritance";

            RelationshipRepository.relationship_.Add(e);

            Elem elem = new Elem();
            elem.type = "function";
            elem.name = "Derived";
            elem.begin = 1;
            elem.end = 10;
            elem.functionComplexity = 2;
            OutputRepository.output_.Add(elem);
            XMLOutput xml = new XMLOutput();
            xml.displaySummary();
            xml.displayFunctionAnalysis();
            xml.displayRelation();
        }
コード例 #27
0
 public void relationshipanalysis(Elem e, object file, List<Elem> fileSetInfo)
 {
     CSsemi.CSemiExp semi = new CSsemi.CSemiExp();
       semi.open(file as string);
       do
       {
       semi.getSemi();
       } while (semi.lineCount < (e.begin-1)); // ignore semi before type define
       while (semi.lineCount <= e.end)
       {     // detect four kinds of relationship
       inheritance(semi, e);
       aggregation(semi, e, fileSetInfo);
       composition(semi, e, fileSetInfo);
       usingRelationship(semi, e, fileSetInfo);
       semi.getSemi();
       }
       return;
 }
コード例 #28
0
        ////helper method to calculation cohesion of a function
        public void processFunctionCohesion(Repository repository, CSsemi.CSemiExp local)
        {
            if (repository != null)
            {
                Elem elem = new Elem();
                elem.type = local[0];
                elem.name = local[1];

                string currentClassScope = repository.currentClassScope;
                Dictionary <string, List <Elem> > classDataMembers = repository.LocationsTable;

                if (classDataMembers.ContainsKey(currentClassScope))
                {
                    List <Elem> classScopeVariables = classDataMembers[currentClassScope];

                    string keyname = elem.type + elem.name;
                    Dictionary <string, List <Elem> > functions = repository.FunctionTable;

                    //if the dictionary already store the existing function
                    if (functions.ContainsKey(keyname))
                    {
                        //first find all variables that the current function has
                        for (int i = 0; i < classScopeVariables.Count; i++)
                        {
                            Elem tempElem = classScopeVariables[i];
                            if (elem.name.Equals(tempElem.name) && elem.type.Equals(tempElem.type))
                            {
                                List <Elem> functionVariables = functions[keyname];
                                functionVariables.Add(elem);
                                functions[keyname] = functionVariables;

                                //increment the cohesion for that function elem
                                for (int j = 0; j < repository.locations.Count; j++)
                                {
                                    Elem currentElem = repository.locations[i];

                                    //update class variable
                                    if (currentElem.name.Equals(elem.name))
                                    {
                                        repository.locations[j].cohesion += 1;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < classScopeVariables.Count; i++)
                        {
                            Elem tempElem = classScopeVariables[i];
                            if (elem.name.Equals(tempElem.name) && elem.type.Equals(tempElem.type))
                            {
                                List <Elem> functionVariables = new List <Elem>();
                                functionVariables.Add(elem);
                                functions[keyname] = functionVariables;

                                //increment the cohesion for that function elem
                                for (int j = 0; j < repository.locations.Count; j++)
                                {
                                    Elem currentElem = repository.locations[i];

                                    //update class variable
                                    if (currentElem.name.Equals(elem.name))
                                    {
                                        repository.locations[j].cohesion += 1;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
コード例 #29
0
        public override void doAction(CSsemi.CSemiExp semi)
        {
            Elem elem = new Elem();
              elem.type = semi[0];  // expects type
              elem.name = semi[1];  // expects name
              elem.begin = repo_.semi.lineCount - 1;
              repo_.stack.push(elem);
              if (elem.type == "control" || elem.name == "anonymous")
            return;
              repo_.locations.Add(elem);

              if (AAction.displaySemi)
              {
            Console.Write("\n  line# {0,-5}", repo_.semi.lineCount - 1);
            Console.Write("entering ");
            string indent = new string(' ', 2 * repo_.stack.count);
            Console.Write("{0}", indent);
            this.display(semi); // defined in abstract action
              }
              if(AAction.displayStack)
            repo_.stack.display();
        }
コード例 #30
0
 public int ComplexityAnalyze(Elem e, Object file)
 {
     CSsemi.CSemiExp local = new CSsemi.CSemiExp();
       local.open(file as string);
       int complexity = 1;
       while(local.lineCount<e.begin)
       {
       local.getSemi();
       }
       while(local.lineCount <= e.end)
       {
       local.getSemi();
       if (local.Contains("if") != -1)
           complexity++;
       if (local.Contains("else") != -1)
           complexity++;
       if (local.Contains("for") != -1)
           complexity++;
       if (local.Contains("foreach") != -1)
           complexity++;
       if (local.Contains("while") != -1)
           complexity++;
       if (local.Contains("try") != -1)
           complexity++;
       if (local.Contains("catch") != -1)
           complexity++;
       if (local.Contains("case") != -1)
           complexity++;
       }
       return complexity;
 }
コード例 #31
0
        public override void doAction(ITokenCollection semi)//IToken need more than get ss
        {
            Display.displayActions(actionDelegate, "action PushStack");
            ++repo_.scopeCount;//manage scope stack ss
            Elem elem = new Elem();


            elem.type = semi[0];     // expects type, i.e., namespace, class, struct, ..
            elem.name = semi[1];     // expects name

            //Checked if the type name matches with our requirement and added in Type Table
            string[] IncludeType = { "class", "enum", "struct", "delegate", "namespace", "interface", "using" };
            foreach (string stoken in IncludeType)
            {
                if (stoken == semi[0])
                {
                    String filename  = repo_.semi.getFileName();
                    String curr_file = System.IO.Path.GetFileName(filename);

                    if (semi[0].Equals("namespace"))//To create Type Table1q
                    {
                        holdnamespace = semi[1];
                        tt.add(semi[1], curr_file, semi[0]);
                    }
                    else if (semi[0].Equals("using"))//To create Alias Table
                    {
                        tt.addalias(semi[1], curr_file, semi[2]);
                        tt.addalias(semi[1], curr_file, semi[2]);
                    }
                    else
                    {
                        tt.add(semi[1], curr_file, holdnamespace);
                    }
                }
            }



            elem.beginLine       = repo_.semi.lineCount() - 1;
            elem.endLine         = 0; // will be set by PopStack action
            elem.beginScopeCount = repo_.scopeCount;
            elem.endScopeCount   = 0; // will be set by PopStack action
            repo_.stack.push(elem);

            // display processing details if requested

            if (AAction.displayStack)
            {
                repo_.stack.display();
            }
            if (AAction.displaySemi)
            {
                Console.Write("\n  line# {0,-5}", repo_.semi.lineCount() - 1);
                Console.Write("entering ");
                string indent = new string(' ', 2 * repo_.stack.count);
                Console.Write("{0}", indent);
                this.display(semi); // defined in abstract action
            }

            // add starting location if namespace, type, or function

            if (elem.type == "control" || elem.name == "anonymous")//Never be controlled anonymous ss ni
            {
                return;
            }
            repo_.locations.Add(elem);
        }
コード例 #32
0
        // function to analyze using relationship
        public void UsingAnalyze(CSsemi.CSemiExp local, List<Elem> TABLE, Elem e)
        {
            DetectFunction df = new DetectFunction();
              if (df.test(local) == true && local.Contains("(") != -1 && local.Contains(")") != -1 && local.Contains("{") != -1)
              {
              foreach (Elem ele in TABLE)
              {
                  if (local.Contains(ele.name) > -1 && ele.UsingFlag == false && (ele.type == "class" || ele.type == "interface" || ele.type == "enum"))
                  {
                      ele.UsingFlag = true;
                      Console.Write("\n using: ");
                      int index = local.Contains(ele.name);
                      Console.Write(" {0}", local[index]);
                      continue;
                  }
              }

              }
        }
コード例 #33
0
        static void Main(string[] args)
        {
            string filename = "1";
            XMLBuilder xmlbdr = new XMLBuilder();
            List<Elem> table = new List<Elem>();
            Elem ns = new Elem();
            Elem cl = new Elem();
            Elem en = new Elem();
            Elem fn = new Elem();
            Elem st = new Elem();
            Elem it = new Elem();

            ns.name = "myNamespace";
            ns.type = "namespace";
            ns.beginLine = 1;
            ns.endLine = 100;

            it.name = "myInterface";
            it.type = "interface";
            it.beginLine = 10;
            it.endLine = 20;

            st.name = "myStruct";
            st.type = "struct";
            st.beginLine = 30;
            st.endLine = 35;

            cl.name = "myClass";
            cl.type = "class";
            cl.beginLine = 40;
            cl.endLine = 70;

            fn.name = "myFunction";
            fn.type = "function";
            fn.beginLine = 50;
            fn.endLine = 60;

            en.name = "myEnum";
            en.type = "enum";
            en.beginLine = 80;
            en.endLine = 90;

            table.Add(ns);
            table.Add(it);
            table.Add(st);
            table.Add(cl);
            table.Add(fn);
            table.Add(en);

            xmlbdr.XMLBuild(table,filename);
        }
コード例 #34
0
 // function detect composition
 public static void composition(CSsemi.CSemiExp semi, Elem e, List<Elem> fileSetInfo)
 {
     foreach (Elem elem in fileSetInfo)
       {
       if (semi.Contains(elem.name) != -1 && semi.Contains("=") != -1 && elem.type == "class" && semi.Contains("=") > semi.Contains(elem.name) || semi.Contains(elem.name) != -1 && semi.Contains("=") != -1 && elem.type == "struct" && semi.Contains("=") > semi.Contains(elem.name) || semi.Contains(elem.name) != -1 && semi.Contains("=") != -1 && elem.type == "enum" && semi.Contains("=") > semi.Contains(elem.name))
           if (semi.Contains("new") == -1)
           {
               if (e.dependency.IndexOf(elem.name) < 0 && e.name != elem.name)
               {
                   e.dependency += elem.name + " ";
               }
           }
       }
 }
コード例 #35
0
 public void RelationshipAnalyzer(Elem e, Object file, List<Elem> TABLE)
 {
     CSsemi.CSemiExp local = new CSsemi.CSemiExp();
       local.open(file as string);
       while (local.lineCount < e.begin)
       {
       local.getSemi();
       }
       while (local.lineCount < e.end)
       {
       InheritanceAnalyze(local, TABLE);
       AggregationAnalyze(local, TABLE);
       CompositionAnalyze(local, TABLE);
       UsingAnalyze(local, TABLE, e);
       local.getSemi();
       }
 }
コード例 #36
0
ファイル: RulesAndActions.cs プロジェクト: WaverV/Projects
        public override void doAction(CSsemi.CSemiExp semi, string file)
        {
            Elem elem = new Elem();
            elem.type = semi[0];  // expects type
            if (elem.type == "scopeDetect")   //for incrementing the complexity of the function
            {
                int i = repo_.locations.Count;
                repo_.locations[i - 1].functionComplexity = repo_.locations[i - 1].functionComplexity + 1;
                return;
            }
            if (elem.type == "function")
            {
                elem.functionComplexity = 1;
            }
            elem.name = semi[1];  // expects name
            elem.begin = repo_.semi.lineCount - 1;
            elem.end = 0;
            elem.fileName = file;
            repo_.stack.push(elem);
            if (elem.type == "control" || elem.name == "anonymous")
                return;
            repo_.locations.Add(elem);
            OutputRepository.output_.Add(elem);

            if (AAction.displaySemi)
            {
                Console.Write("\n  line# {0,-5}", repo_.semi.lineCount - 1);
                Console.Write("entering ");
                string indent = new string(' ', 2 * repo_.stack.count);
                Console.Write("{0}", indent);
                this.display(semi); // defined in abstract action
            }
            if (AAction.displayStack)
                repo_.stack.display();
        }