Fixed swizzling when SmallSense is loaded using Smalltalk loadPackage:.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 02 Sep 2013 12:36:51 +0100
changeset 74 ff14a7c424cf
parent 73 c4d090b63d05
child 75 2046f40e5dde
Fixed swizzling when SmallSense is loaded using Smalltalk loadPackage:.
jv_smallsense.st
--- a/jv_smallsense.st	Mon Sep 02 12:25:26 2013 +0100
+++ b/jv_smallsense.st	Mon Sep 02 12:36:51 2013 +0100
@@ -2,7 +2,7 @@
 
 LibraryDefinition subclass:#jv_smallsense
 	instanceVariableNames:''
-	classVariableNames:''
+	classVariableNames:'Swizzled'
 	poolDictionaries:''
 	category:'* Projects & Packages *'
 !
@@ -16,9 +16,13 @@
      is not called when classlibrary is built-in (i.e., not loaded
      by Smalltalk loadPackage: ...). This is indeed a bug. "
 
-    self swizzle
+    Swizzled := false.
+    self hasAllClassesFullyLoaded ifTrue:[
+        self swizzle
+    ].
 
     "Created: / 19-08-2013 / 15:24:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-09-2013 / 12:29:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !jv_smallsense class methodsFor:'description'!
@@ -106,6 +110,17 @@
     )
 ! !
 
+!jv_smallsense class methodsFor:'description - actions'!
+
+postLoadAction
+    "/ Swizzle methods. Note, that if they are already swizzled,
+    "/ self swizzle is noop.
+
+    self swizzle.
+
+    "Created: / 02-09-2013 / 12:30:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !jv_smallsense class methodsFor:'description - contents'!
 
 classNamesAndAttributes
@@ -255,13 +270,17 @@
 swizzle
     "Swizzle all methods annotated as <swizzle:>"
 
+    Swizzled ifTrue:[ ^ self ].
     self extensionMethods do:[:m|self swizzle: m].
+    Swizzled := true.
+
 
     "
     jv_smallsense swizzle
     "
 
     "Created: / 19-08-2013 / 14:54:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-09-2013 / 12:30:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 swizzle: method