コード例 #1
0
ファイル: ConsoleLogger.cs プロジェクト: ndung/NDepCheck
 private static string FormatMessage(Dependency dependency, ViolationType violationType)
 {
     var message = violationType == ViolationType.Warning ? dependency.QuestionableMessage() : dependency.IllegalMessage();
     if (dependency.FileName != null) {
         var sb = new StringBuilder(message);
         sb.Append(" (probably at ").Append(dependency.FileName);
         if (dependency.StartLine > 0) {
             sb.Append(":").Append(dependency.StartLine);
         }
         sb.Append(")");
         return sb.ToString();
     } else {
         return message;
     }
 }
コード例 #2
0
ファイル: DependencyRule.cs プロジェクト: hmmueller/NDepCheck
 public override bool Matches(Dependency d)
 {
     return d.UsedNamespace == d.UsingNamespace;
 }
コード例 #3
0
ファイル: DependencyRule.cs プロジェクト: hmmueller/NDepCheck
 public override bool Matches(Dependency d)
 {
     return d.UsedItem.StartsWith(_usedFixedPrefix) && d.UsingItem.StartsWith(_usingFixedPrefix);
 }
コード例 #4
0
ファイル: DependencyRule.cs プロジェクト: hmmueller/NDepCheck
 public override bool Matches(Dependency d)
 {
     return d.UsingItem.StartsWith(_usingFixedPrefix)
            && d.UsedItem.StartsWith(_usedFixedPrefix)
            && IsClassTail(d.UsedItem.Substring(_usedFixedPrefix.Length));
 }
コード例 #5
0
ファイル: DependencyRule.cs プロジェクト: hmmueller/NDepCheck
 public override bool Matches(Dependency d)
 {
     if (d.UsedItem.StartsWith(_usedFixedPrefix) && d.UsingItem.StartsWith(_usingFixedPrefix)) {
         return Regex.IsMatch(d.UsingItem + SEPARATOR + d.UsedItem, _rex);
     } else {
         return false;
     }
 }
コード例 #6
0
ファイル: DependencyRule.cs プロジェクト: hmmueller/NDepCheck
 public override bool Matches(Dependency d)
 {
     Match usingMatch = Regex.Match(d.UsingItem, _usingRegex);
     if (usingMatch.Success) {
         string usingRest = d.UsingItem.Substring(usingMatch.Value.Length);
         if (IsClassTail(usingRest)) {
             Match usedMatch = Regex.Match(d.UsedItem, _usedRegex);
             string usedRest = d.UsedItem.Substring(usedMatch.Value.Length);
             return IsClassTail(usedRest);
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
コード例 #7
0
ファイル: DependencyRule.cs プロジェクト: hmmueller/NDepCheck
 public override bool Matches(Dependency d)
 {
     if (d.UsedItem.StartsWith(_usedFixedPrefix) && d.UsingItem.StartsWith(_usingFixedPrefix)) {
         string check = d.UsingItem + SEPARATOR + d.UsedItem;
         Match match = Regex.Match(check, _rex);
         string rest = check.Substring(match.Value.Length);
         return IsClassTail(rest);
     } else {
         return false;
     }
 }
コード例 #8
0
ファイル: DependencyRule.cs プロジェクト: hmmueller/NDepCheck
 public abstract bool Matches(Dependency d);
コード例 #9
0
ファイル: DependencyRule.cs プロジェクト: hmmueller/NDepCheck
 /// <summary>
 /// Check whether a concrete using item and used item
 /// match this dependency.
 /// </summary>
 public bool Matches(Dependency d)
 {
     if (Log.IsDebugEnabled) {
         Log.WriteDebug("Checking " + d + " against " + this);
     }
     if (_ruleMatch.Matches(d)) {
         _hitCount++;
         _rep.MarkHit();
         return true;
     } else {
         return false;
     }
 }
コード例 #10
0
 private bool Check(IAssemblyContext assemblyContext, Dependency d)
 {
     bool ok = false;
     if (Log.IsVerboseEnabled) {
         Log.WriteInfo("Checking " + d);
     }
     if (_forbidden.Any(r => r.Matches(d))) {
         goto DONE;
     }
     if (_allowed.Any(r => r.Matches(d))) {
         ok = true;
         goto DONE;
     }
     if (_questionable.Any(r => r.Matches(d))) {
         var ruleViolation = new RuleViolation(d, ViolationType.Warning);
         Log.WriteViolation(ruleViolation);
         if (assemblyContext != null) {
             assemblyContext.Add(ruleViolation);
         }
         ok = true;
     }
     DONE:
     if (!ok) {
         var ruleViolation = new RuleViolation(d, ViolationType.Error);
         Log.WriteViolation(ruleViolation);
         if (assemblyContext != null) {
             assemblyContext.Add(ruleViolation);
         }
     }
     return ok;
 }
コード例 #11
0
        private void ComputeDependencyEdge(IEnumerable <GraphAbstraction> graphAbstractions,
                                           IEnumerable <DependencyRuleGroup> ruleSet,
                                           Dependency d, Dictionary <string, Node> nodes)
        {
            string usingMatch = null;
            string usedMatch  = null;

            foreach (GraphAbstraction ga in graphAbstractions)
            {
                string m = ga.Match(d.UsingItem);
                if (m != null)
                {
                    if (usingMatch == null || usingMatch.Length < m.Length)
                    {
                        usingMatch = m;
                    }
                }
                string n = ga.Match(d.UsedItem);
                if (n != null)
                {
                    if (usedMatch == null || usedMatch.Length < n.Length)
                    {
                        usedMatch = n;
                    }
                }
            }
            if (usingMatch == null)
            {
                Log.WriteInfo("No graph output pattern found for drawing " + d.UsingItem + " - I ignore it");
            }
            else if (usedMatch == null)
            {
                Log.WriteInfo("No graph output pattern found for drawing " + d.UsedItem + " - I ignore it");
            }
            else if (usingMatch == "" || usedMatch == "")
            {
                // ignore this edge!
            }
            else
            {
                bool isOk = _checker.Check(null, ruleSet, new List <Dependency> {
                    d
                }, false);

                // Filter out loops that are ok - they are not shown.
                // All other edges (non-loops; and non-ok loops) are shown.
                if (usingMatch != usedMatch || !isOk)
                {
                    usingMatch = "\"" + usingMatch + "\"";
                    Node usingNode = GetOrCreateNode(nodes, usingMatch);
                    usedMatch = "\"" + usedMatch + "\"";
                    Node usedNode = GetOrCreateNode(nodes, usedMatch);
                    Edge ed       = usingNode.FindOrAddEdgeTo(usedNode);
                    if (!isOk)
                    {
                        if (ed.NotOkExample == null)
                        {
                            ed.NotOkExample = d;
                        }
                        ed.NotOkCt++;
                    }
                }
            }
        }
コード例 #12
0
ファイル: DependencyGrapher.cs プロジェクト: ndung/NDepCheck
 public Edge(Node usingNode, Node usedNode)
 {
     _usingNode = usingNode;
     UsedNode = usedNode;
     NotOkCt = 0;
     NotOkExample = null;
 }
コード例 #13
0
ファイル: DependencyGrapher.cs プロジェクト: ndung/NDepCheck
        private void ComputeDependencyEdge(IEnumerable<GraphAbstraction> graphAbstractions, 
            IEnumerable<DependencyRuleGroup> ruleSet,
                                           Dependency d, Dictionary<string, Node> nodes)
        {
            string usingMatch = null;
            string usedMatch = null;
            foreach (GraphAbstraction ga in graphAbstractions) {
                string m = ga.Match(d.UsingItem);
                if (m != null) {
                    if (usingMatch == null || usingMatch.Length < m.Length) {
                        usingMatch = m;
                    }
                }
                string n = ga.Match(d.UsedItem);
                if (n != null) {
                    if (usedMatch == null || usedMatch.Length < n.Length) {
                        usedMatch = n;
                    }
                }
            }
            if (usingMatch == null) {
                Log.WriteInfo("No graph output pattern found for drawing " + d.UsingItem + " - I ignore it");
            } else if (usedMatch == null) {
                Log.WriteInfo("No graph output pattern found for drawing " + d.UsedItem + " - I ignore it");
            } else if (usingMatch == "" || usedMatch == "") {
                // ignore this edge!
            } else {
                bool isOk = _checker.Check(null, ruleSet, new List<Dependency> {d}, false);

                // Filter out loops that are ok - they are not shown.
                // All other edges (non-loops; and non-ok loops) are shown.
                if (usingMatch != usedMatch || !isOk) {
                    usingMatch = "\"" + usingMatch + "\"";
                    Node usingNode = GetOrCreateNode(nodes, usingMatch);
                    usedMatch = "\"" + usedMatch + "\"";
                    Node usedNode = GetOrCreateNode(nodes, usedMatch);
                    Edge ed = usingNode.FindOrAddEdgeTo(usedNode);
                    if (!isOk) {
                        if (ed.NotOkExample == null)
                            ed.NotOkExample = d;
                        ed.NotOkCt++;
                    }
                }
            }
        }