Pārlūkot izejas kodu

MethodModified announcement

Nicolas Petton 11 gadi atpakaļ
vecāks
revīzija
d9e62a414e

+ 28 - 1
js/Kernel-Announcements.deploy.js

@@ -1,4 +1,4 @@
-smalltalk.addPackage('Kernel-Announcements', {});
+smalltalk.addPackage('Kernel-Announcements');
 smalltalk.addClass('AnnouncementSubscription', smalltalk.Object, ['block', 'announcementClass'], 'Kernel-Announcements');
 smalltalk.addMethod(
 "_announcementClass",
@@ -228,6 +228,33 @@ smalltalk.MethodAnnouncement);
 smalltalk.addClass('MethodAdded', smalltalk.MethodAnnouncement, [], 'Kernel-Announcements');
 
 
+smalltalk.addClass('MethodModified', smalltalk.MethodAnnouncement, ['oldMethod'], 'Kernel-Announcements');
+smalltalk.addMethod(
+"_oldMethod",
+smalltalk.method({
+selector: "oldMethod",
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var $1;
+$1=self["@oldMethod"];
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"oldMethod",{}, smalltalk.MethodModified)})},
+messageSends: []}),
+smalltalk.MethodModified);
+
+smalltalk.addMethod(
+"_oldMethod_",
+smalltalk.method({
+selector: "oldMethod:",
+fn: function (aMethod){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
self["@oldMethod"]=aMethod;
+return self}, function($ctx1) {$ctx1.fill(self,"oldMethod:",{aMethod:aMethod}, smalltalk.MethodModified)})},
+messageSends: []}),
+smalltalk.MethodModified);
+
+
+
 smalltalk.addClass('MethodRemoved', smalltalk.MethodAnnouncement, [], 'Kernel-Announcements');
 
 

+ 38 - 1
js/Kernel-Announcements.js

@@ -1,4 +1,4 @@
-smalltalk.addPackage('Kernel-Announcements', {});
+smalltalk.addPackage('Kernel-Announcements');
 smalltalk.addClass('AnnouncementSubscription', smalltalk.Object, ['block', 'announcementClass'], 'Kernel-Announcements');
 smalltalk.AnnouncementSubscription.comment="The subscription is a single entry in a subscription registry of an `Announcer`.\x0aSeveral subscriptions by the same object is possible."
 smalltalk.addMethod(
@@ -312,6 +312,43 @@ smalltalk.MethodAnnouncement);
 smalltalk.addClass('MethodAdded', smalltalk.MethodAnnouncement, [], 'Kernel-Announcements');
 
 
+smalltalk.addClass('MethodModified', smalltalk.MethodAnnouncement, ['oldMethod'], 'Kernel-Announcements');
+smalltalk.addMethod(
+"_oldMethod",
+smalltalk.method({
+selector: "oldMethod",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
var $1;
+$1=self["@oldMethod"];
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"oldMethod",{}, smalltalk.MethodModified)})},
+args: [],
+source: "oldMethod\x0a\x09^ oldMethod",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.MethodModified);
+
+smalltalk.addMethod(
+"_oldMethod_",
+smalltalk.method({
+selector: "oldMethod:",
+category: 'accessing',
+fn: function (aMethod){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
self["@oldMethod"]=aMethod;
+return self}, function($ctx1) {$ctx1.fill(self,"oldMethod:",{aMethod:aMethod}, smalltalk.MethodModified)})},
+args: ["aMethod"],
+source: "oldMethod: aMethod\x0a\x09oldMethod := aMethod",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.MethodModified);
+
+
+
 smalltalk.addClass('MethodRemoved', smalltalk.MethodAnnouncement, [], 'Kernel-Announcements');
 
 

+ 24 - 9
js/Kernel-Classes.deploy.js

@@ -1,4 +1,4 @@
-smalltalk.addPackage('Kernel-Classes', {});
+smalltalk.addPackage('Kernel-Classes');
 smalltalk.addClass('Behavior', smalltalk.Object, [], 'Kernel-Classes');
 smalltalk.addMethod(
 "_addCompiledMethod_",
@@ -6,15 +6,30 @@ smalltalk.method({
 selector: "addCompiledMethod:",
 fn: function (aMethod){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
var $1,$2;
+var oldMethod,announcement;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3,$4,$5;
+oldMethod=_st(_st(self)._methodDictionary())._at_ifAbsent_(_st(aMethod)._selector(),(function(){
+return smalltalk.withContext(function($ctx2) {
return nil;
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
 _st(self)._basicAddCompiledMethod_(aMethod);
-$1=_st((smalltalk.MethodAdded || MethodAdded))._new();
-_st($1)._theClass_(self);
-_st($1)._method_(aMethod);
-$2=_st($1)._yourself();
-_st(_st((smalltalk.SystemAnnouncer || SystemAnnouncer))._current())._announce_($2);
-return self}, function($ctx1) {$ctx1.fill(self,"addCompiledMethod:",{aMethod:aMethod}, smalltalk.Behavior)})},
-messageSends: ["basicAddCompiledMethod:", "announce:", "theClass:", "new", "method:", "yourself", "current"]}),
+$1=oldMethod;
+if(($receiver = $1) == nil || $receiver == undefined){
+$2=_st((smalltalk.MethodAdded || MethodAdded))._new();
+_st($2)._theClass_(self);
+_st($2)._method_(aMethod);
+$3=_st($2)._yourself();
+announcement=$3;
+} else {
+$4=_st((smalltalk.MethodModified || MethodModified))._new();
+_st($4)._theClass_(self);
+_st($4)._oldMethod_(oldMethod);
+_st($4)._method_(aMethod);
+$5=_st($4)._yourself();
+announcement=$5;
+};
+_st(_st((smalltalk.SystemAnnouncer || SystemAnnouncer))._current())._announce_(announcement);
+return self}, function($ctx1) {$ctx1.fill(self,"addCompiledMethod:",{aMethod:aMethod,oldMethod:oldMethod,announcement:announcement}, smalltalk.Behavior)})},
+messageSends: ["at:ifAbsent:", "selector", "methodDictionary", "basicAddCompiledMethod:", "ifNil:ifNotNil:", "theClass:", "new", "method:", "yourself", "oldMethod:", "announce:", "current"]}),
 smalltalk.Behavior);
 
 smalltalk.addMethod(

+ 26 - 11
js/Kernel-Classes.js

@@ -1,4 +1,4 @@
-smalltalk.addPackage('Kernel-Classes', {});
+smalltalk.addPackage('Kernel-Classes');
 smalltalk.addClass('Behavior', smalltalk.Object, [], 'Kernel-Classes');
 smalltalk.Behavior.comment="Behavior is the superclass of all class objects. \x0a\x0aIt defines the protocol for creating instances of a class with `#basicNew` and `#new` (see `boot.js` for class constructors details).\x0aInstances know about the subclass/superclass relationships between classes, contain the description that instances are created from, \x0aand hold the method dictionary that's associated with each class.\x0a\x0aBehavior also  provides methods for compiling methods, examining the method dictionary, and iterating over the class hierarchy."
 smalltalk.addMethod(
@@ -8,18 +8,33 @@ selector: "addCompiledMethod:",
 category: 'compiling',
 fn: function (aMethod){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
var $1,$2;
+var oldMethod,announcement;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3,$4,$5;
+oldMethod=_st(_st(self)._methodDictionary())._at_ifAbsent_(_st(aMethod)._selector(),(function(){
+return smalltalk.withContext(function($ctx2) {
return nil;
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
 _st(self)._basicAddCompiledMethod_(aMethod);
-$1=_st((smalltalk.MethodAdded || MethodAdded))._new();
-_st($1)._theClass_(self);
-_st($1)._method_(aMethod);
-$2=_st($1)._yourself();
-_st(_st((smalltalk.SystemAnnouncer || SystemAnnouncer))._current())._announce_($2);
-return self}, function($ctx1) {$ctx1.fill(self,"addCompiledMethod:",{aMethod:aMethod}, smalltalk.Behavior)})},
+$1=oldMethod;
+if(($receiver = $1) == nil || $receiver == undefined){
+$2=_st((smalltalk.MethodAdded || MethodAdded))._new();
+_st($2)._theClass_(self);
+_st($2)._method_(aMethod);
+$3=_st($2)._yourself();
+announcement=$3;
+} else {
+$4=_st((smalltalk.MethodModified || MethodModified))._new();
+_st($4)._theClass_(self);
+_st($4)._oldMethod_(oldMethod);
+_st($4)._method_(aMethod);
+$5=_st($4)._yourself();
+announcement=$5;
+};
+_st(_st((smalltalk.SystemAnnouncer || SystemAnnouncer))._current())._announce_(announcement);
+return self}, function($ctx1) {$ctx1.fill(self,"addCompiledMethod:",{aMethod:aMethod,oldMethod:oldMethod,announcement:announcement}, smalltalk.Behavior)})},
 args: ["aMethod"],
-source: "addCompiledMethod: aMethod\x0a\x09self basicAddCompiledMethod: aMethod.\x0a    \x0a    SystemAnnouncer current\x0a   \x09\x09announce: (MethodAdded new\x0a        \x09theClass: self;\x0a            method: aMethod;\x0a            yourself)",
-messageSends: ["basicAddCompiledMethod:", "announce:", "theClass:", "new", "method:", "yourself", "current"],
-referencedClasses: ["MethodAdded", "SystemAnnouncer"]
+source: "addCompiledMethod: aMethod\x0a\x09| oldMethod announcement |\x0a    \x0a\x09oldMethod := self methodDictionary \x0a    \x09at: aMethod selector \x0a        ifAbsent: [ nil ].\x0a    \x0a\x09self basicAddCompiledMethod: aMethod.\x0a    \x0a    announcement := oldMethod \x0a    \x09ifNil: [\x0a\x09\x09    MethodAdded new\x0a       \x09\x09\x09 \x09theClass: self;\x0a\x09\x09            method: aMethod;\x0a       \x09\x09\x09    yourself ]\x0a    \x09ifNotNil: [\x0a          \x09MethodModified new\x0a       \x09\x09\x09 \x09theClass: self;\x0a                    oldMethod: oldMethod; \x0a\x09\x09            method: aMethod;\x0a       \x09\x09\x09    yourself ].\x0a                    \x0a\x09SystemAnnouncer current\x0a\x09\x09   \x09\x09announce: announcement",
+messageSends: ["at:ifAbsent:", "selector", "methodDictionary", "basicAddCompiledMethod:", "ifNil:ifNotNil:", "theClass:", "new", "method:", "yourself", "oldMethod:", "announce:", "current"],
+referencedClasses: ["MethodAdded", "MethodModified", "SystemAnnouncer"]
 }),
 smalltalk.Behavior);
 

+ 14 - 0
st/Kernel-Announcements.st

@@ -155,6 +155,20 @@ MethodAnnouncement subclass: #MethodAdded
 	instanceVariableNames: ''
 	package: 'Kernel-Announcements'!
 
+MethodAnnouncement subclass: #MethodModified
+	instanceVariableNames: 'oldMethod'
+	package: 'Kernel-Announcements'!
+
+!MethodModified methodsFor: 'accessing'!
+
+oldMethod
+	^ oldMethod
+!
+
+oldMethod: aMethod
+	oldMethod := aMethod
+! !
+
 MethodAnnouncement subclass: #MethodRemoved
 	instanceVariableNames: ''
 	package: 'Kernel-Announcements'!

+ 21 - 5
st/Kernel-Classes.st

@@ -174,13 +174,29 @@ withAllSubclasses
 !Behavior methodsFor: 'compiling'!
 
 addCompiledMethod: aMethod
+	| oldMethod announcement |
+    
+	oldMethod := self methodDictionary 
+    	at: aMethod selector 
+        ifAbsent: [ nil ].
+    
 	self basicAddCompiledMethod: aMethod.
     
-    SystemAnnouncer current
-   		announce: (MethodAdded new
-        	theClass: self;
-            method: aMethod;
-            yourself)
+    announcement := oldMethod 
+    	ifNil: [
+		    MethodAdded new
+       			 	theClass: self;
+		            method: aMethod;
+       			    yourself ]
+    	ifNotNil: [
+          	MethodModified new
+       			 	theClass: self;
+                    oldMethod: oldMethod; 
+		            method: aMethod;
+       			    yourself ].
+                    
+	SystemAnnouncer current
+		   		announce: announcement
 !
 
 compile: aString