示例#1
0
        internal static void CheckComplexityMetrics(List <KBObject> objs, IOutputService output, int maxNestLevel, int maxComplexityLevel, int maxCodeBlock, int maxParametersCount)
        {
            foreach (KBObject obj in objs)
            {
                if (obj is Transaction || obj is WebPanel || obj is Procedure || obj is WorkPanel)
                {
                    if (isGenerated(obj) && !isGeneratedbyPattern(obj))
                    {
                        string source = Utility.ObjectSourceUpper(obj);
                        source = Utility.RemoveEmptyLines(source);

                        string sourceWOComments = Utility.ExtractComments(source);
                        sourceWOComments = Utility.RemoveEmptyLines(sourceWOComments);

                        int CodeBlock       = Utility.MaxCodeBlock(sourceWOComments);
                        int NestLevel       = Utility.MaxNestLevel(sourceWOComments);
                        int ComplexityLevel = Utility.ComplexityLevel(sourceWOComments);

                        KBObjectPart part = Utility.ObjectSourcePart(obj);

                        int parametersCount = ParametersCountObject(obj);
                        if (NestLevel > maxNestLevel)
                        {
                            OutputError err = new OutputError("Nested level too high (" + NestLevel.ToString() + "). Recommended max: " + maxNestLevel.ToString(), MessageLevel.Error, new KBObjectPosition(part));
                            output.Add("KBDoctor", err);
                        }
                        if (ComplexityLevel > maxComplexityLevel)
                        {
                            OutputError err = new OutputError("Complexity too high(" + ComplexityLevel.ToString() + ").Recommended max: " + maxComplexityLevel.ToString(), MessageLevel.Error, new KBObjectPosition(part));
                            output.Add("KBDoctor", err);
                        }

                        if (CodeBlock > maxCodeBlock)
                        {
                            OutputError err = new OutputError("Code block too large(" + CodeBlock.ToString() + ").Recommended max: " + maxCodeBlock.ToString(), MessageLevel.Error, new KBObjectPosition(part));
                            output.Add("KBDoctor", err);
                        }
                        if (parametersCount > maxParametersCount)
                        {
                            OutputError err = new OutputError("Too many parameters (" + parametersCount.ToString() + ").Recommended max: " + maxParametersCount.ToString(), MessageLevel.Error, new KBObjectPosition(part));
                            output.Add("KBDoctor", err);
                        }
                    }
                }
            }
        }
示例#2
0
 internal static void CodeCommented(List <KBObject> objs, IOutputService output)
 {
     foreach (KBObject obj in objs)
     {
         string source = Utility.ObjectSourceUpper(obj);
         source = Utility.RemoveEmptyLines(source);
         string codeCommented = Utility.CodeCommented(source);
         codeCommented = codeCommented.Replace("'", "");
         codeCommented = codeCommented.Replace(">", "");
         codeCommented = codeCommented.Replace("<", "");
         if (codeCommented != "")
         {
             KBObjectPart part = Utility.ObjectSourcePart(obj);
             OutputError  err  = new OutputError("Commented code", MessageLevel.Warning, new KBObjectPosition(part));
             output.Add("KBDoctor", err);
         }
     }
 }