deprecate old Help class
[supercollider.git] / SCClassLibrary / DefaultLibrary / dumpFullInterface.sc
blobf4122ba3ac91e9166de7e16867b440fbdcd7feba
1 + Class {
3         dumpFullInterface {
5                 ("\nFull Interface for " ++ this.name).postln;
7                 // post the superclasses
8                 ("\nSuperclasses: " ++ this.superclasses).postln;
10                 // Instance methods
11                 this.dumpAllMethods;
13                 // Class methods
14                 this.class.dumpAllMethods;
15         }
17         dumpAllMethods {
18                 var methodlist, superclasses, prependString, superPrependString, name;
19                 methodlist = IdentitySet[];
20                 if(this.isMetaClass,
21                         {       prependString = "\nClass Methods for ";
22                                 superPrependString = "\nClass Methods inherited from ";
23                                 name = this.asString.copyToEnd(5);
24                                 superclasses = name.asSymbol.asClass.superclasses;
25                         },
26                         {       prependString = "\nInstance Methods for ";
27                                 superPrependString = "\nInstance Methods inherited from ";
28                                 name = this.name;
29                                 superclasses =  this.superclasses;
30                         }
31                 );
32                 (prependString ++ name ++ "\n").postln;
33                 this.methods.do({ arg meth;
34                         var numargs, methname;
35                         methname = meth.name;
36                         methodlist.add(methname);
37                         numargs = meth.argNames.size - 1;
38                         "   ".post;
39                         methname.post;
40                         " ( ".post;
41                         meth.argNames.do({ arg name, i;
42                                 if (i > 0, { // skip 'this'
43                                         name.post;
44                                         if (i < numargs, {
45                                                 ", ".post;
46                                         });
47                                 });
48                         });
49                         " )\n".post;
50                 });
51                 // Methods for superclasses
52                 superclasses.do({ arg superclass, superobject, supername;
53                         if(this.isMetaClass,
54                                 {
55                                         superobject = superclass.class;
56                                 },
57                                 {
58                                         superobject = superclass;
59                                 }
60                         );
61                         supername = superobject.asString;
62                         if(supername.containsStringAt(0, "Meta_"), { supername = supername.copyToEnd(5) });
63                         (superPrependString ++ supername ++ "\n").postln;
64                         superobject.methods.do({ arg meth;
65                                 var numargs, methname;
66                                 methname = meth.name;
67                                 if(methodlist.includes(methname).not, {
68                                         methodlist.add(methname);
69                                         numargs = meth.argNames.size - 1;
70                                         "   ".post;
71                                         methname.post;
72                                         " ( ".post;
73                                         meth.argNames.do({ arg name, i;
74                                                 if (i > 0, { // skip 'this'
75                                                         name.post;
76                                                         if (i < numargs, {
77                                                                 ", ".post;
78                                                         });
79                                                 });
80                                         });
81                                         " )\n".post;
82                                 });
83                         });
85                 });
86                 // include methods for Class
88                 if(this.isMetaClass, {"\nMethods inherited from Class\n".postln; Class.dumpInterface; });
90         }
92         dumpMethodList {
93                 var     mList, sc;
95                 mList = IdentityDictionary.new;         // repository for methods
96                 this.collectMethods(mList);                     // get them
98                 sc = this;      // to print superclass chain
99                 { sc != Object }.while({
100                         (sc.name ++ " : ").post;
101                         sc = sc.superclass;
102                 });
103                 "Object".postln;
105                 mList.asSortedArray.do({ |pair|
106                         (pair[0] ++ " <" ++ pair[1].ownerClass.name ++ "-"
107                                 ++ pair[0] ++ ">").post;
108                         (pair[1].argNames.size > 1).if({
109                                 " (".post;
110                                 pair[1].argNames.do({ |argname, i|
111                                         (i > 1).if({ ", ".post });
112                                         (i > 0).if({ argname.post; });
113                                 });
114                                 ")".post;
115                         });
116                         "".postln;
117                 });
118         }
120         collectMethods { arg list;
121                         // only collect if not Object or Class
122                 ((this.name != \Object) && (this.name != \Class)).if({                  this.methods.do({ |meth|
123                                         // if keys already includes methodname,
124                                         // then a subclass has overridden this superclass method, so don't add
125                                 list.keys.includes(meth.name).not.if({
126                                         list.put((meth.name.asString).asSymbol, meth);
127                                 });
128                         });
129                         superclass.asClass.collectMethods(list);  // go up a level
130                 });
131         }
133         helpFileForMethod {
134                 arg methodSymbol;
135                 this.findRespondingMethodFor(methodSymbol).ownerClass.help;
136         }
138                 // show all subclasses of this class sorted in alpha order (not tree order)
139         dumpSubclassList {
140                 var list, listCollector;
141                         // recursive function to collect class objects
142                 listCollector = { arg node, l;
143                         l.add(node);
144                         node.subclasses.do({ arg n; listCollector.value(n, l) });
145                 };
146                 list = List.new;
147                 listCollector.value(this, list);        // do the recursion
148                 list.sort({ arg a, b; a.name < b.name })        // sort it
149                         .do({ arg n;            // and iterate to post the class names (w/ supers)
150                         n.name.post;
151                         n.superclasses.do({ arg s; (" : " ++ s.name).post; });
152                         "\n".post;
153                 });
154                 ("\n" ++ list.size.asString ++ " classes listed.").postln;
155         }