Class.st
changeset 523 27e13690f124
parent 488 1677ee52d630
child 524 1a5c3e68bd6a
--- a/Class.st	Fri Nov 10 21:27:54 1995 +0100
+++ b/Class.st	Fri Nov 10 21:29:13 1995 +0100
@@ -25,7 +25,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Class.st,v 1.66 1995-11-05 16:20:14 cg Exp $
+$Header: /cvs/stx/stx/libbasic/Class.st,v 1.67 1995-11-10 20:29:13 cg Exp $
 "!
 
 documentation
@@ -414,7 +414,7 @@
     "
     comment isNumber ifTrue:[
 	classFilename notNil ifTrue:[
-	    stream := Smalltalk sourceFileStreamFor:classFilename.
+	    stream := self sourceStream. "/ Smalltalk sourceFileStreamFor:classFilename.
 	    stream notNil ifTrue:[
 		stream position:comment.
 		string := String readFrom:stream onError:''.
@@ -549,6 +549,8 @@
     |sourceInfo packageString idx1 idx2 
      moduleString directoryString libraryString components|
 
+    package isNil ifTrue:[^ nil].
+
     packageString := package asString.
     idx1 := packageString lastIndexOf:$(.
     idx1 ~~ 0 ifTrue:[
@@ -775,6 +777,68 @@
     ^ code
 !
 
+sourceStream
+    "return an open stream on my sourcefile, nil if that is not available"
+
+    |source fileName aStream|
+
+    classFilename notNil ifTrue:[
+	source := classFilename
+    ] ifFalse:[
+	source := Smalltalk fileNameForClass:self
+    ].
+
+    fileName := Smalltalk getSourceFileName:source.
+    fileName isNil ifTrue:[
+	fileName := source
+    ].
+    aStream := fileName asFilename readStream.
+    aStream isNil ifTrue:[
+	"/      
+	"/ hard case - there is no source file for this class
+	"/ (neither in the source-dir-path, nor in the current directory).
+	"/      
+
+	"/      
+	"/ look if my binary is from a dynamically loaded module,
+	"/ and, if so, look in the modules directory for the
+	"/ source file.
+	"/      
+	ObjectFileLoader notNil ifTrue:[
+	    ObjectFileLoader loadedObjectHandlesDo:[:h |
+		|f|
+
+		(h classes includes:self) ifTrue:[
+		    f := h pathName.
+		    f := f asFilename directory.
+		    f := f construct:source.
+		    f exists ifTrue:[
+			aStream := f readStream.
+		    ].
+		]
+	    ].
+	].
+    ].
+
+    aStream isNil ifTrue:[
+	"/ mhmh - still no source file.
+	"/ If there is a SourceCodeManager, ask it to aquire the
+	"/ the source for my class, and return an open stream on it. 
+	SourceCodeManager notNil ifTrue:[
+	    aStream := SourceCodeManager sourceStreamFor:self.
+	]
+    ].
+
+    ^ aStream
+
+    "
+     Object sourceStream
+     Clock sourceStream
+    "
+
+    "Created: 10.11.1995 / 21:05:13 / cg"
+!
+
 addClassVarName:aString
     "add a class variable if not already there and initialize it with nil.
      Also writes a change record and notifies dependents.
@@ -1114,8 +1178,6 @@
 !
 
 writingChangePerform:aSelector with:anArgument
-    |aStream|
-
     self writingChangeDo:[:stream |
 	self perform:aSelector with:anArgument with:stream.
     ]
@@ -1750,6 +1812,7 @@
 	(nMethods ~~ 0) ifTrue:[
 	    count := 1.
 	    first := true.
+	    privacy := nil.
 
 	    "/
 	    "/ sort by selector
@@ -2619,7 +2682,7 @@
     "
     pos isNumber ifTrue:[
 	classFilename notNil ifTrue:[
-	    stream := Smalltalk sourceFileStreamFor:classFilename.
+	    stream := self sourceStream. "/ Smalltalk sourceFileStreamFor:classFilename.
 	    stream notNil ifTrue:[
 		stream position:pos+1.
 		string := stream nextChunk.