瀏覽代碼

Rename #newFrom to #from

Kenneth Pullen 11 年之前
父節點
當前提交
a7e8f708e1
共有 6 個文件被更改,包括 77 次插入77 次删除
  1. 15 15
      js/Kernel-Collections.deploy.js
  2. 17 17
      js/Kernel-Collections.js
  3. 13 13
      js/Kernel-Tests.deploy.js
  4. 18 18
      js/Kernel-Tests.js
  5. 7 7
      st/Kernel-Collections.st
  6. 7 7
      st/Kernel-Tests.st

+ 15 - 15
js/Kernel-Collections.deploy.js

@@ -1313,41 +1313,41 @@ smalltalk.HashedCollection);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "fromPairs:",
+selector: "from:",
 fn: function (aCollection){
 var self=this;
-var dict;
+var newCollection;
 return smalltalk.withContext(function($ctx1) { 
 var $1;
-_st(self)._deprecatedAPI();
-dict=_st(self)._new();
+newCollection=_st(self)._new();
 _st(aCollection)._do_((function(each){
 return smalltalk.withContext(function($ctx2) {
-return _st(dict)._add_(each);
+return _st(newCollection)._add_(each);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
-$1=dict;
+$1=newCollection;
 return $1;
-}, function($ctx1) {$ctx1.fill(self,"fromPairs:",{aCollection:aCollection,dict:dict},smalltalk.HashedCollection.klass)})},
-messageSends: ["deprecatedAPI", "new", "do:", "add:"]}),
+}, function($ctx1) {$ctx1.fill(self,"from:",{aCollection:aCollection,newCollection:newCollection},smalltalk.HashedCollection.klass)})},
+messageSends: ["new", "do:", "add:"]}),
 smalltalk.HashedCollection.klass);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "newFrom:",
+selector: "fromPairs:",
 fn: function (aCollection){
 var self=this;
-var newCollection;
+var dict;
 return smalltalk.withContext(function($ctx1) { 
 var $1;
-newCollection=_st(self)._new();
+_st(self)._deprecatedAPI();
+dict=_st(self)._new();
 _st(aCollection)._do_((function(each){
 return smalltalk.withContext(function($ctx2) {
-return _st(newCollection)._add_(each);
+return _st(dict)._add_(each);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
-$1=newCollection;
+$1=dict;
 return $1;
-}, function($ctx1) {$ctx1.fill(self,"newFrom:",{aCollection:aCollection,newCollection:newCollection},smalltalk.HashedCollection.klass)})},
-messageSends: ["new", "do:", "add:"]}),
+}, function($ctx1) {$ctx1.fill(self,"fromPairs:",{aCollection:aCollection,dict:dict},smalltalk.HashedCollection.klass)})},
+messageSends: ["deprecatedAPI", "new", "do:", "add:"]}),
 smalltalk.HashedCollection.klass);
 
 smalltalk.addMethod(

+ 17 - 17
js/Kernel-Collections.js

@@ -1742,49 +1742,49 @@ smalltalk.HashedCollection);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "fromPairs:",
+selector: "from:",
 category: 'instance creation',
 fn: function (aCollection){
 var self=this;
-var dict;
+var newCollection;
 return smalltalk.withContext(function($ctx1) { 
 var $1;
-_st(self)._deprecatedAPI();
-dict=_st(self)._new();
+newCollection=_st(self)._new();
 _st(aCollection)._do_((function(each){
 return smalltalk.withContext(function($ctx2) {
-return _st(dict)._add_(each);
+return _st(newCollection)._add_(each);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
-$1=dict;
+$1=newCollection;
 return $1;
-}, function($ctx1) {$ctx1.fill(self,"fromPairs:",{aCollection:aCollection,dict:dict},smalltalk.HashedCollection.klass)})},
+}, function($ctx1) {$ctx1.fill(self,"from:",{aCollection:aCollection,newCollection:newCollection},smalltalk.HashedCollection.klass)})},
 args: ["aCollection"],
-source: "fromPairs: aCollection\x0a\x09\x22This message is poorly named and has been replaced by #newFrom:\x22\x0a\x09| dict |\x0a\x09self deprecatedAPI.\x0a\x09dict := self new.\x0a\x09aCollection do: [:each | dict add: each].\x0a\x09^dict",
-messageSends: ["deprecatedAPI", "new", "do:", "add:"],
+source: "from: aCollection\x0a| newCollection |\x0anewCollection := self new.\x0aaCollection do: [:each | newCollection add: each].\x0a^ newCollection.",
+messageSends: ["new", "do:", "add:"],
 referencedClasses: []
 }),
 smalltalk.HashedCollection.klass);
 
 smalltalk.addMethod(
 smalltalk.method({
-selector: "newFrom:",
+selector: "fromPairs:",
 category: 'instance creation',
 fn: function (aCollection){
 var self=this;
-var newCollection;
+var dict;
 return smalltalk.withContext(function($ctx1) { 
 var $1;
-newCollection=_st(self)._new();
+_st(self)._deprecatedAPI();
+dict=_st(self)._new();
 _st(aCollection)._do_((function(each){
 return smalltalk.withContext(function($ctx2) {
-return _st(newCollection)._add_(each);
+return _st(dict)._add_(each);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
-$1=newCollection;
+$1=dict;
 return $1;
-}, function($ctx1) {$ctx1.fill(self,"newFrom:",{aCollection:aCollection,newCollection:newCollection},smalltalk.HashedCollection.klass)})},
+}, function($ctx1) {$ctx1.fill(self,"fromPairs:",{aCollection:aCollection,dict:dict},smalltalk.HashedCollection.klass)})},
 args: ["aCollection"],
-source: "newFrom: aCollection\x0a| newCollection |\x0anewCollection := self new.\x0aaCollection do: [:each | newCollection add: each].\x0a^ newCollection.",
-messageSends: ["new", "do:", "add:"],
+source: "fromPairs: aCollection\x0a\x09\x22This message is poorly named and has been replaced by #newFrom:\x22\x0a\x09| dict |\x0a\x09self deprecatedAPI.\x0a\x09dict := self new.\x0a\x09aCollection do: [:each | dict add: each].\x0a\x09^dict",
+messageSends: ["deprecatedAPI", "new", "do:", "add:"],
 referencedClasses: []
 }),
 smalltalk.HashedCollection.klass);

+ 13 - 13
js/Kernel-Tests.deploy.js

@@ -1117,6 +1117,19 @@ return self}, function($ctx1) {$ctx1.fill(self,"testContains",{collection:collec
 messageSends: ["collection", "assert:", "contains:", "=", "first", "values", "deny:", "new"]}),
 smalltalk.HashedCollectionTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testFrom",
+fn: function (){
+var self=this;
+var associations;
+return smalltalk.withContext(function($ctx1) { 
+associations=[_st("a").__minus_gt((1)),_st("b").__minus_gt((2))];
+_st(self)._assertSameContents_as_(_st(_st(_st(self)._class())._collectionClass())._from_(associations),smalltalk.HashedCollection._fromPairs_([_st("a").__minus_gt((1)),_st("b").__minus_gt((2))]));
+return self}, function($ctx1) {$ctx1.fill(self,"testFrom",{associations:associations},smalltalk.HashedCollectionTest)})},
+messageSends: ["->", "assertSameContents:as:", "from:", "collectionClass", "class"]}),
+smalltalk.HashedCollectionTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testIndexOf",
@@ -1137,19 +1150,6 @@ return self}, function($ctx1) {$ctx1.fill(self,"testIndexOf",{},smalltalk.Hashed
 messageSends: ["assert:equals:", "indexOf:", "collection", "should:raise:", "indexOf:ifAbsent:"]}),
 smalltalk.HashedCollectionTest);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "testNewFrom",
-fn: function (){
-var self=this;
-var associations;
-return smalltalk.withContext(function($ctx1) { 
-associations=[_st("a").__minus_gt((1)),_st("b").__minus_gt((2))];
-_st(self)._assertSameContents_as_(_st(_st(_st(self)._class())._collectionClass())._newFrom_(associations),smalltalk.HashedCollection._fromPairs_([_st("a").__minus_gt((1)),_st("b").__minus_gt((2))]));
-return self}, function($ctx1) {$ctx1.fill(self,"testNewFrom",{associations:associations},smalltalk.HashedCollectionTest)})},
-messageSends: ["->", "assertSameContents:as:", "newFrom:", "collectionClass", "class"]}),
-smalltalk.HashedCollectionTest);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testNewFromPairs",

+ 18 - 18
js/Kernel-Tests.js

@@ -1387,6 +1387,24 @@ referencedClasses: ["Object"]
 }),
 smalltalk.HashedCollectionTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testFrom",
+category: 'tests',
+fn: function (){
+var self=this;
+var associations;
+return smalltalk.withContext(function($ctx1) { 
+associations=[_st("a").__minus_gt((1)),_st("b").__minus_gt((2))];
+_st(self)._assertSameContents_as_(_st(_st(_st(self)._class())._collectionClass())._from_(associations),smalltalk.HashedCollection._fromPairs_([_st("a").__minus_gt((1)),_st("b").__minus_gt((2))]));
+return self}, function($ctx1) {$ctx1.fill(self,"testFrom",{associations:associations},smalltalk.HashedCollectionTest)})},
+args: [],
+source: "testFrom\x0a\x22Accept a collection of associations.\x22\x0a| associations |\x0aassociations := { 'a' -> 1. 'b' -> 2 }.\x0aself assertSameContents: ( self class collectionClass from: associations ) as: #{ 'a' -> 1. 'b' -> 2 }.",
+messageSends: ["->", "assertSameContents:as:", "from:", "collectionClass", "class"],
+referencedClasses: []
+}),
+smalltalk.HashedCollectionTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testIndexOf",
@@ -1412,24 +1430,6 @@ referencedClasses: ["Error"]
 }),
 smalltalk.HashedCollectionTest);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "testNewFrom",
-category: 'tests',
-fn: function (){
-var self=this;
-var associations;
-return smalltalk.withContext(function($ctx1) { 
-associations=[_st("a").__minus_gt((1)),_st("b").__minus_gt((2))];
-_st(self)._assertSameContents_as_(_st(_st(_st(self)._class())._collectionClass())._newFrom_(associations),smalltalk.HashedCollection._fromPairs_([_st("a").__minus_gt((1)),_st("b").__minus_gt((2))]));
-return self}, function($ctx1) {$ctx1.fill(self,"testNewFrom",{associations:associations},smalltalk.HashedCollectionTest)})},
-args: [],
-source: "testNewFrom\x0a\x22Accept a collection of associations.\x22\x0a| associations |\x0aassociations := { 'a' -> 1. 'b' -> 2 }.\x0aself assertSameContents: ( self class collectionClass newFrom: associations ) as: #{ 'a' -> 1. 'b' -> 2 }.",
-messageSends: ["->", "assertSameContents:as:", "newFrom:", "collectionClass", "class"],
-referencedClasses: []
-}),
-smalltalk.HashedCollectionTest);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testNewFromPairs",

+ 7 - 7
st/Kernel-Collections.st

@@ -578,6 +578,13 @@ includesKey: aKey
 
 !HashedCollection class methodsFor: 'instance creation'!
 
+from: aCollection
+| newCollection |
+newCollection := self new.
+aCollection do: [:each | newCollection add: each].
+^ newCollection.
+!
+
 fromPairs: aCollection
 	"This message is poorly named and has been replaced by #newFrom:"
 	| dict |
@@ -587,13 +594,6 @@ fromPairs: aCollection
 	^dict
 !
 
-newFrom: aCollection
-| newCollection |
-newCollection := self new.
-aCollection do: [:each | newCollection add: each].
-^ newCollection.
-!
-
 newFromPairs: aCollection
 "Accept an array of elements where every two elements form an association - the odd element being the key, and the even element the value."
 | newCollection |

+ 7 - 7
st/Kernel-Tests.st

@@ -503,19 +503,19 @@ testContains
 	self deny: (self collection contains: [ :each | each = Object new ])
 !
 
+testFrom
+"Accept a collection of associations."
+| associations |
+associations := { 'a' -> 1. 'b' -> 2 }.
+self assertSameContents: ( self class collectionClass from: associations ) as: #{ 'a' -> 1. 'b' -> 2 }.
+!
+
 testIndexOf
 	self assert: (self collection indexOf: 2) equals: 'a'.
 	self should: [ self collection indexOf: 999 ] raise: Error.
 	self assert: (self collection indexOf: 999 ifAbsent: [ 'sentinel' ]) equals: 'sentinel'
 !
 
-testNewFrom
-"Accept a collection of associations."
-| associations |
-associations := { 'a' -> 1. 'b' -> 2 }.
-self assertSameContents: ( self class collectionClass newFrom: associations ) as: #{ 'a' -> 1. 'b' -> 2 }.
-!
-
 testNewFromPairs
 "Accept an array in which all odd indexes are keys and evens are values."
 | flattenedAssociations |