Browse Source

Refactor classes to have defaults for certain messages.

Herbert Vojčík 7 years ago
parent
commit
d633bba06a
3 changed files with 82 additions and 72 deletions
  1. 3 0
      API-CHANGES.txt
  2. 64 58
      src/Kernel-Classes.js
  3. 15 14
      src/Kernel-Classes.st

+ 3 - 0
API-CHANGES.txt

@@ -9,6 +9,9 @@
 + BehaviorBody >>
   + setTraitComposition:
   + traitCompositionDefinition
+  + traitUsers
+  + allSubclassesDo:
+  + superclass
 + Trait
   + allInstanceVariableNames
   + allSubclassesDo:

+ 64 - 58
src/Kernel-Classes.js

@@ -105,6 +105,24 @@ messageSends: ["at:ifAbsent:", "methodDictionary", "selector", "ifFalse:", "incl
 }),
 $globals.BehaviorBody);
 
+$core.addMethod(
+$core.method({
+selector: "allSubclassesDo:",
+protocol: "enumerating",
+fn: function (aBlock){
+var self=this;
+return self;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aBlock"],
+source: "allSubclassesDo: aBlock\x0a\x09\x22Default for non-classes; to be able to send #allSubclassesDo: to any class / trait.\x22",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.BehaviorBody);
+
 $core.addMethod(
 $core.method({
 selector: "basicAddCompiledMethod:",
@@ -241,15 +259,21 @@ selector: "definition",
 protocol: "accessing",
 fn: function (){
 var self=this;
-return "";
-
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+self._subclassResponsibility();
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"definition",{},$globals.BehaviorBody)});
+//>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "definition\x0a\x09^ ''",
+source: "definition\x0a\x09self subclassResponsibility",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: []
+messageSends: ["subclassResponsibility"]
 }),
 $globals.BehaviorBody);
 
@@ -890,6 +914,24 @@ messageSends: []
 }),
 $globals.BehaviorBody);
 
+$core.addMethod(
+$core.method({
+selector: "superclass",
+protocol: "accessing",
+fn: function (){
+var self=this;
+return nil;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "superclass\x0a\x09\x22Default for non-classes; to be able to send #superclass to any class / trait.\x22\x0a\x09^ nil",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.BehaviorBody);
+
 $core.addMethod(
 $core.method({
 selector: "theMetaClass",
@@ -1035,6 +1077,24 @@ messageSends: ["ifNotEmpty:", "traitComposition", "streamContents:", "write:", "
 }),
 $globals.BehaviorBody);
 
+$core.addMethod(
+$core.method({
+selector: "traitUsers",
+protocol: "accessing",
+fn: function (){
+var self=this;
+return [];
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "traitUsers\x0a\x09\x22Default for non-traits; to be able to send #traitUsers to any class / trait\x22\x0a\x09^ #()",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.BehaviorBody);
+
 
 
 $core.addClass("Behavior", $globals.BehaviorBody, [], "Kernel-Classes");
@@ -1287,24 +1347,6 @@ messageSends: ["or:", "includesSelector:", "asString", "and:", "notNil", "superc
 }),
 $globals.Behavior);
 
-$core.addMethod(
-$core.method({
-selector: "definition",
-protocol: "accessing",
-fn: function (){
-var self=this;
-return "";
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "definition\x0a\x09^ ''",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.Behavior);
-
 $core.addMethod(
 $core.method({
 selector: "includesBehavior:",
@@ -2650,24 +2692,6 @@ messageSends: []
 }),
 $globals.Trait);
 
-$core.addMethod(
-$core.method({
-selector: "allSubclassesDo:",
-protocol: "IDE compatibility",
-fn: function (aBlock){
-var self=this;
-return self;
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aBlock"],
-source: "allSubclassesDo: aBlock",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.Trait);
-
 $core.addMethod(
 $core.method({
 selector: "asJavascript",
@@ -2916,24 +2940,6 @@ messageSends: ["ifTrue:", "=", "package", "basicAt:put:", "removeElement:", "org
 }),
 $globals.Trait);
 
-$core.addMethod(
-$core.method({
-selector: "superclass",
-protocol: "IDE compatibility",
-fn: function (){
-var self=this;
-return nil;
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "superclass\x0a\x09^ nil",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.Trait);
-
 $core.addMethod(
 $core.method({
 selector: "theMetaClass",

+ 15 - 14
src/Kernel-Classes.st

@@ -28,7 +28,7 @@ comment: aString
 !
 
 definition
-	^ ''
+	self subclassResponsibility
 !
 
 methodAt: aString
@@ -119,6 +119,11 @@ selectors
 	^ self methodDictionary keys
 !
 
+superclass
+	"Default for non-classes; to be able to send #superclass to any class / trait."
+	^ nil
+!
+
 theMetaClass
 	self subclassResponsibility
 !
@@ -139,6 +144,11 @@ traitCompositionDefinition
 				do: [ :each | str write: each definition ]
 				separatedBy: [ str write: '. ' ].
 			str write: '}' ] ]
+!
+
+traitUsers
+	"Default for non-traits; to be able to send #traitUsers to any class / trait"
+	^ #()
 ! !
 
 !BehaviorBody methodsFor: 'compiling'!
@@ -202,6 +212,10 @@ setTraitComposition: aTraitComposition
 
 !BehaviorBody methodsFor: 'enumerating'!
 
+allSubclassesDo: aBlock
+	"Default for non-classes; to be able to send #allSubclassesDo: to any class / trait."
+!
+
 protocolsDo: aBlock
 	"Execute aBlock for each method protocol with
 	its collection of methods in the sort order of protocol name."
@@ -284,10 +298,6 @@ allSuperclasses
 		yourself
 !
 
-definition
-	^ ''
-!
-
 instanceVariableNames
 	<inlineJS: 'return self.iVarNames'>
 !
@@ -601,15 +611,6 @@ BehaviorBody subclass: #Trait
 	instanceVariableNames: ''
 	package: 'Kernel-Classes'!
 
-!Trait methodsFor: 'IDE compatibility'!
-
-allSubclassesDo: aBlock
-!
-
-superclass
-	^ nil
-! !
-
 !Trait methodsFor: 'accessing'!
 
 category