Пример #1
0
        static public void doAnalysis(string[] files)
        {
            int skipCount = 0;

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

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

            foreach (string file in files)
            {
                if (Display.showFiles)
                {
                    Display.displayString("");
                }
                Display.displayFiles(act, "Processing file: " + file);

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

                try
                {
                    while (semi.getSemi())
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                List <Elem> table = rep.locations;
                if (table.Count == 0)
                {
                    ++skipCount;
                    continue;
                }

                semi.close();
                rep.LocationsTable[file] = table;
                rep.locations            = new List <Elem>();
            }

            displaySkipped(skipCount);
            displayAnalysis(rep);
            analysisSummary(rep);
        }
Пример #2
0
        public override bool test(CSemiExp semi)
        {
            HashSet <string> definedSet = UserType.userDefinedSet;

            string[] specialTokens = { "get", "set" };
            Display.displayFiles(actionDelegate, "rule Detect Association");
            int publicIndex    = semi.Contains("public");
            int staticIndex    = semi.Contains("static");
            int privateIndex   = semi.Contains("private");
            int protectedIndex = semi.Contains("protected");

            //ignoreing special words as aggregation
            for (int i = 0; i < specialTokens.Length; i++)
            {
                if (semi.Contains(specialTokens[i]) != -1)
                {
                    return(false);
                }
            }

            //edge case for a single semi colon
            if (semi.count == 1 && semi[0].Equals(";"))
            {
                return(false);
            }

            //these characteristics is probably a function call rather than a declaration
            if (semi.Contains(".") != -1 && semi.Contains("(") != -1)
            {
                return(false);
            }

            if (semi.Contains("class") == -1 && semi.Contains("interface") == -1)    //not class
            //make sure it is not a function
            {
                if (semi.Contains("(") != -1 && semi.Contains(";") == -1)
                {
                    return(false);
                }

                //parse for the index of the declaration type
                int typeIndex = 0;  //the default type index is 0 if no special variables
                //the coupling might datastructure related
                if (semi.Contains("<") != -1)
                {
                    typeIndex = semi.Contains("<") + 1;
                }
                else if (staticIndex != -1)
                {
                    typeIndex = staticIndex + 1;
                }
                else if (publicIndex != -1 || privateIndex != -1 || protectedIndex != -1)
                {
                    int privacyIndex = Math.Max(Math.Max(publicIndex, privateIndex), protectedIndex);
                    typeIndex = privacyIndex + 1;
                }
                else
                {
                    for (int i = 0; i < semi.count; i++)
                    {
                        if (UserType.userDefinedSet.Contains(semi[i]))
                        {
                            typeIndex = i;
                            break;
                        }
                    }
                }

                //keep track of the declaration type
                string declarationType = semi[typeIndex];

                //store all data type and data member in repo for cohesion use
                Repository repository = Repository.getInstance();
                if (repository.currentClassScope != null && repository.currentClassScope != "")
                {
                    CSsemi.CSemiExp local = new CSemiExp();
                    local.Add(declarationType);
                    local.Add(semi[typeIndex + 1]);

                    if (repository.currentFunctionScope == null || repository.currentFunctionScope.Equals(""))
                    {
                        //since we are not in a function scope we can just store the class data members
                        storeClassDataMember(repository, local);
                    }
                    else
                    {
                        //we are in a function scope so process the varibales in the function for cohesion
                        processFunctionCohesion(repository, local);
                    }
                }

                //only do action if this is user defined type for coupling
                if (UserType.userDefinedSet.Contains(declarationType))
                {
                    CSsemi.CSemiExp local = new CSemiExp();
                    local.Add(declarationType);
                    if (semi.Contains("new") != -1)
                    {
                        local.Add("new");
                    }
                    doActions(local);
                    return(true);
                }
            }

            return(false);
        }