This repository has been archived by the owner on Nov 28, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsPackage.js
6092 lines (5090 loc) · 265 KB
/
JsPackage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
The MIT License (MIT)
Copyright (c) 2012-2013 Abraham TEWA
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*global console:false */
/**
* A number, or a string containing a number.
* @typedef {Definition} Definition
* @access public
*/
/**
* Class are created using
* @typedef {Object} Instance
* @access public
*/
/**
* @typedef {object|Namespace|Package} NamespaceLike
*/
/**
* @typedef {object} Namespace
*/
/**
* @typedef {object} Package
*/
/**
* @typedef {object} Class
*/
/**
* @namespace
* @name main
**/
(function (parameters) {
"use strict";
/**
Environment of a class or package. An environment will contains private, public or protected attribute, according to a
{@link main.Core.DeclarationProperty}
* @typedef {object} Environment
* @memberof main
* @property {string} toString - Return the string representation of the environment. The string representation will indicate if we are in a public or private environment.
* @property {object} $ - Contains informations and methods to manipulate the environment.
*/
/**
* Private environment of classes. This environment contains all public, protected and private statics properties of the class.
* @class ClassPrivateEnvironment
* @memberof main.Class
*/
/**
* Protected environment of classes. This environment contains all public and protected static properties of the class.
* @class ClassProtectedEnvironment
* @memberof main.Class
*/
/**
* Public environment of classes. This environment contains all public static properties of the class
* @class ClassPublicEnvironment
* @memberof main.Class
*/
/**
* Self environment of classes. This environment contains all public, protected static properties of the current class
* @class ClassSelfEnvironment
* @memberof main.Class
*/
/**
* Super environment of classes. This environment contains all public, protected static properties of the parent class
* @class ClassSuperEnvironment
* @memberof main.Class
*/
var globalThis, globalName, debugMode, defaultNamespaces, onerror, publicEnv;
var version;
var jsArray, jsGlobal, jsObject;
var Class, Constants, Core, Definition, Descriptor, Errors, Interface, Namespace, Package, Signature, Version;
/**
* Context in wich JsPackage will be added. This is given in parameter when the file is called.
* By default, this is the "window" object in browser, howether, "global" for Node.js environment.
* @name globalThis
* @variable
* @type object
* @default this.window === undefined ? global : this
* @memberof main
*/
globalThis = parameters.parent;
/**
* Name of JsPackage in the context (see {@link main.globalThis}).
* @variable
* @name globalName
* @type string
* @default 'JsPackage'
* @memberof main
*/
globalName = '' + parameters.name; // The given name must be a string
debugMode = parameters.debug === undefined ? false : !!parameters.debug;
onerror = parameters.onerror;
if (debugMode) {
if (console !== undefined) {
console.log('JsPackage : ' + globalName + ' in debugMode');
};
}
/**
* An authorization list is used to list all objects that can access the currect package/class/instance private/protected environment.
* @typedef {array} main.AuthorizationList
*/
/*----------------------------------------------------------------------------------------------
| Package interne : Class
|-----------------------------------------------------------------------------------------------
| Description
|
| Ce package permet la cr�ation de classe et de leurs instances.
|
|-----------------------------------------------------------------------------------------------
| Cr�ation d'une classe
|
| La cr�ation d'une classe est faite par la fonction "newClass". Cette fonction re�oit entre
| param�tre la d�finition de la classe. Elle va convertir la d�finition en d�finition standard
| et ensuite faire appel � "createClass", en lui fournissant la d�finition standard ouverte
| (cad, l'objet "me" de la d�finition).
| "createClass" va alors cr�er l'objet "me" de la classe, ainsi que les diff�rents environ-
| nements de la classe :
| . publicEnv
| . thisEnv
| . selfEnv
| . superEnv
|
| Pour la description de ces diff�rents environnements, voir la section "Description des
| environnements" plus loin.
|
| Pour chacun de ces environnements, il va cr�er des variables listants les propri�t�s de
| visibilit� des attributs et m�thodes. On va � chaque fois pr�ciser si l'on peut ajouter les
| attributs/m�thodes publiques, priv�s et prot�g�s, et si on peut les surcharger ou non.
| Ces objets poss�de aussi une propri�t� "include", valoris� initialement � "true". Cet
| attribut permettra de filtrer par la suite les obejts "properties" � traiter.
| Ces variables sont respectivemenets :
| . publicProperties
| . thisProperties
| . selfProperties
| . superProperties
|
| Ces 4 objets vont �tre enregistr�s dans un tableau : listProperties.
|
| On va ensuite cr�er la variable "levels". Il s'agira d'un tableau simple dont le seul �l�ment
| � l'initialisation sera "me". Le r�le de level sera discut� plus loin.
|
| On va v�rifier ensuite si la classe h�rite des propri�t�s d'une autre classe. Si oui, alors
| on va appeler la m�thode "extendClass" en lui fournissant la classe �tendue, "listProperties"
| et "levels".
|
| "extendClass" est une fonction qui ressemble fortement � "createClass". Son r�le est cependant
| tout autre. Elle va commencer par cr�er l'objet "me" de la classe fournie en param�tre.
| Elle va cr�er de la m�me mani�re les variables publicProperties, thisProperties,
| selfProperties et superProperties correspondant � ces diff�rents environnements. Cette fois
| cependant, ces objets vont �tre ajout�s � "listProperties" re�u en param�tre. Leurs attributs
| "include" est valoris� � ce moment l� � "true".
| De la m�me mani�re que "createClass", on va v�rifier si la classe h�rite d'une autre classe.
| si c'est le cas, on appelera "extendClass" avec la classe h�rit�e, "listProperties" et
| "levels".
| Si ce n'est pas le cas, on va alors s'occuper de d�clarer les propri�t�s � notre classe.
| h�ritante.
| On va pour cel� appeler la fonction "Core.declare", � laquelle on va fournir pour chaque
| propri�t� de la classe h�ritante, son nom et sa description. "Core.declare" recevera aussi
| "listProperties" et le "thisEnv" de la propri�t�.
| "Core.declare" va alors parcourir chaque objets de "listProperties" et d�terminer s'il faut
| ou non y ajouter la propri�t� pass�e en param�tre.
| Exemple :
| Si la propri�t� est priv�e et que l'�lement 0 de "listProperties" indique de ne pas
| ajouter les objets priv�s (addPrivate = false), alors on ajoutera pas la propri�t� �
| l'environnement associ�.
|
| A noter qu'en r�alit�, on ajoute un "alias" vers la propri�t� (qui elle n'existe que sur un
| seul thisEnv).
|
|---------------------------------------------------------------------------------------------*/
/**
* The namespace Class contains all the function for class creation.
* @namespace
* @name Class
* @memberof main
* @access private
*/
Class = (function () {
/**
* <p>Create a new class from a definition. The definition have been validated.</p>
* <p>First, the {@link main.Class.ClassMe|me} environment of the class will be created. {@link main.Class.ClassMe|me} environment contains all
* {@link main.Class.ClassPrivateEnvironment|private}, {@link main.Class.ClassPublicEnvironment|public}, {@link main.Class.ClassProtectedEnvironment|protected},
* {@link main.Class.ClassSelfEnvironment|self} and {@link main.Class.ClassSuperEnvironment|super} environments. For each of these environments, the function
* will create a {@link main.Core.DeclarationProperty|DeclarationProperty} variable. This variable list all properties that is accessible from the current environment.
* It also declare if the property is public, private or protected, overridable or not. It contains also a "include" flag.</p>
* <p>After creating {@link main.Class.ClassMe|me} and all environments
| Pour chacun de ces environnements, il va cr�er des variables listants les propri�t�s de
| visibilit� des attributs et m�thodes. On va � chaque fois pr�ciser si l'on peut ajouter les
| attributs/m�thodes publiques, priv�s et prot�g�s, et si on peut les surcharger ou non.
| Ces objets poss�de aussi une propri�t� "include", valoris� initialement � "true". Cet
| attribut permettra de filtrer par la suite les obejts "properties" � traiter.
* @function createClass
* @returns {Class} Newly created class
* @memberof main.Class
* @access private
* @param {main.Definition.DefinitionMe} definition Definition of the function. The definition has been validated at this point.
* @property {main.Class.ClassMe} me "Me" of the class.
* @property {main.Core.DeclarationProperty[]} listProperties List of all declaration properties of the class and the child classes.
* @property {Descriptor} publicInitialization This variable is used to determine class can be instanciable in public or not. It's determine by the visibility of the initialization function of the definition.
* @property {main.Core.DeclarationProperty} privateProperties Declaration property of the private environment of the class
* @property {main.Core.DeclarationProperty} protectedProperties Declaration property of the protected environment of the class
* @property {main.Core.DeclarationProperty} publicProperties Declaration property of the public environment of the class
* @property {main.Core.DeclarationProperty} selfProperties Declaration property of the self environment of the class
*/
var createClass = function (definition) {
var env, i, id, listProperties, listAncestry, me, meExtends, name, newFct, protectedProperties, publicInitialization, publicProperties, selfProperties, thisProperties, openExtend;
/**
* {@link main.me|me} object of classes
* @class ClassMe
* @memberof main.Class
* @access public
*/
me = {
/**
* List all the authorized {@link Class|classes} and {@link Package|packages} that can access to the private or protected environment of the class or his instance.
* @member {main.AuthorizationList} authorizationList
* @memberof main.Class.ClassMe
*/
authorizationList : {}
/**
* Opened definition of the class
* @member {DefinitionMe} definition
* @memberof main.Class.ClassMe
*/
, definition : definition
/**
* Determine if the parent is enumerable (true) of not (false)
* @member {boolean} enumerable
* @memberof main.Class.ClassMe
*/
, enumerable : definition.enumerable
/**
* Class extended by the current class.
* @member {Class} extends
* @memberof main.Class.ClassMe
*/
, extends : definition.extends
/**
* Initialization function called after instanciation
* @function initialization
* @memberof main.Class.ClassMe
*/
, initialization : definition.initialization
/**
* List of the interfaces implemented by the class
* @member {Class[]} implements
* @memberof main.Class.ClassMe
*/
, implements : definition.implements.splice(0)
/**
* <p>Determine whether or not the class is an abstract class.</p>
* <p>This value depends on the $.abstract field of the definition of the class</p>
* @function isAbstract
* @memberof main.Class.ClassMe
* @returns {boolean} true: the class is an abstract class, false otherwise
*/
, isAbstract : definition.isAbstract
/**
* <p>Determine whether or not the class is an final class.</p>
* <p>This value depends on the $.final field of the definition of the class</p>
* @function isFinal
* @memberof main.Class.ClassMe
* @returns {boolean} true: the class is final, false otherwise
*/
, isFinal : definition.isFinal
/**
* @member {Class[]} levels
* @memberof main.Class.ClassMe
*/
, levels : []
/**
* Name of the classs. All "Me" object must have this property
* @member {string} name
* @memberof main.Class.ClassMe
*/
, name : definition.name
/**
* Parent of the class. All "Me" object must have this property
* @member {NamespaceLike} Parent
* @memberof main.Class.ClassMe
*/
, parent : definition.parent
/**
* Name of the class. This property is called by the get function {@link Class.name} in private environment
* @member {string} privateName
* @memberof main.Class.ClassMe
*/
, privateName : undefined
/**
* Parent of the class. This property is called by the get function {@link Class.parent} in private environment
* @member {string} privateParent
* @memberof main.Class.ClassMe
*/
, privateParent : undefined
/**
* Protected environment of the class
* @member {main.Class.ClassProtectedEnvironment} protectedEnv
* @memberof main.Class.ClassMe
*/
, protectedEnv : {}
/**
* This function will be use as a false prototype of the class : Instance will be created with this function, allowing the use of "instanceof" standard function.
* @member {function} prototype
* @memberof main.Class.ClassMe
*/
, prototype : function() {}
/**
* Name of the class. This property is called by the get function {@link Class.name} in public environment
* @member {string} publicName
* @memberof main.Class.ClassMe
*/
, publicName : undefined
/**
* Parent of the class. This property is called by the get function {@link Class.parent} in public environment
* @member {NamespaceLike} publicParent
* @memberof main.Class.ClassMe
*/
, publicParent : undefined
/**
* Self environment of the class.
* @member {main.Class.ClassSelfEnvironment} selfEnv
* @memberof main.Class.ClassMe
*/
, selfEnv : {}
/**
* Super environment of the class
* @member {main.Class.ClassSuperEnvironment} superEnv
* @memberof main.Class.ClassMe
*/
, superEnv : undefined
/**
* toString function used to represent class.
* @function toString
* @memberof main.Class.ClassMe
* @returns {string} String representation of the class
*/
, toString : function() { return 'Class : Me'; }
/**
* Constant representing the class.
* @member {string} type
* @memberof main.Class.ClassMe
*/
, type : Constants.CLASS
/**
* Object in which will be store all values of typed attributes
* @member {object} typedAttributes
* @memberof main.Class.ClassMe
*/
, typedAttributes : {}};
/**
* ID of the class
* @member {number} id
* @memberof main.Class.ClassMe
*/
me.id = Core.getNewId(me);
/**
* Determine if the current class has instanciate the given parameter object.
* @func classOf
* @memberof main.Class.ClassMe
* @param {object} object to test
* @returns {boolean} true: the class is the one who instanciate the object. False otherwise
*/
me.classOf = fct.classOf(me);
/**
* Determine if the current class is a parent of the object
* @func parentOf
* @memberof main.Class.ClassMe
* @param {object} object to test
* @returns {boolean} true: the class is parent of the instance, false otherwise
*/
me.parentOf = fct.parentOf(me);
/**
<p>Return the parent of the class. This function will be use as a get property in the private environnment.</p>
<p>This function must exist because at the creation of the class, the parent is not yet fixed :
the parent is fixed once it is sealed. Before that, it's not even sure that the class will be a member of the parent object</p>
* @func getPrivateParent
* @memberof main.Class.ClassMe
* @param {object} object to test
* @returns {NamespaceLike} parent of the class. undefined if their is no parent.
*/
me.getPrivateParent = Core.fct.getValue(me, 'privateParent');
/**
<p>Return the parent of the class. This function will be use as a get property in the public environnment.</p>
<p>This function must exist because at the creation of the class, the parent is not yet fixed :
the parent is fixed once it is sealed. Before that, it's not even sure that the class will be a member of the parent object</p>
* @func getPublicParent
* @memberof main.Class.ClassMe
* @param {object} object to test
* @returns {NamespaceLike} parent of the class. undefined if their is no parent.
*/
me.getPublicParent = Core.fct.getValue(me, 'publicParent');
/**
<p>Return the parent name of the class in the parent object. This function will be use as a get property in the private environnment.</p>
<p>This function must exist because at the creation of the class, the parent is not yet fixed :
the parent is fixed once it is sealed. Before that, it's not even sure that the class will be a member of the parent object</p>
* @func getPrivateName
* @memberof main.Class.ClassMe
* @param {object} object to test
* @returns {string} the class name in parent object. undefined if their is no parents.
*/
me.getPrivateName = Core.fct.getValue(me, 'privateName');
/**
<p>Return the parent name of the class in the parent object. This function will be use as a get property in the public environnment.</p>
<p>This function must exist because at the creation of the class, the parent is not yet fixed :
the parent is fixed once it is sealed. Before that, it's not even sure that the class will be a member of the parent object</p>
* @func getPublicName
* @memberof main.Class.ClassMe
* @param {object} object to test
* @returns {string} the class name in parent object. undefined if their is no parents.
*/
me.getPublicName = Core.fct.getValue(me, 'publicName');
newFct = fct.getNewObject(me);
// If we have a initialization function, then we use it to create the public environment.
if (me.definition.initialization !== undefined) {
// "initialization" is a descriptor describing a method. Is visibility determine who can
// instanciate the function
if (me.initialization.isPublic())
publicInitialization = newFct;
else
publicInitialization = fct.notInstanciableFunction(me);
}
else {
me.initialization = undefined;
publicInitialization = newFct;
}
// The current class can access is one private environment
me.authorizationList[me.id] = 'private';
/**
* Initialization function of the class
* @member {function} New
* @memberof main.Class.ClassMe
*/
me.New = newFct;
/**
* Public environment of the class
* @member {main.Class.ClassPublicEnvironment} publicEnv
* @memberof main.Class.ClassMe
*/
me.publicEnv = publicInitialization;
/**
* Private environment of the class
* @member {main.Class.ClassPrivateEnvironment} thisEnv
* @memberof main.Class.ClassMe
*/
me.thisEnv = fct.getThisEnv(me);
/**
* Return a copy of the ClassMe.{@link main.Class.ClassMe.ancestry|ancestry}.
* @member {Class[]} getAncestry
* @memberof main.Class.ClassMe
*/
me.getAncestry = fct.getAncestry(me);
/**
* Public environment of the class
* @member {Class} Class
* @memberof main.Class.ClassMe
*/
me.Class = me.publicEnv;
/**
* This attribute is added to allow "instanceof" to work detect the instance as an instance of the current class.
* @see main.Class.ClassMe.prototype
* @member {function} __proto__
* @memberof main.Class.ClassPublicEnvironment
*/
me.publicEnv.prototype = me.prototype.prototype;
me._patteBlanche = Core.fct._patteBlanche(me)
// Properties of the environment
protectedProperties = { env : me.protectedEnv
, addPrivate : false
, addProtected : true
, addPublic : true
, include : true
, overridePrivate : false
, overrideProtected : true
, overridePublic : true };
publicProperties = { env : me.publicEnv
, addPrivate : false
, addProtected : false
, addPublic : true
, include : true
, overridePrivate : false
, overrideProtected : false
, overridePublic : true };
selfProperties = { env : me.selfEnv
, addPrivate : false
, addProtected : true
, addPublic : true
, include : true
, overridePrivate : false
, overrideProtected : true
, overridePublic : true };
thisProperties = { env : me.thisEnv
, addPrivate : false
, addProtected : true
, addPublic : true
, include : true
, overridePrivate : false
, overrideProtected : true
, overridePublic : true };
listProperties = [protectedProperties, publicProperties, selfProperties, thisProperties];
me.levels.push(me);
// Creating the extended environment
if (me.extends !== undefined) {
extendClass(me.extends, listProperties, me.levels, me, me.implements);
openExtend = me.extends.$._open(Core.beacon);
/** Contains the ancesters of the class.
This list is build :<ul>
<li>by retreiving the list of ancesters of the parent class</li>
<li>copying this list</li>
<li>adding parent class</li></ul>
* @member {ClassAncestryList} ancestry
* @memberof main.Class.ClassMe
*/
me.ancestry = { me : openExtend.ancestry.me.slice(0)
, publicEnv : openExtend.ancestry.publicEnv.slice(0)};
me.ancestry.me.unshift(openExtend);
me.ancestry.publicEnv.unshift(openExtend.Class);
me.superEnv = openExtend.protectedEnv;
/** ID of topest ancester of the Class.
* @member {number} rootId
* @memberof main.Class.ClassMe
*/
me.rootId = openExtend.rootId;
// Adding parent implemented interfaces
for (i in openExtend.implements) {
if (me.implements.indexOf(openExtend.implements[i]) === -1)
me.implements.push(openExtend.implements[i]);
};
}
else {
me.ancestry = {me:[], publicEnv:[]};
me.rootId = me.id;
}
me.authorizationList[me.id] = 'private';
thisProperties.include = false;
selfProperties.addPrivate = true;
// Adding all static members of the definition in the class
for(name in me.definition.staticEnv) {
Core.declare ( definition.staticEnv[name] // descriptor
, name // name
, me // thisEnv
, listProperties // listEnv
, true); // isStatic
}
// Adding all constant members of the definition in the class
for(name in me.definition.constantEnv) {
Core.declare ( definition.constantEnv[name] // descriptor
, name // name
, me // thisEnv
, listProperties // listEnv
, true); // isStatic
}
/**
* @class
* @name $
* @memberof main.Class.ClassPrivateEnvironment
*/
me.thisEnv.$ = { /** Internal function used by JsPackage to determine whether or not the object has been created by JsPackage.
* @method _patteBlanche
* @memberof main.Class.ClassPrivateEnvironment.$
*/
_patteBlanche : me._patteBlanche
/** This attribute return the current class, always with the highest visibility level accessible.
* @member {Class} Class
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, Class : me.thisEnv
/** Determine if the current class has instanciate the given parameter object.
* @func classOf
* @param {object} object to test
* @returns {boolean} true: the class is the one who instanciate the object. False otherwise
* @memberof main.Class.ClassPrivateEnvironment.$
* @see {@link main.Class.ClassMe|classOf}
*/
, classOf : me.classOf
/** Definition of the class.
* @see {@link main.Class.ClassMe|definition}
* @member {Definition} definition
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, definition : me.definition.publicEnv
/** Extended Class
* @see {@link main.Class.ClassMe|extends}
* @member {Class} extends
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, extends : me.extends
/** Id of the class
* @see {@link main.Class.ClassMe.id|ClassMe.id}
* @member {number} id
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, id : me.id
/** Interfaces implemented by the class. Return the value of {@link main.Class.ClassMe.implements}.
* @see {@link main.Class.ClassMe.implements|ClassMe.implements}
* @member {Interface[]} implements
* @memberof main.Class.ClassPrivateEnvironment.$
* @todo This must be a get function that return a copy of the list
*/
, implements : me.implements
/** Determine if the class is an abstract class. Return the value of {@link main.Class.ClassMe.isAbstract}.
* @method isAbstract
* @returns {boolean} true: The class is an abstract class<br>false: The class is not an abstract class
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, isAbstract : fct.isAbstract(me)
/** Determine if the class is an final class. Return the value of {@link main.Class.ClassMe.isFinal}.
* @method isFinal
* @returns {boolean} true: The class is final<br>false: The class is not final
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, isFinal : fct.isFinal(me)
/** Return the list of ancestry classes of the current class
* @method getAncestry
* @returns {Class[]}
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, getAncestry : me.getAncestry
/** Function that create a new instance. In public/protected environment, this function is usable only if the class is publicly instanciable.
* @see {@link main.Class.ClassMe.New}
* @method new
* @returns {Instance}
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, New : me.New
/** Determine if the class is a parent class of the Class.
* @see {@link main.Class.ClassMe.parentOf|ClassMe.parentOf}
* @method parentOf
* @param {Class} Class to test
* @returns {boolean} true: The class is a parent<br>false: The class is not a parent
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, parentOf : me.parentOf
/** Public environment of the class
* @see {@link main.Class.ClassMe.publicEnv|ClassMe.publicEnv}
* @member {Class} Public
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, Public : me.publicEnv
/** Self environment of the class
* @see {@link main.Class.ClassMe.selfEnv|ClassMe.selfEnv}
* @member {Class} Self
* @memberof main.Class.ClassPrivateEnvironment.$
* @access Private
*/
, Self : me.selfEnv
/** Super environment of the class
* @see {@link main.Class.ClassMe.Super|ClassMe.Super}
* @member {Class} Super
* @memberof main.Class.ClassPrivateEnvironment.$
* @access Protected
*/
, Super : me.superEnv
, This : true
/** toString function of the class
* @see {@link main.Class.ClassMe.toString|ClassMe.toString}
* @method {Class} toString
* @returns {string} Representation of the class. The representation depends on the current visibility.
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, toString : fct.ClassToString(me.thisEnv, 'private')
/** Type of the object. Value:CLASS
* @see {@link main.Class.ClassMe.type|ClassMe.type}
* @constant {string} type
* @memberof main.Class.ClassPrivateEnvironment.$
*/
, type : me.type};
/**
* @class
* @name $
* @memberof main.Class.ClassProtectedEnvironment
*/
me.protectedEnv.$ = { /** Internal function used by JsPackage to determine whether or not the object has been created by JsPackage.
* @method _patteBlanche
* @memberof main.Class.ClassProtectedEnvironment.$
*/
_patteBlanche : me._patteBlanche
/** This attribute return the current class, always with the highest visibility level accessible.
* @member {Class} Class
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, Class : me.Class
/** Determine if the current class has instanciate the given parameter object.
* @func classOf
* @param {object} object to test
* @returns {boolean} true: the class is the one who instanciate the object. False otherwise
* @memberof main.Class.ClassProtectedEnvironment.$
* @see {@link main.Class.ClassMe|classOf}
*/
, classOf : me.classOf
/** Definition of the class.
* @see {@link main.Class.ClassMe|definition}
* @member {Definition} definition
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, definition : me.definition.publicEnv
/** Extended Class
* @see {@link main.Class.ClassMe|extends}
* @member {Class} extends
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, extends : me.extends
/** Id of the class
* @see {@link main.Class.ClassMe.id|ClassMe.id}
* @member {number} id
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, id : me.id
/** Determine if the class is an abstract class. Return the value of {@link main.Class.ClassMe.isAbstract}.
* @method isAbstract
* @returns {boolean} true: The class is an abstract class<br>false: The class is not an abstract class
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, implements : me.implements
/** Determine if the class is an final class. Return the value of {@link main.Class.ClassMe.isFinal}.
* @method isFinal
* @returns {boolean} true: The class is final<br>false: The class is not final
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, isAbstract : fct.isAbstract(me)
/** Return the list of ancestry classes of the current class
* @method getAncestry
* @returns {Class[]}
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, isFinal : fct.isFinal(me)
/** Function that create a new instance. In public/protected environment, this function is usable only if the class is publicly instanciable.
* @see {@link main.Class.ClassMe.New}
* @method new
* @returns {Instance}
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, getAncestry : me.getAncestry
/** Function that create a new instance. In public/protected environment, this function is usable only if the class is publicly instanciable.
* @see {@link main.Class.ClassMe.New}
* @method new
* @returns {Instance}
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, New : publicInitialization
/** Determine if the class is a parent class of the Class.
* @see {@link main.Class.ClassMe.parentOf|ClassMe.parentOf}
* @method parentOf
* @param {Class} Class to test
* @returns {boolean} true: The class is a parent<br>false: The class is not a parent
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, parentOf : me.parentOf
/** Public environment of the class
* @see {@link main.Class.ClassPublicEnvironment|ClassMe.publicEnv}
* @member {Class} Public
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, Public : me.publicEnv
/** Super environment of the class
* @see {@link main.Class.ClassMe.ClassSuperEnvironment|ClassMe.Super}
* @member {Class} Super
* @memberof main.Class.ClassProtectedEnvironment.$
* @access Protected
*/
, Super : me.superEnv
, This : false
, toString : fct.ClassToString(me.thisEnv, 'super')
/** Type of the object. Value:CLASS
* @see {@link main.Class.ClassMe.type|ClassMe.type}
* @constant {string} type
* @memberof main.Class.ClassProtectedEnvironment.$
*/
, type : me.type};
me.publicEnv.$ = { _patteBlanche : me._patteBlanche
, _open : fct._ProtectedReturn(me)
, Class : me.Class
, classOf : me.classOf
, definition : me.definition.publicEnv
, extends : me.extends
, id : me.id
, implements : me.implements
, isAbstract : fct.isAbstract(me)
, isFinal : fct.isFinal(me)
, getAncestry : me.getAncestry
, New : publicInitialization
, parentOf : me.parentOf
, Public : me.publicEnv
, toString : fct.ClassToString(me.publicEnv, 'public')
, type : me.type };
me.selfEnv.$ = { _patteBlanche : Core.fct._patteBlanche(me)
, Class : me.thisEnv
, classOf : me.classOf
, definition : me.definition.publicEnv
, extends : me.extends
, id : me.id
, implements : me.implements
, isAbstract : fct.isAbstract(me)
, isFinal : fct.isFinal(me)
, getAncestry : me.getAncestry
, New : fct.getNewObject(me)
, parentOf : me.parentOf
, Public : me.publicEnv
, Super : me.superEnv
, type : me.type
, toString : fct.ClassToString(me.selfEnv, 'self')
, Self : true};
/** Parent of the class.
<p>Once the class created, the parent of the class is not yet fixed : if the parent is a package, then the
package must be sealed. Until the package is unsealed, the parent will be "undefined" : this prevent
any class to declare itself into a package.</p>
<p>Each environment doesn't see the same package environment : {@link main.Class.ClassMe.thisEnv|thisEnv}
and {@link main.Class.ClassMe.selfEnv|selfEnv} see the private environment of the package, other environments
seeing the public environment.</p>
* @see {@link memberof main.Class.ClassPrivateEnvironment.$.name}
* @see {@link main.Class.ClassMe.getPrivateParent|ClassMe.getPrivateParent}
* @see {@link main.Class.ClassMe.getPublicParent|ClassMe.getPublicParent}
* @member {NamespaceLike} parent
* @memberof main.Class.ClassPrivateEnvironment.$
*/
jsObject.defineProperty(me.thisEnv.$ , 'parent', { get : me.getPrivateParent });
jsObject.defineProperty(me.selfEnv.$ , 'parent', { get : me.getPrivateParent });
jsObject.defineProperty(me.publicEnv.$ , 'parent', { get : me.getPublicParent });
jsObject.defineProperty(me.protectedEnv.$, 'parent', { get : me.getPublicParent });
/** <p>Name of the class.</p>
<p>Follow the same rules than {@link memberof main.Class.ClassPrivateEnvironment.$.parent}.
* @see {@link memberof main.Class.ClassPrivateEnvironment.$.parent}
* @see {@link main.Class.ClassMe.getPrivateName|ClassMe.getPrivateName}
* @see {@link main.Class.ClassMe.getPublicName|ClassMe.getPublicName}
* @member {string} name
* @memberof main.Class.ClassPrivateEnvironment.$
*/
jsObject.defineProperty(me.thisEnv.$ , 'name' , { get : me.getPrivateName });
jsObject.defineProperty(me.selfEnv.$ , 'name' , { get : me.getPrivateName });
jsObject.defineProperty(me.publicEnv.$ , 'name' , { get : me.getPublicName });
jsObject.defineProperty(me.protectedEnv.$, 'name' , { get : me.getPublicName });
if (me.definition.initialization !== undefined) {
me.thisEnv.$.New = me.New;
me.selfEnv.$.New = me.selfEnv.$.New;
if (me.definition.initialization.isPublic()) {
me.publicEnv.$.New = me.New;
}
}
else {
me.publicEnv.$.New = me.New;
}
if (me.name !== undefined)
Core.declareToParent(me);
// In debug mode, we add a object in all environment that give access to public, private, self and super environment.
if (debugMode) {
/** Contains all the environments (public, private, self and super) of the class. This member is accessible only in debug mode.
* @member {object} debug
* @memberof main.Class.ClassPrivateEnvironment.$
*/
me.thisEnv.$.debug = { publicEnv : me.publicEnv
, privateEnv : me.thisEnv
, selfEnv : me.selfEnv
, superEnv : openExtend !== undefined ? openExtend.protectedEnv : undefined};
me.publicEnv.$.debug = me.thisEnv.$.debug;
me.selfEnv.$.debug = me.thisEnv.$.debug;
}
// Sealing all the environments
for(env in listProperties) {
Core.sealEnv(listProperties[env].env);
}
return me.publicEnv;
};
/**
* Create a classe using a Definition object receive in parameter.
* The definition must be an open definition.
* @func createObject
* @param {Class} cls Class use to create the object
* @returns {Instance} Instance created
* @memberof main.Class
* @access private
*/
var createObject = function (cls) {
var classMe, listEnv, me, meExtends, name, protectedEnv, publicEnv, selfEnv, superEnv, thisEnv;
classMe = Core.getObject(cls.id);
/**
* {@link main.me|me} object of classes
* @class InstanceMe
* @memberof main.Class
* @access private
*/
me = { /** Class of the instance
* @member {Class} Class
* @memberof main.Class.InstanceMe
*/
Class : classMe.publicEnv
/** classMe of the class instance
* @member {main.Class.ClassMe} classMe
* @memberof main.Class.InstanceMe
*/
, classMe : classMe
/** Definition of the class.
* @see {@link main.Class.ClassMe.definition|ClassMe.definition}
* @member {DefinitionMe} definition
* @memberof main.Class.InstanceMe
*/
, definition : classMe.definition
/** Class extended by the class
* @see {@link main.Class.ClassMe.definition|ClassMe.definition}
* @member {Class} extends
* @memberof main.Class.InstanceMe
*/
, extends : classMe.extends
/** Initialization function of the class
* @see {@link main.Class.ClassMe.initialization|ClassMe.initialization}
* @member {function} initialization
* @memberof main.Class.InstanceMe
*/
, initialization : classMe.initialization
/**
* @member {array} levels
* @memberof main.Class.InstanceMe
*/
, levels : []