Browse Source

Collection >> #shortenedPrintString.

Used to set inspector labels.
Herby Vojčík 4 years ago
parent
commit
40d349b2af

+ 1 - 0
lang/API-CHANGES.txt

@@ -2,6 +2,7 @@
 
 + Collection >>
   + copyEmpty
+  + shortenedPrintString
 
 
 0.25.0:

+ 126 - 0
lang/src/Kernel-Collections.js

@@ -1665,6 +1665,49 @@ return each;
 }; }),
 $globals.Collection);
 
+$core.addMethod(
+$core.method({
+selector: "shortenedPrintString",
+protocol: "printing",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "shortenedPrintString\x0a\x09^ self size <= 1\x0a\x09\x09ifTrue: [ self printString ]\x0a\x09\x09ifFalse: [ (self copyEmpty copyWith: self anyOne) printString, ' ... ', (self size - 1), ' more items' ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["ifTrue:ifFalse:", "<=", "size", "printString", ",", "copyWith:", "copyEmpty", "anyOne", "-"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+if($core.assert($recv([$self._size()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["size"]=1
+//>>excludeEnd("ctx");
+][0]).__lt_eq((1)))){
+return [$self._printString()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["printString"]=1
+//>>excludeEnd("ctx");
+][0];
+} else {
+return [$recv([$recv($recv($recv($recv($self._copyEmpty())._copyWith_($self._anyOne()))._printString()).__comma(" ... ")).__comma($recv($self._size()).__minus((1)))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx[","]=2
+//>>excludeEnd("ctx");
+][0]).__comma(" more items")
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx[","]=1
+//>>excludeEnd("ctx");
+][0];
+}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"shortenedPrintString",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.Collection);
+
 $core.addMethod(
 $core.method({
 selector: "single",
@@ -2769,6 +2812,54 @@ return copy;
 }; }),
 $globals.AssociativeCollection);
 
+$core.addMethod(
+$core.method({
+selector: "shortenedPrintString",
+protocol: "printing",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "shortenedPrintString\x0a\x09^ self size <= 1\x0a\x09\x09ifTrue: [ self printString ]\x0a\x09\x09ifFalse: [ | key | key := self keys anyOne. (self copyEmpty at: key put: (self at: key); yourself) printString, ' ... ', (self size - 1), ' more items' ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["ifTrue:ifFalse:", "<=", "size", "printString", "anyOne", "keys", ",", "at:put:", "copyEmpty", "at:", "yourself", "-"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+if($core.assert($recv([$self._size()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["size"]=1
+//>>excludeEnd("ctx");
+][0]).__lt_eq((1)))){
+return [$self._printString()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["printString"]=1
+//>>excludeEnd("ctx");
+][0];
+} else {
+var key;
+key=$recv($self._keys())._anyOne();
+$1=$self._copyEmpty();
+$recv($1)._at_put_(key,$self._at_(key));
+return [$recv([$recv($recv($recv($recv($1)._yourself())._printString()).__comma(" ... ")).__comma($recv($self._size()).__minus((1)))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx[","]=2
+//>>excludeEnd("ctx");
+][0]).__comma(" more items")
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx[","]=1
+//>>excludeEnd("ctx");
+][0];
+}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"shortenedPrintString",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.AssociativeCollection);
+
 $core.addMethod(
 $core.method({
 selector: "size",
@@ -6672,6 +6763,41 @@ return self;
 }; }),
 $globals.String);
 
+$core.addMethod(
+$core.method({
+selector: "shortenedPrintString",
+protocol: "printing",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "shortenedPrintString\x0a\x09^ self printString size > 30\x0a\x09\x09ifTrue: [ (self printString copyFrom: 1 to: 30), '...''' ]\x0a\x09\x09ifFalse: [ self printString ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["ifTrue:ifFalse:", ">", "size", "printString", ",", "copyFrom:to:"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+if($core.assert($recv($recv([$self._printString()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["printString"]=1
+//>>excludeEnd("ctx");
+][0])._size()).__gt((30)))){
+return $recv($recv([$self._printString()
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["printString"]=2
+//>>excludeEnd("ctx");
+][0])._copyFrom_to_((1),(30))).__comma("...'");
+} else {
+return $self._printString();
+}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"shortenedPrintString",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.String);
+
 $core.addMethod(
 $core.method({
 selector: "subStrings:",

+ 20 - 0
lang/src/Kernel-Collections.st

@@ -374,6 +374,14 @@ errorNotFound
 	self error: 'Object is not in the collection'
 ! !
 
+!Collection methodsFor: 'printing'!
+
+shortenedPrintString
+	^ self size <= 1
+		ifTrue: [ self printString ]
+		ifFalse: [ (self copyEmpty copyWith: self anyOne) printString, ' ... ', (self size - 1), ' more items' ]
+! !
+
 !Collection methodsFor: 'streaming'!
 
 putOn: aStream
@@ -658,6 +666,12 @@ printOn: aStream
 		do: [ :each | each printOn: aStream ]
 		separatedBy: [ aStream nextPutAll: ' , ' ].
 	aStream nextPutAll: ')'
+!
+
+shortenedPrintString
+	^ self size <= 1
+		ifTrue: [ self printString ]
+		ifFalse: [ | key | key := self keys anyOne. (self copyEmpty at: key put: (self at: key); yourself) printString, ' ... ', (self size - 1), ' more items' ]
 ! !
 
 !AssociativeCollection methodsFor: 'testing'!
@@ -1448,6 +1462,12 @@ printOn: aStream
 		nextPutAll: ''''
 !
 
+shortenedPrintString
+	^ self printString size > 30
+		ifTrue: [ (self printString copyFrom: 1 to: 30), '...''' ]
+		ifFalse: [ self printString ]
+!
+
 symbolPrintString
 	^ String streamContents: [ :str | self asSymbolPrintOn: str ]
 ! !

+ 9 - 58
lang/src/Platform-Services.js

@@ -1952,11 +1952,11 @@ selector: "inspectOn:",
 protocol: "*Platform-Services",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anInspector"],
-source: "inspectOn: anInspector\x0a\x09| variables |\x0a\x09variables := Dictionary new.\x0a\x09variables at: '#self' put: self.\x0a\x09variables at: '#keys' put: self keys.\x0a\x09self keysAndValuesDo: [ :key :value |\x0a\x09\x09variables at: key put: value ].\x0a\x09anInspector\x0a\x09\x09setLabel: self printString;\x0a\x09\x09setVariables: variables",
+source: "inspectOn: anInspector\x0a\x09| variables |\x0a\x09variables := Dictionary new.\x0a\x09variables at: '#self' put: self.\x0a\x09variables at: '#keys' put: self keys.\x0a\x09self keysAndValuesDo: [ :key :value |\x0a\x09\x09variables at: key put: value ].\x0a\x09anInspector\x0a\x09\x09setLabel: self shortenedPrintString;\x0a\x09\x09setVariables: variables",
 referencedClasses: ["Dictionary"],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["new", "at:put:", "keys", "keysAndValuesDo:", "setLabel:", "printString", "setVariables:"]
+messageSends: ["new", "at:put:", "keys", "keysAndValuesDo:", "setLabel:", "shortenedPrintString", "setVariables:"]
 }, function ($methodClass){ return function (anInspector){
 var self=this,$self=this;
 var variables;
@@ -1983,7 +1983,7 @@ return $recv(variables)._at_put_(key,value);
 }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,1)});
 //>>excludeEnd("ctx");
 }));
-$recv(anInspector)._setLabel_($self._printString());
+$recv(anInspector)._setLabel_($self._shortenedPrintString());
 $recv(anInspector)._setVariables_(variables);
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -1998,11 +1998,11 @@ selector: "inspectOn:",
 protocol: "*Platform-Services",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anInspector"],
-source: "inspectOn: anInspector\x0a\x09| variables |\x0a\x09variables := Dictionary new.\x0a\x09variables at: '#self' put: self.\x0a\x09self withIndexDo: [ :each :i |\x0a\x09\x09variables at: i put: each ].\x0a\x09anInspector\x0a\x09\x09setLabel: self printString;\x0a\x09\x09setVariables: variables",
+source: "inspectOn: anInspector\x0a\x09| variables |\x0a\x09variables := Dictionary new.\x0a\x09variables at: '#self' put: self.\x0a\x09self withIndexDo: [ :each :i |\x0a\x09\x09variables at: i put: each ].\x0a\x09anInspector\x0a\x09\x09setLabel: self shortenedPrintString;\x0a\x09\x09setVariables: variables",
 referencedClasses: ["Dictionary"],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["new", "at:put:", "withIndexDo:", "setLabel:", "printString", "setVariables:"]
+messageSends: ["new", "at:put:", "withIndexDo:", "setLabel:", "shortenedPrintString", "setVariables:"]
 }, function ($methodClass){ return function (anInspector){
 var self=this,$self=this;
 var variables;
@@ -2024,7 +2024,7 @@ return $recv(variables)._at_put_(i,each);
 }, function($ctx2) {$ctx2.fillBlock({each:each,i:i},$ctx1,1)});
 //>>excludeEnd("ctx");
 }));
-$recv(anInspector)._setLabel_($self._printString());
+$recv(anInspector)._setLabel_($self._shortenedPrintString());
 $recv(anInspector)._setVariables_(variables);
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -2196,11 +2196,11 @@ selector: "inspectOn:",
 protocol: "*Platform-Services",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anInspector"],
-source: "inspectOn: anInspector\x0a\x09| variables i |\x0a\x09variables := Dictionary new.\x0a\x09variables at: '#self' put: self.\x0a\x09i := 1.\x0a\x09self do: [ :each |\x0a\x09\x09variables at: i put: each.\x0a\x09\x09i := i + 1 ].\x0a\x09anInspector\x0a\x09\x09setLabel: self printString;\x0a\x09\x09setVariables: variables",
+source: "inspectOn: anInspector\x0a\x09| variables i |\x0a\x09variables := Dictionary new.\x0a\x09variables at: '#self' put: self.\x0a\x09i := 1.\x0a\x09self do: [ :each |\x0a\x09\x09variables at: i put: each.\x0a\x09\x09i := i + 1 ].\x0a\x09anInspector\x0a\x09\x09setLabel: self shortenedPrintString;\x0a\x09\x09setVariables: variables",
 referencedClasses: ["Dictionary"],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["new", "at:put:", "do:", "+", "setLabel:", "printString", "setVariables:"]
+messageSends: ["new", "at:put:", "do:", "+", "setLabel:", "shortenedPrintString", "setVariables:"]
 }, function ($methodClass){ return function (anInspector){
 var self=this,$self=this;
 var variables,i;
@@ -2225,7 +2225,7 @@ return i;
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
 //>>excludeEnd("ctx");
 }));
-$recv(anInspector)._setLabel_($self._printString());
+$recv(anInspector)._setLabel_($self._shortenedPrintString());
 $recv(anInspector)._setVariables_(variables);
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -2234,55 +2234,6 @@ return self;
 }; }),
 $globals.Set);
 
-$core.addMethod(
-$core.method({
-selector: "inspectOn:",
-protocol: "*Platform-Services",
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anInspector"],
-source: "inspectOn: anInspector\x0a\x09| label |\x0a\x09super inspectOn: anInspector.\x0a\x09self printString size > 30\x0a\x09\x09ifTrue: [ label := (self printString copyFrom: 1 to: 30), '...''' ]\x0a\x09\x09ifFalse: [ label := self printString ].\x0a\x09anInspector setLabel: label",
-referencedClasses: [],
-//>>excludeEnd("ide");
-pragmas: [],
-messageSends: ["inspectOn:", "ifTrue:ifFalse:", ">", "size", "printString", ",", "copyFrom:to:", "setLabel:"]
-}, function ($methodClass){ return function (anInspector){
-var self=this,$self=this;
-var label;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-[(
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = true,
-//>>excludeEnd("ctx");
-($methodClass.superclass||$boot.nilAsClass).fn.prototype._inspectOn_.call($self,anInspector))
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-,$ctx1.supercall = false
-//>>excludeEnd("ctx");
-][0];
-if($core.assert($recv($recv([$self._printString()
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-,$ctx1.sendIdx["printString"]=1
-//>>excludeEnd("ctx");
-][0])._size()).__gt((30)))){
-label=$recv($recv([$self._printString()
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-,$ctx1.sendIdx["printString"]=2
-//>>excludeEnd("ctx");
-][0])._copyFrom_to_((1),(30))).__comma("...'");
-label;
-} else {
-label=$self._printString();
-label;
-}
-$recv(anInspector)._setLabel_(label);
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"inspectOn:",{anInspector:anInspector,label:label})});
-//>>excludeEnd("ctx");
-}; }),
-$globals.String);
-
 $core.addMethod(
 $core.method({
 selector: "inspectOn:",

+ 3 - 14
lang/src/Platform-Services.st

@@ -540,7 +540,7 @@ inspectOn: anInspector
 	self keysAndValuesDo: [ :key :value |
 		variables at: key put: value ].
 	anInspector
-		setLabel: self printString;
+		setLabel: self shortenedPrintString;
 		setVariables: variables
 ! !
 
@@ -553,7 +553,7 @@ inspectOn: anInspector
 	self withIndexDo: [ :each :i |
 		variables at: i put: each ].
 	anInspector
-		setLabel: self printString;
+		setLabel: self shortenedPrintString;
 		setVariables: variables
 ! !
 
@@ -619,21 +619,10 @@ inspectOn: anInspector
 		variables at: i put: each.
 		i := i + 1 ].
 	anInspector
-		setLabel: self printString;
+		setLabel: self shortenedPrintString;
 		setVariables: variables
 ! !
 
-!String methodsFor: '*Platform-Services'!
-
-inspectOn: anInspector
-	| label |
-	super inspectOn: anInspector.
-	self printString size > 30
-		ifTrue: [ label := (self printString copyFrom: 1 to: 30), '...''' ]
-		ifFalse: [ label := self printString ].
-	anInspector setLabel: label
-! !
-
 !TMethodContext methodsFor: '*Platform-Services'!
 
 inspectOn: anInspector