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 >>
 + BehaviorBody >>
   + setTraitComposition:
   + setTraitComposition:
   + traitCompositionDefinition
   + traitCompositionDefinition
+  + traitUsers
+  + allSubclassesDo:
+  + superclass
 + Trait
 + Trait
   + allInstanceVariableNames
   + allInstanceVariableNames
   + allSubclassesDo:
   + allSubclassesDo:

+ 64 - 58
src/Kernel-Classes.js

@@ -105,6 +105,24 @@ messageSends: ["at:ifAbsent:", "methodDictionary", "selector", "ifFalse:", "incl
 }),
 }),
 $globals.BehaviorBody);
 $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.addMethod(
 $core.method({
 $core.method({
 selector: "basicAddCompiledMethod:",
 selector: "basicAddCompiledMethod:",
@@ -241,15 +259,21 @@ selector: "definition",
 protocol: "accessing",
 protocol: "accessing",
 fn: function (){
 fn: function (){
 var self=this;
 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);
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
 args: [],
-source: "definition\x0a\x09^ ''",
+source: "definition\x0a\x09self subclassResponsibility",
 referencedClasses: [],
 referencedClasses: [],
 //>>excludeEnd("ide");
 //>>excludeEnd("ide");
-messageSends: []
+messageSends: ["subclassResponsibility"]
 }),
 }),
 $globals.BehaviorBody);
 $globals.BehaviorBody);
 
 
@@ -890,6 +914,24 @@ messageSends: []
 }),
 }),
 $globals.BehaviorBody);
 $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.addMethod(
 $core.method({
 $core.method({
 selector: "theMetaClass",
 selector: "theMetaClass",
@@ -1035,6 +1077,24 @@ messageSends: ["ifNotEmpty:", "traitComposition", "streamContents:", "write:", "
 }),
 }),
 $globals.BehaviorBody);
 $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");
 $core.addClass("Behavior", $globals.BehaviorBody, [], "Kernel-Classes");
@@ -1287,24 +1347,6 @@ messageSends: ["or:", "includesSelector:", "asString", "and:", "notNil", "superc
 }),
 }),
 $globals.Behavior);
 $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.addMethod(
 $core.method({
 $core.method({
 selector: "includesBehavior:",
 selector: "includesBehavior:",
@@ -2650,24 +2692,6 @@ messageSends: []
 }),
 }),
 $globals.Trait);
 $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.addMethod(
 $core.method({
 $core.method({
 selector: "asJavascript",
 selector: "asJavascript",
@@ -2916,24 +2940,6 @@ messageSends: ["ifTrue:", "=", "package", "basicAt:put:", "removeElement:", "org
 }),
 }),
 $globals.Trait);
 $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.addMethod(
 $core.method({
 $core.method({
 selector: "theMetaClass",
 selector: "theMetaClass",

+ 15 - 14
src/Kernel-Classes.st

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