ClassDescription.st
changeset 2483 fb469352be7d
parent 2451 d019db46e488
child 2515 109a25a5cdca
--- a/ClassDescription.st	Sat Mar 22 14:18:56 1997 +0100
+++ b/ClassDescription.st	Sat Mar 22 14:19:44 1997 +0100
@@ -186,6 +186,99 @@
     ^ ClassOrganizer for:self
 ! !
 
+!ClassDescription methodsFor:'printOut'!
+
+printHierarchyAnswerIndentOn:aStream
+    "print my class hierarchy on aStream - return indent
+     recursively calls itself to print superclass and use returned indent
+     for my description - used in the browser"
+
+    |indent nm|
+
+    indent := 0.
+    (superclass notNil) ifTrue:[
+        indent := (superclass printHierarchyAnswerIndentOn:aStream) + 2
+    ].
+    aStream spaces:indent.
+    nm := self printNameInHierarchy.
+    aStream nextPutAll:nm; nextPutAll:' ('.
+    self printInstVarNamesOn:aStream indent:(indent + nm size + 2).
+    aStream nextPutLine:')'.
+    ^ indent
+
+    "Created: 22.3.1997 / 14:11:29 / cg"
+    "Modified: 22.3.1997 / 14:15:42 / cg"
+!
+
+printHierarchyOn:aStream
+    "print my class hierarchy on aStream"
+
+    self printHierarchyAnswerIndentOn:aStream
+
+    "Created: 22.3.1997 / 14:11:13 / cg"
+!
+
+printInstVarNamesOn:aStream indent:indent
+    "print the instance variable names indented and breaking at line end"
+
+    self printNameArray:(self instVarNames) on:aStream indent:indent
+
+    "Created: 22.3.1997 / 14:12:00 / cg"
+!
+
+printNameArray:anArray on:aStream indent:indent
+    "print an array of strings separated by spaces; when the stream
+     defines a lineLength, break when this limit is reached; indent
+     every line; used to printOut instance variable names"
+
+    |thisName nextName arraySize lenMax pos mustBreak line spaces|
+
+    arraySize := anArray size.
+    arraySize ~~ 0 ifTrue:[
+        pos := indent.
+        lenMax := aStream lineLength.
+        thisName := anArray at:1.
+        line := ''.
+        1 to:arraySize do:[:index |
+            line := line , thisName.
+            pos := pos + thisName size.
+            (index == arraySize) ifFalse:[
+                nextName := anArray at:(index + 1).
+                mustBreak := false.
+                (lenMax > 0) ifTrue:[
+                    ((pos + nextName size) > lenMax) ifTrue:[
+                        mustBreak := true
+                    ]
+                ].
+                mustBreak ifTrue:[
+                    aStream nextPutLine:line withTabs.
+                    spaces isNil ifTrue:[
+                        spaces := String new:indent
+                    ].
+                    line := spaces.
+                    pos := indent
+                ] ifFalse:[
+                    line := line , ' '.
+                    pos := pos + 1
+                ].
+                thisName := nextName
+            ]
+        ].
+        aStream nextPutAll:line withTabs
+    ]
+
+    "Modified: 9.11.1996 / 00:12:06 / cg"
+    "Created: 22.3.1997 / 14:12:12 / cg"
+!
+
+printNameInHierarchy
+    "return my name as printed in the hierarchy"
+
+    ^ self name
+
+    "Created: 22.3.1997 / 14:15:36 / cg"
+! !
+
 !ClassDescription methodsFor:'printing & storing'!
 
 displayString
@@ -1011,5 +1104,5 @@
 !ClassDescription class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ClassDescription.st,v 1.41 1997-03-07 23:42:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ClassDescription.st,v 1.42 1997-03-22 13:19:44 cg Exp $'
 ! !