From 7ac1b3939eb752bc6628ce6aa5bb13224a08f40f Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Fri, 29 May 2015 21:35:47 -0400 Subject: [PATCH] nitx: add hierarchies commands Signed-off-by: Alexandre Terrasa --- src/doc/doc_phases/doc_console.nit | 85 +++++++++++++++++++++++++++++++++++- src/nitx.nit | 3 +- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/doc/doc_phases/doc_console.nit b/src/doc/doc_phases/doc_console.nit index e14fa46..b6d08dc 100644 --- a/src/doc/doc_phases/doc_console.nit +++ b/src/doc/doc_phases/doc_console.nit @@ -20,6 +20,7 @@ module doc_console import semantize import doc_extract +import doc_poset import doc::console_templates # Nitx handles console I/O. @@ -66,6 +67,11 @@ class Nitx print "\treturn: \t\tlookup methods returning the corresponding 'Type'" print "\tnew: \t\tlookup methods creating new instances of 'Type'" print "\tcall: \t\tlookup methods calling 'name'" + print "\nHierarchy lookup:" + print "\tparents: \tlist direct parents of 'Class'" + print "\tancestors: \tlist all ancestors of 'Class'" + print "\tchildren: \tlist direct children of 'Class'" + print "\tdescendants: \tlist all descendants of 'Class'" print "\nCode lookup:" print "\tcode: \t\tdisplay the source code associated to the 'name' entity" print "\n" @@ -127,7 +133,14 @@ interface NitxQuery return new CallQuery(query_string) else if query_string.has_prefix("code:") then return new CodeQuery(query_string) - + else if query_string.has_prefix("parents:") then + return new ParentsQuery(query_string) + else if query_string.has_prefix("ancestors:") then + return new AncestorsQuery(query_string) + else if query_string.has_prefix("children:") then + return new ChildrenQuery(query_string) + else if query_string.has_prefix("descendants:") then + return new DescendantsQuery(query_string) end return new CommentQuery("comment: {query_string}") end @@ -359,6 +372,76 @@ class PageMatch end end +# Search in class or module hierarchy of a `MEntity`. +# +# It actually searches for pages about the mentity and extracts the +# pre-calculated hierarchies by the `doc_post` phase. +abstract class HierarchiesQuery + super DocQuery + + redef fun make_results(nitx, results) do + var page = new DocPage("hierarchy", "Hierarchy") + for result in results do + if not result isa PageMatch then continue + var rpage = result.page + if not rpage isa MClassPage then continue + page.root.add_child build_article(rpage) + end + return page + end + + # Build an article containing the hierarchy list depending on subclasses. + private fun build_article(page: MClassPage): DocArticle is abstract +end + +# List all parents of a `MClass`. +class AncestorsQuery + super HierarchiesQuery + + redef fun build_article(page) do + return new MEntitiesListArticle( + "ancerstors", + "Ancestors for {page.mentity.name}", + page.ancestors.to_a) + end +end + +# List direct parents of a `MClass`. +class ParentsQuery + super HierarchiesQuery + + redef fun build_article(page) do + return new MEntitiesListArticle( + "parents", + "Parents for {page.mentity.name}", + page.parents.to_a) + end +end + +# List direct children of a `MClass`. +class ChildrenQuery + super HierarchiesQuery + + redef fun build_article(page) do + return new MEntitiesListArticle( + "children", + "Children for {page.mentity.name}", + page.children.to_a) + end +end + +# List all descendants of a `MClass`. +class DescendantsQuery + super HierarchiesQuery + + redef fun build_article(page) do + return new MEntitiesListArticle( + "descendants", + "Descendants for {page.mentity.name}", + page.children.to_a) + end +end + # A query to search source code from a file name. class CodeQuery super MetaQuery diff --git a/src/nitx.nit b/src/nitx.nit index 23490a8..cf5ab95 100644 --- a/src/nitx.nit +++ b/src/nitx.nit @@ -48,7 +48,8 @@ private class NitxPhase new ExtractionPhase(toolcontext, doc), new MakePagePhase(toolcontext, doc), new ConcernsPhase(toolcontext, doc), - new StructurePhase(toolcontext, doc): DocPhase] + new StructurePhase(toolcontext, doc), + new POSetPhase(toolcontext, doc): DocPhase] for phase in phases do toolcontext.info("# {phase.class_name}", 1) -- 1.7.9.5