Merge: Nitsmell : Adding new code smells and print console updated
[nit.git] / src / test_model_visitor.nit
index 9dd07e8..d7cc947 100644 (file)
@@ -25,17 +25,26 @@ class TestModelVisitor
        super ModelVisitor
 
        redef fun visit(e) do
-               if not doc_only or e.mdoc != null then
-                       cpt.inc(e.class_name)
+               cpt.inc(e.class_name)
+
+               if not e isa Model then
+                       var name = e.full_name
+                       var old = names.get_or_null(name)
+                       if old != null then
+                               names[name + "!CONFLICT!" + old.class_name] = old
+                               name = name + "!CONFLICT!" + e.class_name
+                       end
+                       names[name] = e
                end
+
                e.visit_all(self)
        end
 
        # Counter of visited entities (by classnames)
        var cpt = new Counter[String]
 
-       # Do the visitor only count entities with a documentation?
-       var doc_only = false
+       # Dictionary of full_names
+       var names = new Map[String, MEntity]
 end
 
 # The body of the specific work.
@@ -47,12 +56,15 @@ do
 
        print "All entities, including fictive ones:"
        var v = new TestModelVisitor
+       v.min_visibility = private_visibility
        v.include_fictive = true
        v.enter_visit(model)
        v.cpt.print_elements(10)
+       var names = v.names
 
        print "All entities:"
        v = new TestModelVisitor
+       v.min_visibility = private_visibility
        v.enter_visit(model)
        v.cpt.print_elements(10)
 
@@ -65,7 +77,46 @@ do
        print "\nAll documented non-private entities:"
        v = new TestModelVisitor
        v.min_visibility = protected_visibility
-       v.doc_only = true
+       v.include_empty_doc = false
+       v.enter_visit(model)
+       v.cpt.print_elements(10)
+
+       print "\nAll public entities:"
+       v = new TestModelVisitor
+       v.min_visibility = public_visibility
+       v.enter_visit(model)
+       v.cpt.print_elements(10)
+
+       print "\nAll documented public entities:"
+       v = new TestModelVisitor
+       v.min_visibility = public_visibility
+       v.include_empty_doc = false
        v.enter_visit(model)
        v.cpt.print_elements(10)
+
+       print "\nNames:"
+       print "\n# Classes of entities"
+       var cpt
+       cpt = new Counter[String]
+       for n, e in names do
+               cpt.inc(e.class_name)
+       end
+       cpt.print_summary
+       cpt.print_elements(10)
+
+       print "\n# Name length of entities"
+       cpt = new Counter[String]
+       for n, e in names do
+               cpt[n] = n.length
+       end
+       cpt.print_summary
+       cpt.print_elements(10)
+
+       print "\n# All entities"
+       for n, e in names do
+               var c = ""
+               var d = e.mdoc_or_fallback
+               if d != null and d.content.not_empty then c = d.content.first
+               print "{n}\t{e.class_name}\t{e.location}\t{c}"
+       end
 end