1
0
فهرست منبع

Fix package rename bugs.

Herbert Vojčík 7 سال پیش
والد
کامیت
74d7197b66
5فایلهای تغییر یافته به همراه35 افزوده شده و 24 حذف شده
  1. 2 1
      API-CHANGES.txt
  2. 26 6
      src/Kernel-Infrastructure.js
  3. 5 1
      src/Kernel-Infrastructure.st
  4. 2 13
      src/Platform-Services.js
  5. 0 3
      src/Platform-Services.st

+ 2 - 1
API-CHANGES.txt

@@ -3,7 +3,7 @@
 * Deprecate amber/boot api nextId, prop globalJsVariables.
 * Remove amber/boot prop reservedWords (with the hope no one uses it directly).
 * Deprecate ProtoObject >> identityHash.
-* Deprecate SmalltalkImage >> packageAt: in favour of explicit #packageAt:ifAbsent:.
+* Deprecate SmalltalkImage >> packageAt: in favour of explicit #packageAt:if{Absent,Present}:.
 
 + AmberBootstrapInitialization class >>
   + run
@@ -35,6 +35,7 @@
   + named:javaScriptDescriptor:
 + SmalltalkImage >>
   + packageDictionary
+  + packageAt:ifPresent:
 + TBehaviorProvider >>
   + methodOrganizationEnter:andLeave:
 + TMasterBehavior >>

+ 26 - 6
src/Kernel-Infrastructure.js

@@ -3475,6 +3475,29 @@ messageSends: ["at:ifAbsent:", "packageDictionary"]
 }),
 $globals.SmalltalkImage);
 
+$core.addMethod(
+$core.method({
+selector: "packageAt:ifPresent:",
+protocol: "packages",
+fn: function (packageName,aBlock){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($self._packageDictionary())._at_ifPresent_(packageName,aBlock);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"packageAt:ifPresent:",{packageName:packageName,aBlock:aBlock},$globals.SmalltalkImage)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["packageName", "aBlock"],
+source: "packageAt: packageName ifPresent: aBlock\x0a\x09^ self packageDictionary at: packageName ifPresent: aBlock",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["at:ifPresent:", "packageDictionary"]
+}),
+$globals.SmalltalkImage);
+
 $core.addMethod(
 $core.method({
 selector: "packageDictionary",
@@ -3822,10 +3845,7 @@ $ctx2.sendIdx["error:"]=1;
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");
 }));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["packageAt:ifAbsent:"]=1;
-//>>excludeEnd("ctx");
-$self._packageAt_ifAbsent_(newName,(function(){
+$self._packageAt_ifPresent_(newName,(function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
@@ -3847,10 +3867,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["packageName", "newName"],
-source: "renamePackage: packageName to: newName\x0a\x09\x22Rename a package.\x22\x0a\x0a\x09| pkg |\x0a\x09pkg := self packageAt: packageName ifAbsent: [ self error: 'Missing package: ', packageName ].\x0a\x09self packageAt: newName ifAbsent: [ self error: 'Already exists a package called: ', newName ].\x0a\x09pkg name: newName; beDirty.\x0a\x09self packageDictionary\x0a\x09\x09at: newName put: pkg;\x0a\x09\x09removeKey: packageName",
+source: "renamePackage: packageName to: newName\x0a\x09\x22Rename a package.\x22\x0a\x0a\x09| pkg |\x0a\x09pkg := self packageAt: packageName ifAbsent: [ self error: 'Missing package: ', packageName ].\x0a\x09self packageAt: newName ifPresent: [ self error: 'Already exists a package called: ', newName ].\x0a\x09pkg name: newName; beDirty.\x0a\x09self packageDictionary\x0a\x09\x09at: newName put: pkg;\x0a\x09\x09removeKey: packageName",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["packageAt:ifAbsent:", "error:", ",", "name:", "beDirty", "at:put:", "packageDictionary", "removeKey:"]
+messageSends: ["packageAt:ifAbsent:", "error:", ",", "packageAt:ifPresent:", "name:", "beDirty", "at:put:", "packageDictionary", "removeKey:"]
 }),
 $globals.SmalltalkImage);
 

+ 5 - 1
src/Kernel-Infrastructure.st

@@ -980,6 +980,10 @@ packageAt: packageName ifAbsent: aBlock
 	^ self packageDictionary at: packageName ifAbsent: aBlock
 !
 
+packageAt: packageName ifPresent: aBlock
+	^ self packageDictionary at: packageName ifPresent: aBlock
+!
+
 packageDictionary
 	^ packageDictionary ifNil: [ packageDictionary := Dictionary new ]
 !
@@ -1005,7 +1009,7 @@ renamePackage: packageName to: newName
 
 	| pkg |
 	pkg := self packageAt: packageName ifAbsent: [ self error: 'Missing package: ', packageName ].
-	self packageAt: newName ifAbsent: [ self error: 'Already exists a package called: ', newName ].
+	self packageAt: newName ifPresent: [ self error: 'Already exists a package called: ', newName ].
 	pkg name: newName; beDirty.
 	self packageDictionary
 		at: newName put: pkg;

+ 2 - 13
src/Platform-Services.js

@@ -1162,17 +1162,6 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$receiver;
-$1=$recv($recv($globals.Smalltalk)._globals())._at_(aNewPackageName);
-if(($receiver = $1) == null || $receiver.a$nil){
-$1;
-} else {
-$2=$recv("A package named ".__comma(aNewPackageName)).__comma(" already exists");
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx[","]=1;
-//>>excludeEnd("ctx");
-$self._error_($2);
-}
 $recv($globals.Smalltalk)._renamePackage_to_(aPackageName,aNewPackageName);
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -1181,10 +1170,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aPackageName", "aNewPackageName"],
-source: "renamePackage: aPackageName to: aNewPackageName\x0a        (Smalltalk globals at: aNewPackageName)\x0a                ifNotNil: [ self error: 'A package named ', aNewPackageName, ' already exists' ].\x0a\x0a        Smalltalk renamePackage: aPackageName to: aNewPackageName",
+source: "renamePackage: aPackageName to: aNewPackageName\x0a        Smalltalk renamePackage: aPackageName to: aNewPackageName",
 referencedClasses: ["Smalltalk"],
 //>>excludeEnd("ide");
-messageSends: ["ifNotNil:", "at:", "globals", "error:", ",", "renamePackage:to:"]
+messageSends: ["renamePackage:to:"]
 }),
 $globals.Environment);
 

+ 0 - 3
src/Platform-Services.st

@@ -208,9 +208,6 @@ renameClass: aClass to: aClassName
 !
 
 renamePackage: aPackageName to: aNewPackageName
-        (Smalltalk globals at: aNewPackageName)
-                ifNotNil: [ self error: 'A package named ', aNewPackageName, ' already exists' ].
-
         Smalltalk renamePackage: aPackageName to: aNewPackageName
 !