Explorar el Código

Inspector operates on list of associations.

Dictionary implementation is quadratic,
and what is inspected is in fact list of associations.
Herby Vojčík hace 4 años
padre
commit
12d7d22013
Se han modificado 2 ficheros con 66 adiciones y 43 borrados
  1. 55 33
      src/Helios-Inspector.js
  2. 11 10
      src/Helios-Inspector.st

+ 55 - 33
src/Helios-Inspector.js

@@ -95,31 +95,30 @@ selector: "selectionDisplayString",
 protocol: "rendering",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "selectionDisplayString\x0a\x09|selection|\x0a\x09selection := self model selection.\x0a    ^ (self model variables includesKey: selection)\x0a    \x09ifTrue:[ (self model instVarObjectAt: selection) printString ]\x0a      \x09ifFalse:[ '' ]",
+source: "selectionDisplayString\x0a\x09|selection|\x0a\x09selection := self model selection.\x0a    ^ (self model instVarObjectAt: selection ifAbsent: [ ^ '' ]) printString",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["selection", "model", "ifTrue:ifFalse:", "includesKey:", "variables", "printString", "instVarObjectAt:"]
+messageSends: ["selection", "model", "printString", "instVarObjectAt:ifAbsent:"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 var selection;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
+var $early={};
+try {
 selection=$recv([$self._model()
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 ,$ctx1.sendIdx["model"]=1
 //>>excludeEnd("ctx");
 ][0])._selection();
-if($core.assert($recv($recv([$self._model()
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-,$ctx1.sendIdx["model"]=2
-//>>excludeEnd("ctx");
-][0])._variables())._includesKey_(selection))){
-return $recv($recv($self._model())._instVarObjectAt_(selection))._printString();
-} else {
-return "";
+return $recv($recv($self._model())._instVarObjectAt_ifAbsent_(selection,(function(){
+throw $early=[""];
+
+})))._printString();
 }
+catch(e) {if(e===$early)return e[0]; throw e}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"selectionDisplayString",{selection:selection})});
 //>>excludeEnd("ctx");
@@ -227,23 +226,31 @@ $globals.HLInspectorModel);
 
 $core.addMethod(
 $core.method({
-selector: "instVarObjectAt:",
+selector: "instVarObjectAt:ifAbsent:",
 protocol: "actions",
 //>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anInstVarName"],
-source: "instVarObjectAt: anInstVarName\x0a\x09^ self variables at: anInstVarName",
+args: ["anInstVarName", "aBlock"],
+source: "instVarObjectAt: anInstVarName ifAbsent: aBlock\x0a\x09^ (self variables detect: [ :assoc | assoc key = anInstVarName ] ifNone: aBlock) value",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["at:", "variables"]
-}, function ($methodClass){ return function (anInstVarName){
+messageSends: ["value", "detect:ifNone:", "variables", "=", "key"]
+}, function ($methodClass){ return function (anInstVarName,aBlock){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return $recv($self._variables())._at_(anInstVarName);
+return $recv($recv($self._variables())._detect_ifNone_((function(assoc){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"instVarObjectAt:",{anInstVarName:anInstVarName})});
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $recv($recv(assoc)._key()).__eq(anInstVarName);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({assoc:assoc},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),aBlock))._value();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"instVarObjectAt:ifAbsent:",{anInstVarName:anInstVarName,aBlock:aBlock})});
 //>>excludeEnd("ctx");
 }; }),
 $globals.HLInspectorModel);
@@ -326,17 +333,25 @@ selector: "selectedInstVarObject",
 protocol: "accessing",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "selectedInstVarObject\x0a\x09^ self instVarObjectAt: self selection",
+source: "selectedInstVarObject\x0a\x09^ self instVarObjectAt: self selection ifAbsent: [ self error: 'Unable to get variable value.' ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["instVarObjectAt:", "selection"]
+messageSends: ["instVarObjectAt:ifAbsent:", "selection", "error:"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return $self._instVarObjectAt_($self._selection());
+return $self._instVarObjectAt_ifAbsent_($self._selection(),(function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $self._error_("Unable to get variable value.");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
+//>>excludeEnd("ctx");
+}));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"selectedInstVarObject",{})});
 //>>excludeEnd("ctx");
@@ -427,11 +442,11 @@ selector: "variables",
 protocol: "accessing",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "variables\x0a\x09^ variables ifNil: [ Dictionary new ]",
-referencedClasses: ["Dictionary"],
+source: "variables\x0a\x09^ variables ifNil: [ #() ]",
+referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["ifNil:", "new"]
+messageSends: ["ifNil:"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -440,7 +455,7 @@ return $core.withContext(function($ctx1) {
 var $1;
 $1=$self.variables;
 if($1 == null || $1.a$nil){
-return $recv($globals.Dictionary)._new();
+return [];
 } else {
 return $1;
 }
@@ -879,17 +894,17 @@ selector: "variables",
 protocol: "accessing",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "variables\x0a\x09^ self model variables keys",
+source: "variables\x0a\x09^ self model variables collect: #key",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["keys", "variables", "model"]
+messageSends: ["collect:", "variables", "model"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return $recv($recv($self._model())._variables())._keys();
+return $recv($recv($self._model())._variables())._collect_("key");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"variables",{})});
 //>>excludeEnd("ctx");
@@ -1547,21 +1562,28 @@ $core.method({
 selector: "setVariables:",
 protocol: "actions",
 //>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aDictionary"],
-source: "setVariables: aDictionary\x0a\x09self model variables: aDictionary",
+args: ["aCollection"],
+source: "setVariables: aCollection\x0a\x09self model variables: (\x0a\x09\x09(aCollection respondsTo: #associations)\x0a\x09\x09\x09ifTrue: [ aCollection associations ]\x0a\x09\x09\x09ifFalse: [ aCollection ])",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["variables:", "model"]
-}, function ($methodClass){ return function (aDictionary){
+messageSends: ["variables:", "model", "ifTrue:ifFalse:", "respondsTo:", "associations"]
+}, function ($methodClass){ return function (aCollection){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-$recv($self._model())._variables_(aDictionary);
+var $1,$2;
+$1=$self._model();
+if($core.assert($recv(aCollection)._respondsTo_("associations"))){
+$2=$recv(aCollection)._associations();
+} else {
+$2=aCollection;
+}
+$recv($1)._variables_($2);
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"setVariables:",{aDictionary:aDictionary})});
+}, function($ctx1) {$ctx1.fill(self,"setVariables:",{aCollection:aCollection})});
 //>>excludeEnd("ctx");
 }; }),
 $globals.HLInspectorWidget);

+ 11 - 10
src/Helios-Inspector.st

@@ -28,9 +28,7 @@ renderContentOn: html
 selectionDisplayString
 	|selection|
 	selection := self model selection.
-    ^ (self model variables includesKey: selection)
-    	ifTrue:[ (self model instVarObjectAt: selection) printString ]
-      	ifFalse:[ '' ]
+    ^ (self model instVarObjectAt: selection ifAbsent: [ ^ '' ]) printString
 ! !
 
 HLModel subclass: #HLInspectorModel
@@ -67,7 +65,7 @@ label: aString
 !
 
 selectedInstVarObject
-	^ self instVarObjectAt: self selection
+	^ self instVarObjectAt: self selection ifAbsent: [ self error: 'Unable to get variable value.' ]
 !
 
 selection
@@ -81,7 +79,7 @@ selection: anObject
 !
 
 variables
-	^ variables ifNil: [ Dictionary new ]
+	^ variables ifNil: [ #() ]
 !
 
 variables: aCollection
@@ -96,8 +94,8 @@ inspect: anObject on: anInspector
 	inspectee inspectOn: anInspector
 !
 
-instVarObjectAt: anInstVarName
-	^ self variables at: anInstVarName
+instVarObjectAt: anInstVarName ifAbsent: aBlock
+	^ (self variables detect: [ :assoc | assoc key = anInstVarName ] ifNone: aBlock) value
 !
 
 selectedInstVar: anInstVarName
@@ -148,7 +146,7 @@ selection
 !
 
 variables
-	^ self model variables keys
+	^ self model variables collect: #key
 ! !
 
 !HLInspectorVariablesWidget methodsFor: 'actions'!
@@ -314,8 +312,11 @@ setLabel: aString
 	self model label: aString
 !
 
-setVariables: aDictionary
-	self model variables: aDictionary
+setVariables: aCollection
+	self model variables: (
+		(aCollection respondsTo: #associations)
+			ifTrue: [ aCollection associations ]
+			ifFalse: [ aCollection ])
 ! !
 
 !HLInspectorWidget methodsFor: 'defaults'!