diff --git a/deft-browse/deft-browse.dylan b/deft-browse/deft-browse.dylan index 0e34a9f..5dfacb6 100644 --- a/deft-browse/deft-browse.dylan +++ b/deft-browse/deft-browse.dylan @@ -208,3 +208,54 @@ define command inspect ($deft-commands) implementation inspect-dylan-object(dylan-object-name); end; + +define method print-class-subclasses + (project :: , object, depth :: , max-depth :: ) + let id = environment-object-id(project, object); + format-out("%s is not a class.\n", id.id-name); +end method; + +define method print-class-subclasses + (project :: , object == #f, depth :: , max-depth :: ) + format-out("Object not found.\n"); +end method; + +define method print-class-subclasses + (project :: , object :: , depth :: , max-depth :: ) + let id = environment-object-id(project, object); + let subclasses = class-direct-subclasses(project, object); + for (sc in subclasses) + let sc-id = environment-object-id(project, sc); + // use 2 column indent, starting from column 2 + let indent = make(, size: (depth + 1) * 2); + format-out("%s%s\n", indent, sc-id.id-name); + if (depth < max-depth) + print-class-subclasses(project, sc, depth + 1, max-depth); + end if; + end for; +end method; + +define function subclasses-for-class(name :: , max-depth :: ) + let project = dylan-current-project($deft-context); + if (project) + let library = project-library(project); + let object = find-environment-object(project, name, + library: library, + module: first(library-modules(project, library))); + print-class-subclasses(project, object, 0, max-depth); + else + format-out("No open project found.\n"); + end if +end function; + +define command subclasses ($deft-commands) + help "Display the subclasses of a class."; + simple parameter dylan-class-name :: , + help: "the dylan class", + required?: #t; + named parameter depth :: , + help: "the hierarchy depth", + required?: #f; + implementation + subclasses-for-class(dylan-class-name, if (depth) depth else 0 end); +end;