Browse Source

Trait >> traitUsers

Herbert Vojčík 7 years ago
parent
commit
34302742a1
4 changed files with 38 additions and 1 deletions
  1. 1 0
      API-CHANGES.txt
  2. 23 0
      src/Kernel-Classes.js
  3. 4 0
      src/Kernel-Classes.st
  4. 10 1
      support/kernel-language.js

+ 1 - 0
API-CHANGES.txt

@@ -21,6 +21,7 @@
   + theMetaClass
   + theNonMetaClass
   + exportBehaviorDefinitionTo:using:
+  + traitUsers
 + TraitTransformation
   + -
   + @

+ 23 - 0
src/Kernel-Classes.js

@@ -2698,6 +2698,29 @@ messageSends: []
 }),
 $globals.Trait);
 
+$core.addMethod(
+$core.method({
+selector: "traitUsers",
+protocol: "accessing",
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv(self._basicAt_("traitUsers"))._copy();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"traitUsers",{},$globals.Trait)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "traitUsers\x0a\x09^ (self basicAt: 'traitUsers') copy",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["copy", "basicAt:"]
+}),
+$globals.Trait);
+
 
 $core.addMethod(
 $core.method({

+ 4 - 0
src/Kernel-Classes.st

@@ -605,6 +605,10 @@ theMetaClass
 
 theNonMetaClass
 	^ self
+!
+
+traitUsers
+	^ (self basicAt: 'traitUsers') copy
 ! !
 
 !Trait methodsFor: 'compiler compatibility'!

+ 10 - 1
support/kernel-language.js

@@ -59,12 +59,14 @@ define(['./compatibility'], function () {
         });
     }
 
-    TraitsBrik.deps = ["behaviors", "composition", "root"];
+    TraitsBrik.deps = ["behaviors", "composition", "arraySet", "root"];
     function TraitsBrik (brikz, st) {
         var coreFns = brikz.root.coreFns;
         var SmalltalkBehaviorBody = brikz.behaviors.BehaviorBody;
         var setupMethods = brikz.composition.setupMethods;
         var buildBehaviorBody = brikz.behaviors.buildBehaviorBody;
+        var addElement = brikz.arraySet.addElement;
+        var removeElement = brikz.arraySet.removeElement;
 
         function SmalltalkTrait () {
         }
@@ -88,6 +90,12 @@ define(['./compatibility'], function () {
         defineMethod(SmalltalkTrait, "methodRemoved", function (method) {
             if (st._traitMethodRemoved) st._traitMethodRemoved(method, this);
         });
+        defineMethod(SmalltalkTrait, "addUser", function (behaviorBody) {
+            addElement(this.traitUsers, behaviorBody);
+        });
+        defineMethod(SmalltalkTrait, "removeUser", function (behaviorBody) {
+            removeElement(this.traitUsers, behaviorBody);
+        });
 
         function traitBuilder (className) {
             return {
@@ -96,6 +104,7 @@ define(['./compatibility'], function () {
                     var that = new SmalltalkTrait();
                     that.className = className;
                     that.pkg = pkg;
+                    that.traitUsers = [];
                     setupMethods(that);
                     return that;
                 },