|
@@ -1969,246 +1969,96 @@ messageSends: ["addSubclassOf:named:instanceVariableNames:package:", "ifNil:", "
|
|
|
$globals.ClassBuilder);
|
|
|
|
|
|
|
|
|
-
|
|
|
-$core.addClass("ClassSorterNode", $globals.Object, ["theClass", "level", "nodes"], "Kernel-Classes");
|
|
|
-
|
|
|
-$globals.ClassSorterNode.comment="I provide an algorithm for sorting classes alphabetically.\x0a\x0aSee [Issue #143](https://lolg.it/amber/amber/issues/143).";
|
|
|
-
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
-selector: "getNodesFrom:",
|
|
|
-protocol: "accessing",
|
|
|
+selector: "sortClasses:",
|
|
|
+protocol: "as yet unclassified",
|
|
|
fn: function (aCollection){
|
|
|
var self=this,$self=this;
|
|
|
-var children,others;
|
|
|
+var root,members;
|
|
|
|
|
|
return $core.withContext(function($ctx1) {
|
|
|
|
|
|
-var $1;
|
|
|
-children=[];
|
|
|
-others=[];
|
|
|
+var $1,$2,$3,$4,$5,$7,$6,$8,$receiver;
|
|
|
+root=[nil,[]];
|
|
|
+members=$recv($globals.HashedCollection)._new();
|
|
|
$recv(aCollection)._do_((function(each){
|
|
|
|
|
|
return $core.withContext(function($ctx2) {
|
|
|
|
|
|
-$1=$recv($recv(each)._superclass()).__eq($self._theClass());
|
|
|
-if($core.assert($1)){
|
|
|
-return $recv(children)._add_(each);
|
|
|
+$1=members;
|
|
|
+$2=$recv(each)._name();
|
|
|
|
|
|
-$ctx2.sendIdx["add:"]=1;
|
|
|
+$ctx2.sendIdx["name"]=1;
|
|
|
|
|
|
-} else {
|
|
|
-return $recv(others)._add_(each);
|
|
|
-}
|
|
|
+return $recv($1)._at_put_($2,[each,[]]);
|
|
|
|
|
|
}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
|
|
|
|
|
|
}));
|
|
|
-$self.nodes=$recv(children)._collect_((function(each){
|
|
|
|
|
|
-return $core.withContext(function($ctx2) {
|
|
|
-
|
|
|
-return $recv($globals.ClassSorterNode)._on_classes_level_(each,others,$recv($self._level()).__plus((1)));
|
|
|
-
|
|
|
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,4)});
|
|
|
+$ctx1.sendIdx["do:"]=1;
|
|
|
|
|
|
-}));
|
|
|
-return self;
|
|
|
-
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"getNodesFrom:",{aCollection:aCollection,children:children,others:others})});
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: ["aCollection"],
|
|
|
-source: "getNodesFrom: aCollection\x0a\x09| children others |\x0a\x09children := #().\x0a\x09others := #().\x0a\x09aCollection do: [ :each |\x0a\x09\x09(each superclass = self theClass)\x0a\x09\x09\x09ifTrue: [ children add: each ]\x0a\x09\x09\x09ifFalse: [ others add: each ]].\x0a\x09nodes:= children collect: [ :each |\x0a\x09\x09ClassSorterNode on: each classes: others level: self level + 1 ]",
|
|
|
-referencedClasses: ["ClassSorterNode"],
|
|
|
-
|
|
|
-pragmas: [],
|
|
|
-messageSends: ["do:", "ifTrue:ifFalse:", "=", "superclass", "theClass", "add:", "collect:", "on:classes:level:", "+", "level"]
|
|
|
-}),
|
|
|
-$globals.ClassSorterNode);
|
|
|
-
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "level",
|
|
|
-protocol: "accessing",
|
|
|
-fn: function (){
|
|
|
-var self=this,$self=this;
|
|
|
-return $self.level;
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: [],
|
|
|
-source: "level\x0a\x09^ level",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-pragmas: [],
|
|
|
-messageSends: []
|
|
|
-}),
|
|
|
-$globals.ClassSorterNode);
|
|
|
-
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "level:",
|
|
|
-protocol: "accessing",
|
|
|
-fn: function (anInteger){
|
|
|
-var self=this,$self=this;
|
|
|
-$self.level=anInteger;
|
|
|
-return self;
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: ["anInteger"],
|
|
|
-source: "level: anInteger\x0a\x09level := anInteger",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-pragmas: [],
|
|
|
-messageSends: []
|
|
|
-}),
|
|
|
-$globals.ClassSorterNode);
|
|
|
-
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "nodes",
|
|
|
-protocol: "accessing",
|
|
|
-fn: function (){
|
|
|
-var self=this,$self=this;
|
|
|
-return $self.nodes;
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: [],
|
|
|
-source: "nodes\x0a\x09^ nodes",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-pragmas: [],
|
|
|
-messageSends: []
|
|
|
-}),
|
|
|
-$globals.ClassSorterNode);
|
|
|
-
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "theClass",
|
|
|
-protocol: "accessing",
|
|
|
-fn: function (){
|
|
|
-var self=this,$self=this;
|
|
|
-return $self.theClass;
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: [],
|
|
|
-source: "theClass\x0a\x09^ theClass",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-pragmas: [],
|
|
|
-messageSends: []
|
|
|
-}),
|
|
|
-$globals.ClassSorterNode);
|
|
|
-
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "theClass:",
|
|
|
-protocol: "accessing",
|
|
|
-fn: function (aClass){
|
|
|
-var self=this,$self=this;
|
|
|
-$self.theClass=aClass;
|
|
|
-return self;
|
|
|
-
|
|
|
-},
|
|
|
-
|
|
|
-args: ["aClass"],
|
|
|
-source: "theClass: aClass\x0a\x09theClass := aClass",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-pragmas: [],
|
|
|
-messageSends: []
|
|
|
-}),
|
|
|
-$globals.ClassSorterNode);
|
|
|
-
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "traverseClassesWith:",
|
|
|
-protocol: "visiting",
|
|
|
-fn: function (aCollection){
|
|
|
-var self=this,$self=this;
|
|
|
-
|
|
|
-return $core.withContext(function($ctx1) {
|
|
|
-
|
|
|
-var $1,$3,$2;
|
|
|
-$1=$self._theClass();
|
|
|
-
|
|
|
-$ctx1.sendIdx["theClass"]=1;
|
|
|
-
|
|
|
-$recv(aCollection)._add_($1);
|
|
|
-$recv($recv($self._nodes())._sorted_((function(a,b){
|
|
|
+$recv($recv($recv(aCollection)._asArray())._sorted_((function(a,b){
|
|
|
|
|
|
return $core.withContext(function($ctx2) {
|
|
|
|
|
|
-$3=$recv(a)._theClass();
|
|
|
+$3=$recv(a)._name();
|
|
|
|
|
|
-$ctx2.sendIdx["theClass"]=2;
|
|
|
+$ctx2.sendIdx["name"]=2;
|
|
|
|
|
|
-$2=$recv($3)._name();
|
|
|
+$4=$recv(b)._name();
|
|
|
|
|
|
-$ctx2.sendIdx["name"]=1;
|
|
|
+$ctx2.sendIdx["name"]=3;
|
|
|
|
|
|
-return $recv($2).__lt_eq($recv($recv(b)._theClass())._name());
|
|
|
+return $recv($3).__lt_eq($4);
|
|
|
|
|
|
-}, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1,1)});
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1,2)});
|
|
|
|
|
|
-})))._do_((function(aNode){
|
|
|
+})))._do_((function(each){
|
|
|
+var target;
|
|
|
|
|
|
return $core.withContext(function($ctx2) {
|
|
|
|
|
|
-return $recv(aNode)._traverseClassesWith_(aCollection);
|
|
|
+$5=members;
|
|
|
+$7=$recv(each)._superclass();
|
|
|
+if(($receiver = $7) == null || $receiver.a$nil){
|
|
|
+$6=$7;
|
|
|
+} else {
|
|
|
+var superklass;
|
|
|
+superklass=$receiver;
|
|
|
+$6=$recv(superklass)._name();
|
|
|
|
|
|
-}, function($ctx2) {$ctx2.fillBlock({aNode:aNode},$ctx1,2)});
|
|
|
+$ctx2.sendIdx["name"]=4;
|
|
|
|
|
|
+}
|
|
|
+target=$recv($5)._at_ifAbsent_($6,(function(){
|
|
|
+return root;
|
|
|
+
|
|
|
}));
|
|
|
-return self;
|
|
|
+$8=$recv(target)._second();
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"traverseClassesWith:",{aCollection:aCollection})});
|
|
|
+$ctx2.sendIdx["second"]=1;
|
|
|
|
|
|
-},
|
|
|
-
|
|
|
-args: ["aCollection"],
|
|
|
-source: "traverseClassesWith: aCollection\x0a\x09\x22sort classes alphabetically Issue #143\x22\x0a\x0a\x09aCollection add: self theClass.\x0a\x09(self nodes sorted: [ :a :b | a theClass name <= b theClass name ]) do: [ :aNode |\x0a\x09\x09aNode traverseClassesWith: aCollection ].",
|
|
|
-referencedClasses: [],
|
|
|
-
|
|
|
-pragmas: [],
|
|
|
-messageSends: ["add:", "theClass", "do:", "sorted:", "nodes", "<=", "name", "traverseClassesWith:"]
|
|
|
-}),
|
|
|
-$globals.ClassSorterNode);
|
|
|
-
|
|
|
-
|
|
|
-$core.addMethod(
|
|
|
-$core.method({
|
|
|
-selector: "on:classes:level:",
|
|
|
-protocol: "instance creation",
|
|
|
-fn: function (aClass,aCollection,anInteger){
|
|
|
-var self=this,$self=this;
|
|
|
+return $recv($8)._add_($recv(members)._at_($recv(each)._name()));
|
|
|
|
|
|
-return $core.withContext(function($ctx1) {
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({each:each,target:target},$ctx1,3)});
|
|
|
|
|
|
-var $1;
|
|
|
-$1=$self._new();
|
|
|
-$recv($1)._theClass_(aClass);
|
|
|
-$recv($1)._level_(anInteger);
|
|
|
-$recv($1)._getNodesFrom_(aCollection);
|
|
|
-return $recv($1)._yourself();
|
|
|
+}));
|
|
|
+return $recv(root)._second();
|
|
|
|
|
|
-}, function($ctx1) {$ctx1.fill(self,"on:classes:level:",{aClass:aClass,aCollection:aCollection,anInteger:anInteger})});
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"sortClasses:",{aCollection:aCollection,root:root,members:members})});
|
|
|
|
|
|
},
|
|
|
|
|
|
-args: ["aClass", "aCollection", "anInteger"],
|
|
|
-source: "on: aClass classes: aCollection level: anInteger\x0a\x09^ self new\x0a\x09\x09theClass: aClass;\x0a\x09\x09level: anInteger;\x0a\x09\x09getNodesFrom: aCollection;\x0a\x09\x09yourself",
|
|
|
-referencedClasses: [],
|
|
|
+args: ["aCollection"],
|
|
|
+source: "sortClasses: aCollection\x0a\x09| root members |\x0a\x09root := {nil. {}}.\x0a\x09members := HashedCollection new.\x0a\x09aCollection do: [ :each | members at: each name put: {each. {}} ].\x0a\x09(aCollection asArray sorted: [ :a :b | a name <= b name ]) do: [ :each |\x0a\x09\x09| target |\x0a\x09\x09target := members\x0a\x09\x09\x09at: (each superclass ifNotNil: [ :superklass | superklass name ])\x0a\x09\x09\x09ifAbsent: [ root ].\x0a\x09\x09target second add: (members at: each name) ].\x0a\x09^ root second",
|
|
|
+referencedClasses: ["HashedCollection"],
|
|
|
|
|
|
pragmas: [],
|
|
|
-messageSends: ["theClass:", "new", "level:", "getNodesFrom:", "yourself"]
|
|
|
+messageSends: ["new", "do:", "at:put:", "name", "sorted:", "asArray", "<=", "at:ifAbsent:", "ifNotNil:", "superclass", "add:", "second", "at:"]
|
|
|
}),
|
|
|
-$globals.ClassSorterNode.a$cls);
|
|
|
+$globals.ClassBuilder.a$cls);
|
|
|
|
|
|
|
|
|
$core.addTrait("TBehaviorDefaults", "Kernel-Classes");
|