@ui5/webcomponents-localization 1.14.6 → 1.14.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/.eslintignore +2 -1
  2. package/CHANGELOG.md +12 -0
  3. package/dist/generated/assets/cldr/ar.json +102 -62
  4. package/dist/generated/assets/cldr/ar_EG.json +102 -62
  5. package/dist/generated/assets/cldr/ar_SA.json +102 -62
  6. package/dist/generated/assets/cldr/bg.json +364 -325
  7. package/dist/generated/assets/cldr/ca.json +491 -453
  8. package/dist/generated/assets/cldr/cs.json +431 -324
  9. package/dist/generated/assets/cldr/cy.json +608 -340
  10. package/dist/generated/assets/cldr/da.json +290 -227
  11. package/dist/generated/assets/cldr/de.json +348 -241
  12. package/dist/generated/assets/cldr/de_AT.json +348 -241
  13. package/dist/generated/assets/cldr/de_CH.json +347 -240
  14. package/dist/generated/assets/cldr/el.json +128 -100
  15. package/dist/generated/assets/cldr/el_CY.json +128 -100
  16. package/dist/generated/assets/cldr/en.json +538 -512
  17. package/dist/generated/assets/cldr/en_AU.json +583 -520
  18. package/dist/generated/assets/cldr/en_GB.json +485 -441
  19. package/dist/generated/assets/cldr/en_HK.json +519 -474
  20. package/dist/generated/assets/cldr/en_IE.json +485 -440
  21. package/dist/generated/assets/cldr/en_IN.json +465 -420
  22. package/dist/generated/assets/cldr/en_NZ.json +505 -460
  23. package/dist/generated/assets/cldr/en_PG.json +505 -460
  24. package/dist/generated/assets/cldr/en_SG.json +505 -460
  25. package/dist/generated/assets/cldr/en_ZA.json +485 -440
  26. package/dist/generated/assets/cldr/es.json +709 -456
  27. package/dist/generated/assets/cldr/es_AR.json +687 -434
  28. package/dist/generated/assets/cldr/es_BO.json +721 -468
  29. package/dist/generated/assets/cldr/es_CL.json +567 -422
  30. package/dist/generated/assets/cldr/es_CO.json +485 -339
  31. package/dist/generated/assets/cldr/es_MX.json +734 -481
  32. package/dist/generated/assets/cldr/es_PE.json +409 -372
  33. package/dist/generated/assets/cldr/es_UY.json +433 -396
  34. package/dist/generated/assets/cldr/es_VE.json +453 -416
  35. package/dist/generated/assets/cldr/et.json +340 -307
  36. package/dist/generated/assets/cldr/fa.json +96 -34
  37. package/dist/generated/assets/cldr/fi.json +359 -308
  38. package/dist/generated/assets/cldr/fr.json +347 -321
  39. package/dist/generated/assets/cldr/fr_BE.json +347 -321
  40. package/dist/generated/assets/cldr/fr_CA.json +458 -432
  41. package/dist/generated/assets/cldr/fr_CH.json +290 -264
  42. package/dist/generated/assets/cldr/fr_LU.json +347 -321
  43. package/dist/generated/assets/cldr/he.json +241 -130
  44. package/dist/generated/assets/cldr/hi.json +103 -53
  45. package/dist/generated/assets/cldr/hr.json +467 -410
  46. package/dist/generated/assets/cldr/hu.json +246 -195
  47. package/dist/generated/assets/cldr/id.json +478 -406
  48. package/dist/generated/assets/cldr/it.json +418 -362
  49. package/dist/generated/assets/cldr/it_CH.json +418 -362
  50. package/dist/generated/assets/cldr/ja.json +58 -18
  51. package/dist/generated/assets/cldr/kk.json +562 -398
  52. package/dist/generated/assets/cldr/ko.json +36 -15
  53. package/dist/generated/assets/cldr/lt.json +320 -231
  54. package/dist/generated/assets/cldr/lv.json +184 -120
  55. package/dist/generated/assets/cldr/ms.json +460 -388
  56. package/dist/generated/assets/cldr/nb.json +160 -92
  57. package/dist/generated/assets/cldr/nl.json +621 -373
  58. package/dist/generated/assets/cldr/nl_BE.json +621 -373
  59. package/dist/generated/assets/cldr/pl.json +590 -279
  60. package/dist/generated/assets/cldr/pt.json +696 -334
  61. package/dist/generated/assets/cldr/pt_PT.json +730 -454
  62. package/dist/generated/assets/cldr/ro.json +409 -339
  63. package/dist/generated/assets/cldr/ru.json +317 -279
  64. package/dist/generated/assets/cldr/ru_UA.json +312 -274
  65. package/dist/generated/assets/cldr/sk.json +454 -413
  66. package/dist/generated/assets/cldr/sl.json +118 -80
  67. package/dist/generated/assets/cldr/sr.json +294 -142
  68. package/dist/generated/assets/cldr/sr_Latn.json +972 -824
  69. package/dist/generated/assets/cldr/sv.json +382 -338
  70. package/dist/generated/assets/cldr/th.json +56 -36
  71. package/dist/generated/assets/cldr/tr.json +371 -320
  72. package/dist/generated/assets/cldr/uk.json +340 -290
  73. package/dist/generated/assets/cldr/vi.json +352 -328
  74. package/dist/generated/assets/cldr/zh_CN.json +34 -10
  75. package/dist/generated/assets/cldr/zh_HK.json +33 -9
  76. package/dist/generated/assets/cldr/zh_SG.json +33 -9
  77. package/dist/generated/assets/cldr/zh_TW.json +32 -8
  78. package/dist/sap/base/Event.js +59 -0
  79. package/dist/sap/base/Eventing.js +147 -0
  80. package/dist/sap/base/Log.js +2 -239
  81. package/dist/sap/base/assert.js +28 -1
  82. package/dist/sap/base/config/MemoryConfigurationProvider.js +20 -0
  83. package/dist/sap/base/config.js +17 -0
  84. package/dist/sap/base/i18n/Formatting.js +1130 -0
  85. package/dist/sap/base/i18n/LanguageTag.js +173 -0
  86. package/dist/sap/base/i18n/Localization.js +721 -0
  87. package/dist/sap/base/i18n/date/CalendarType.js +43 -0
  88. package/dist/sap/base/i18n/date/CalendarWeekNumbering.js +105 -0
  89. package/dist/sap/base/i18n/date/TimezoneUtils.js +319 -0
  90. package/dist/sap/base/strings/camelize.js +30 -0
  91. package/dist/sap/base/strings/formatMessage.js +88 -15
  92. package/dist/sap/base/util/ObjectPath.js +95 -3
  93. package/dist/sap/base/util/Version.js +157 -0
  94. package/dist/sap/base/util/_merge.js +83 -26
  95. package/dist/sap/base/util/array/uniqueSort.js +37 -15
  96. package/dist/sap/base/util/deepClone.js +102 -0
  97. package/dist/sap/base/util/deepEqual.js +75 -51
  98. package/dist/sap/base/util/extend.js +58 -7
  99. package/dist/sap/base/util/isEmptyObject.js +34 -0
  100. package/dist/sap/base/util/isPlainObject.js +35 -1
  101. package/dist/sap/base/util/now.js +24 -3
  102. package/dist/sap/base/util/resolveReference.js +157 -0
  103. package/dist/sap/base/util/uid.js +27 -0
  104. package/dist/sap/ui/base/DataType.js +657 -0
  105. package/dist/sap/ui/base/Interface.js +47 -1
  106. package/dist/sap/ui/base/Metadata.js +436 -171
  107. package/dist/sap/ui/base/Object.js +284 -48
  108. package/dist/sap/ui/core/CalendarType.js +24 -8
  109. package/dist/sap/ui/core/Locale.js +190 -155
  110. package/dist/sap/ui/core/LocaleData.js +2661 -1351
  111. package/dist/sap/ui/core/Supportability.js +5 -0
  112. package/dist/sap/ui/core/Theming.js +539 -0
  113. package/dist/sap/ui/core/date/Buddhist.js +162 -87
  114. package/dist/sap/ui/core/date/CalendarUtils.js +61 -32
  115. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +30 -7
  116. package/dist/sap/ui/core/date/Gregorian.js +25 -10
  117. package/dist/sap/ui/core/date/Islamic.js +298 -185
  118. package/dist/sap/ui/core/date/Japanese.js +210 -115
  119. package/dist/sap/ui/core/date/Persian.js +324 -195
  120. package/dist/sap/ui/core/date/UI5Date.js +923 -237
  121. package/dist/sap/ui/core/date/UniversalDate.js +1238 -256
  122. package/dist/sap/ui/core/date/_Calendars.js +10 -1
  123. package/dist/sap/ui/core/format/DateFormat.js +3174 -2111
  124. package/dist/sap/ui/core/format/TimezoneUtil.js +24 -89
  125. package/package-scripts.cjs +6 -11
  126. package/package.json +9 -5
  127. package/used-modules.txt +24 -1
  128. package/dist/sap/ui/Device.js +0 -5
@@ -1,219 +1,484 @@
1
- import ObjectPath from '../../base/util/ObjectPath.js';
2
- import assert from '../../base/assert.js';
3
- import Log from '../../base/Log.js';
4
- import uniqueSort from '../../base/util/array/uniqueSort.js';
1
+ /*!
2
+ * OpenUI5
3
+ * (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
4
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
5
+ */
6
+ // Provides class sap.ui.base.Metadata
7
+ import ObjectPath from "../../base/util/ObjectPath.js";
8
+ import assert from "../../base/assert.js";
9
+ import Log from "../../base/Log.js";
10
+ import uniqueSort from "../../base/util/array/uniqueSort.js";
11
+ function isFunction(obj) {
12
+ return typeof obj === "function";
13
+ }
14
+
15
+ /**
16
+ * Creates a new metadata object from the given static infos.
17
+ *
18
+ * <b>Note:</b> Throughout this class documentation, the described subclass of Object
19
+ * is referenced as <i>the described class</i>.
20
+ *
21
+ * @param {string} sClassName Fully qualified name of the described class
22
+ * @param {object} oClassInfo Info to construct the class and its metadata from
23
+ * @param {sap.ui.base.Object.MetadataOptions} [oClassInfo.metadata]
24
+ * The metadata object describing the class
25
+ *
26
+ * @class Metadata for a class.
27
+ * @author Frank Weigel
28
+ * @version 1.120.3
29
+ * @since 0.8.6
30
+ * @public
31
+ * @alias sap.ui.base.Metadata
32
+ */
5
33
  var Metadata = function (sClassName, oClassInfo) {
6
- assert(typeof sClassName === 'string' && sClassName, 'Metadata: sClassName must be a non-empty string');
7
- assert(typeof oClassInfo === 'object', 'Metadata: oClassInfo must be empty or an object');
8
- if (!oClassInfo || typeof oClassInfo.metadata !== 'object') {
9
- oClassInfo = {
10
- metadata: oClassInfo || {},
11
- constructor: ObjectPath.get(sClassName)
12
- };
13
- oClassInfo.metadata.__version = 1;
14
- }
15
- oClassInfo.metadata.__version = oClassInfo.metadata.__version || 2;
16
- if (typeof oClassInfo.constructor !== 'function') {
17
- throw Error('constructor for class ' + sClassName + ' must have been declared before creating metadata for it');
18
- }
19
- this._sClassName = sClassName;
20
- this._oClass = oClassInfo.constructor;
21
- this.extend(oClassInfo);
34
+ assert(typeof sClassName === "string" && sClassName, "Metadata: sClassName must be a non-empty string");
35
+ assert(typeof oClassInfo === "object", "Metadata: oClassInfo must be empty or an object");
36
+
37
+ // support for old usage of Metadata
38
+ if (!oClassInfo || typeof oClassInfo.metadata !== "object") {
39
+ oClassInfo = {
40
+ metadata: oClassInfo || {},
41
+ // retrieve class by its name. Using a lookup costs time but avoids the need for redundant arguments to this function
42
+ constructor: ObjectPath.get(sClassName) // legacy-relevant, code path not used by extend call
43
+ };
44
+
45
+ oClassInfo.metadata.__version = 1.0;
46
+ }
47
+ oClassInfo.metadata.__version = oClassInfo.metadata.__version || 2.0;
48
+ if (!isFunction(oClassInfo.constructor)) {
49
+ throw Error("constructor for class " + sClassName + " must have been declared before creating metadata for it");
50
+ }
51
+
52
+ // invariant: oClassInfo exists, oClassInfo.metadata exists, oClassInfo.constructor exists
53
+ this._sClassName = sClassName;
54
+ this._oClass = oClassInfo.constructor;
55
+ this.extend(oClassInfo);
22
56
  };
57
+
58
+ /**
59
+ * @private
60
+ * @final
61
+ */
23
62
  Metadata.prototype.extend = function (oClassInfo) {
24
- this.applySettings(oClassInfo);
25
- this.afterApplySettings();
63
+ this.applySettings(oClassInfo);
64
+ this.afterApplySettings();
26
65
  };
66
+
67
+ /**
68
+ * @private
69
+ * @since 1.3.1
70
+ */
27
71
  Metadata.prototype.applySettings = function (oClassInfo) {
28
- var that = this, oStaticInfo = oClassInfo.metadata, oPrototype;
29
- if (oStaticInfo.baseType) {
30
- var oParentClass = ObjectPath.get(oStaticInfo.baseType);
31
- if (typeof oParentClass !== 'function') {
32
- Log.fatal('base class \'' + oStaticInfo.baseType + '\' does not exist');
33
- }
34
- if (oParentClass.getMetadata) {
35
- this._oParent = oParentClass.getMetadata();
36
- assert(oParentClass === oParentClass.getMetadata().getClass(), 'Metadata: oParentClass must match the class in the parent metadata');
37
- } else {
38
- this._oParent = new Metadata(oStaticInfo.baseType, {});
39
- }
72
+ var that = this,
73
+ oStaticInfo = oClassInfo.metadata,
74
+ oPrototype;
75
+ if (oStaticInfo.baseType) {
76
+ var oParentClass;
77
+ if (isFunction(oStaticInfo.baseType)) {
78
+ oParentClass = oStaticInfo.baseType;
79
+ if (!isFunction(oParentClass.getMetadata)) {
80
+ throw new TypeError("baseType must be a UI5 class with a static getMetadata function");
81
+ }
40
82
  } else {
41
- this._oParent = undefined;
83
+ // lookup base class by its name - same reasoning as above
84
+ oParentClass = ObjectPath.get(oStaticInfo.baseType); // legacy-relevant, code path not used by extend call
85
+ if (!isFunction(oParentClass)) {
86
+ Log.fatal("base class '" + oStaticInfo.baseType + "' does not exist");
87
+ }
42
88
  }
43
- this._bAbstract = !!oStaticInfo['abstract'];
44
- this._bFinal = !!oStaticInfo['final'];
45
- this._sStereotype = oStaticInfo.stereotype || (this._oParent ? this._oParent._sStereotype : 'object');
46
- this._bDeprecated = !!oStaticInfo['deprecated'];
47
- this._aInterfaces = oStaticInfo.interfaces || [];
48
- this._aPublicMethods = oStaticInfo.publicMethods || [];
49
- this._bInterfacesUnique = false;
50
- oPrototype = this._oClass.prototype;
51
- for (var n in oClassInfo) {
52
- if (n !== 'metadata' && n !== 'constructor') {
53
- oPrototype[n] = oClassInfo[n];
54
- if (!n.match(/^_|^on|^init$|^exit$/)) {
55
- that._aPublicMethods.push(n);
56
- }
57
- }
89
+ // link metadata with base metadata
90
+ if (oParentClass.getMetadata) {
91
+ this._oParent = oParentClass.getMetadata();
92
+ assert(oParentClass === oParentClass.getMetadata().getClass(), "Metadata: oParentClass must match the class in the parent metadata");
93
+ } else {
94
+ // fallback, if base class has no metadata - can only happen if baseType is a string
95
+ this._oParent = new Metadata(oStaticInfo.baseType, {});
58
96
  }
97
+ } else {
98
+ this._oParent = undefined;
99
+ }
100
+ this._bAbstract = !!oStaticInfo["abstract"];
101
+ this._bFinal = !!oStaticInfo["final"];
102
+ this._sStereotype = oStaticInfo.stereotype || (this._oParent ? this._oParent._sStereotype : "object");
103
+ this._bDeprecated = !!oStaticInfo["deprecated"];
104
+
105
+ // handle interfaces
106
+ this._aInterfaces = oStaticInfo.interfaces || [];
107
+
108
+ // take over metadata from static info
109
+ this._aPublicMethods = oStaticInfo.publicMethods || [];
110
+
111
+ // interfaces info possibly not unique
112
+ this._bInterfacesUnique = false;
113
+
114
+ // enrich prototype
115
+ oPrototype = this._oClass.prototype;
116
+ for (var n in oClassInfo) {
117
+ if (n !== "metadata" && n !== "constructor") {
118
+ oPrototype[n] = oClassInfo[n];
119
+ if (!n.match(/^_|^on|^init$|^exit$/)) {
120
+ // TODO hard coded knowledge about event handlers ("on") and about init/exit hooks is not nice....
121
+ that._aPublicMethods.push(n);
122
+ }
123
+ }
124
+ }
59
125
  };
126
+
127
+ /**
128
+ * Called after new settings have been applied.
129
+ *
130
+ * Typically, this method is used to do some cleanup (e.g. uniqueness)
131
+ * or to calculate an optimized version of some data.
132
+ * @private
133
+ * @since 1.3.1
134
+ */
60
135
  Metadata.prototype.afterApplySettings = function () {
61
- if (this._oParent) {
62
- this._aAllPublicMethods = this._oParent._aAllPublicMethods.concat(this._aPublicMethods);
63
- this._bInterfacesUnique = false;
64
- } else {
65
- this._aAllPublicMethods = this._aPublicMethods;
66
- }
136
+ // create the flattened "all" view
137
+ if (this._oParent) {
138
+ this._aAllPublicMethods = this._oParent._aAllPublicMethods.concat(this._aPublicMethods);
139
+ this._bInterfacesUnique = false;
140
+ } else {
141
+ this._aAllPublicMethods = this._aPublicMethods;
142
+ }
67
143
  };
144
+
145
+ /**
146
+ * Stereotype of the described class.
147
+ *
148
+ * @experimental might be enhanced to a set of stereotypes
149
+ * @private
150
+ * @ui5-restricted
151
+ */
68
152
  Metadata.prototype.getStereotype = function () {
69
- return this._sStereotype;
153
+ return this._sStereotype;
70
154
  };
155
+
156
+ /**
157
+ * Returns the fully qualified name of the described class
158
+ * @return {string} name of the described class
159
+ * @public
160
+ */
71
161
  Metadata.prototype.getName = function () {
72
- return this._sClassName;
162
+ return this._sClassName;
73
163
  };
164
+
165
+ /**
166
+ * Returns the (constructor of the) described class
167
+ * @return {function(new:sap.ui.base.Object)} class described by this metadata
168
+ * @public
169
+ */
74
170
  Metadata.prototype.getClass = function () {
75
- return this._oClass;
171
+ return this._oClass;
76
172
  };
173
+
174
+ /**
175
+ * Returns the metadata object of the base class of the described class
176
+ * or undefined if the class has no (documented) base class.
177
+ *
178
+ * @return {sap.ui.base.Metadata | undefined} metadata of the base class
179
+ * @public
180
+ */
77
181
  Metadata.prototype.getParent = function () {
78
- return this._oParent;
182
+ return this._oParent;
79
183
  };
184
+
185
+ /**
186
+ * Removes duplicate names in place from the interfaces and public methods members of this metadata object.
187
+ *
188
+ * @private
189
+ */
80
190
  Metadata.prototype._dedupInterfaces = function () {
81
- if (!this._bInterfacesUnique) {
82
- uniqueSort(this._aInterfaces);
83
- uniqueSort(this._aPublicMethods);
84
- uniqueSort(this._aAllPublicMethods);
85
- this._bInterfacesUnique = true;
86
- }
191
+ if (!this._bInterfacesUnique) {
192
+ uniqueSort(this._aInterfaces);
193
+ uniqueSort(this._aPublicMethods);
194
+ uniqueSort(this._aAllPublicMethods);
195
+ this._bInterfacesUnique = true;
196
+ }
87
197
  };
198
+
199
+ /**
200
+ * Returns an array with the names of the public methods declared by the described class, methods of
201
+ * ancestors are not listed.
202
+ *
203
+ * @return {string[]} array with names of public methods declared by the described class
204
+ * @deprecated As of 1.58, this method should not be used for productive code. The accuracy of the returned
205
+ * information highly depends on the concrete class and is not actively monitored. There might be
206
+ * more public methods or some of the returned methods might not really be intended for public use.
207
+ * In general, pure visibility information should not be exposed in runtime metadata but be part of the
208
+ * documentation.
209
+ * Subclasses of <code>sap.ui.base.Object</code> might decide to provide runtime metadata describing
210
+ * their public API, but this then should not be backed by this method.
211
+ * See {@link sap.ui.core.mvc.ControllerMetadata#getAllMethods} for an example.
212
+ * @public
213
+ */
88
214
  Metadata.prototype.getPublicMethods = function () {
89
- this._dedupInterfaces();
90
- return this._aPublicMethods;
215
+ this._dedupInterfaces();
216
+ return this._aPublicMethods;
91
217
  };
218
+
219
+ /**
220
+ * Returns an array with the names of all public methods declared by the described class
221
+ * and all its ancestors classes.
222
+ *
223
+ * @return {string[]} array with names of all public methods provided by the described class and its ancestors
224
+ * @deprecated As of 1.58, this method should not be used for productive code. The accuracy of the returned
225
+ * information highly depends on the concrete class and is not actively monitored. There might be
226
+ * more public methods or some of the returned methods might not really be intended for public use.
227
+ * In general, pure visibility information should not be exposed in runtime metadata but be part of the
228
+ * documentation.
229
+ * Subclasses of <code>sap.ui.base.Object</code> might decide to provide runtime metadata describing
230
+ * their public API, but this then should not be backed by this method.
231
+ * See {@link sap.ui.core.mvc.ControllerMetadata#getAllMethods} for an example.
232
+ * @public
233
+ */
92
234
  Metadata.prototype.getAllPublicMethods = function () {
93
- this._dedupInterfaces();
94
- return this._aAllPublicMethods;
235
+ this._dedupInterfaces();
236
+ return this._aAllPublicMethods;
95
237
  };
238
+
239
+ /**
240
+ * Returns the names of interfaces implemented by the described class.
241
+ * As the representation of interfaces is not clear yet, this method is still private.
242
+ *
243
+ * @return {string} array of names of implemented interfaces
244
+ * @private
245
+ */
96
246
  Metadata.prototype.getInterfaces = function () {
97
- this._dedupInterfaces();
98
- return this._aInterfaces;
247
+ this._dedupInterfaces();
248
+ return this._aInterfaces;
99
249
  };
250
+
251
+ /**
252
+ * Checks whether the described class or one of its ancestor classes implements the given interface.
253
+ *
254
+ * @param {string} sInterface name of the interface to test for (in dot notation)
255
+ * @return {boolean} whether this class implements the interface
256
+ * @public
257
+ */
100
258
  Metadata.prototype.isInstanceOf = function (sInterface) {
101
- if (this._oParent) {
102
- if (this._oParent.isInstanceOf(sInterface)) {
103
- return true;
104
- }
259
+ if (this._oParent) {
260
+ if (this._oParent.isInstanceOf(sInterface)) {
261
+ return true;
105
262
  }
106
- var a = this._aInterfaces;
107
- for (var i = 0, l = a.length; i < l; i++) {
108
- if (a[i] === sInterface) {
109
- return true;
110
- }
263
+ }
264
+ var a = this._aInterfaces;
265
+ for (var i = 0, l = a.length; i < l; i++) {
266
+ // FIXME doesn't handle interface inheritance (requires object representation for interfaces)
267
+ if (a[i] === sInterface) {
268
+ return true;
111
269
  }
112
- return false;
270
+ }
271
+ return false;
113
272
  };
114
- Object.defineProperty(Metadata.prototype, '_mImplementedTypes', {
115
- get: function () {
116
- if (this === Metadata.prototype) {
117
- throw new Error('sap.ui.base.Metadata: The \'_mImplementedTypes\' property must not be accessed on the prototype');
118
- }
119
- var result = Object.create(this._oParent ? this._oParent._mImplementedTypes : null);
120
- result[this._sClassName] = true;
121
- var aInterfaces = this._aInterfaces, i = aInterfaces.length;
122
- while (i-- > 0) {
123
- if (!result[aInterfaces[i]]) {
124
- result[aInterfaces[i]] = true;
125
- }
126
- }
127
- Object.defineProperty(this, '_mImplementedTypes', {
128
- value: Object.freeze(result),
129
- writable: false,
130
- configurable: false
131
- });
132
- return result;
133
- },
134
- configurable: true
273
+
274
+ /*
275
+ * Lazy calculation of the set of implemented types.
276
+ *
277
+ * A calculation function is configured as getter for the <code>_mImplementedTypes</code>
278
+ * on the prototype object. On first call for a metadata instance, it collects
279
+ * the implemented types (classes, interfaces) from the described class and
280
+ * any base classes and writes it to the property <code>_mImplementedTypes</code> of the
281
+ * current instance of metadata. Future read access to the property will immediately
282
+ * return the instance property and not call the calculation function again.
283
+ */
284
+ Object.defineProperty(Metadata.prototype, "_mImplementedTypes", {
285
+ get: function () {
286
+ if (this === Metadata.prototype) {
287
+ throw new Error("sap.ui.base.Metadata: The '_mImplementedTypes' property must not be accessed on the prototype");
288
+ }
289
+
290
+ // create map of types, including inherited types
291
+ // Note: to save processing time and memory, the inherited types are merged via the prototype chain of 'result'
292
+ var result = Object.create(this._oParent ? this._oParent._mImplementedTypes : null);
293
+ /*
294
+ * Flat alternative:
295
+ * var result = Object.create(null);
296
+ * if ( this._oParent ) {
297
+ * Object.assign(result, this._oParent._mImplementedTypes);
298
+ * }
299
+ */
300
+
301
+ // add own class
302
+ result[this._sClassName] = true;
303
+
304
+ // additionally collect interfaces
305
+ var aInterfaces = this._aInterfaces,
306
+ i = aInterfaces.length;
307
+ while (i-- > 0) {
308
+ if (!result[aInterfaces[i]]) {
309
+ // take care to write property only if it hasn't been set already
310
+ result[aInterfaces[i]] = true;
311
+ }
312
+ }
313
+
314
+ // write instance property, hiding the getter on the prototype
315
+ Object.defineProperty(this, "_mImplementedTypes", {
316
+ value: Object.freeze(result),
317
+ writable: false,
318
+ configurable: false
319
+ });
320
+ return result;
321
+ },
322
+ configurable: true
135
323
  });
324
+
325
+ /**
326
+ * Checks whether the class described by this metadata object is of the named type.
327
+ *
328
+ * This check is solely based on the type names as declared in the class metadata.
329
+ * It compares the given <code>vTypeName</code> with the name of this class, with the
330
+ * names of any base class of this class and with the names of all interfaces
331
+ * implemented by any of the aforementioned classes.
332
+ *
333
+ * Instead of a single type name, an array of type names can be given and the method
334
+ * will check if this class is of any of the listed types (logical or).
335
+ *
336
+ * Should the UI5 class system in future implement additional means of associating classes
337
+ * with type names (e.g. by introducing mixins), then this method might detect matches
338
+ * for those names as well.
339
+ *
340
+ * @param {string|string[]} vTypeName Type or types to check for
341
+ * @returns {boolean} Whether this class is of the given type or of any of the given types
342
+ * @public
343
+ * @since 1.56
344
+ */
136
345
  Metadata.prototype.isA = function (vTypeName) {
137
- var mTypes = this._mImplementedTypes;
138
- if (Array.isArray(vTypeName)) {
139
- for (var i = 0; i < vTypeName.length; i++) {
140
- if (vTypeName[i] in mTypes) {
141
- return true;
142
- }
143
- }
144
- return false;
346
+ var mTypes = this._mImplementedTypes;
347
+ if (Array.isArray(vTypeName)) {
348
+ for (var i = 0; i < vTypeName.length; i++) {
349
+ if (vTypeName[i] in mTypes) {
350
+ return true;
351
+ }
145
352
  }
146
- return vTypeName in mTypes;
353
+ return false;
354
+ }
355
+ // Note: the check with 'in' also finds inherited types via the prototype chain of mTypes
356
+ return vTypeName in mTypes;
147
357
  };
358
+
359
+ /**
360
+ * Returns whether the described class is abstract
361
+ * @return {boolean} whether the class is abstract
362
+ * @public
363
+ */
148
364
  Metadata.prototype.isAbstract = function () {
149
- return this._bAbstract;
365
+ return this._bAbstract;
150
366
  };
367
+
368
+ /**
369
+ * Returns whether the described class is final
370
+ * @return {boolean} whether the class is final
371
+ * @public
372
+ */
151
373
  Metadata.prototype.isFinal = function () {
152
- return this._bFinal;
374
+ return this._bFinal;
153
375
  };
376
+
377
+ /**
378
+ * Whether the described class is deprecated and should not be used any more
379
+ *
380
+ * @return {boolean} whether the class is considered deprecated
381
+ * @public
382
+ * @since 1.26.4
383
+ */
154
384
  Metadata.prototype.isDeprecated = function () {
155
- return this._bDeprecated;
385
+ return this._bDeprecated;
156
386
  };
157
- Metadata.prototype.addPublicMethods = function (sMethod) {
158
- var aNames = sMethod instanceof Array ? sMethod : arguments;
159
- Array.prototype.push.apply(this._aPublicMethods, aNames);
160
- Array.prototype.push.apply(this._aAllPublicMethods, aNames);
161
- this._bInterfacesUnique = false;
387
+
388
+ /**
389
+ * Adds one or more new methods to the list of API methods.
390
+ *
391
+ * Can be used by contributer classes (like the EnabledPropagator) to enrich the declared set of methods.
392
+ * The method can either be called with multiple names (strings) or with one array of strings.
393
+ *
394
+ * <b>Note</b>: the newly added method(s) will only be visible in {@link sap.ui.base.Interface interface}
395
+ * objects that are created <i>after</i> this method has been called.
396
+ *
397
+ * @param {string|string[]} sMethod name(s) of the new method(s)
398
+ */
399
+ Metadata.prototype.addPublicMethods = function (sMethod /* ... */) {
400
+ var aNames = sMethod instanceof Array ? sMethod : arguments;
401
+ Array.prototype.push.apply(this._aPublicMethods, aNames);
402
+ Array.prototype.push.apply(this._aAllPublicMethods, aNames);
403
+ this._bInterfacesUnique = false;
162
404
  };
405
+
406
+ /**
407
+ * @since 1.3.1
408
+ * @private
409
+ */
163
410
  Metadata.createClass = function (fnBaseClass, sClassName, oClassInfo, FNMetaImpl) {
164
- if (typeof fnBaseClass === 'string') {
165
- FNMetaImpl = oClassInfo;
166
- oClassInfo = sClassName;
167
- sClassName = fnBaseClass;
168
- fnBaseClass = null;
169
- }
170
- assert(!fnBaseClass || typeof fnBaseClass === 'function');
171
- assert(typeof sClassName === 'string' && !!sClassName);
172
- assert(!oClassInfo || typeof oClassInfo === 'object');
173
- assert(!FNMetaImpl || typeof FNMetaImpl === 'function');
174
- FNMetaImpl = FNMetaImpl || Metadata;
175
- if (typeof FNMetaImpl.preprocessClassInfo === 'function') {
176
- oClassInfo = FNMetaImpl.preprocessClassInfo(oClassInfo);
177
- }
178
- oClassInfo = oClassInfo || {};
179
- oClassInfo.metadata = oClassInfo.metadata || {};
180
- if (!oClassInfo.hasOwnProperty('constructor')) {
181
- oClassInfo.constructor = undefined;
182
- }
183
- var fnClass = oClassInfo.constructor;
184
- assert(!fnClass || typeof fnClass === 'function');
185
- if (fnBaseClass) {
186
- if (!fnClass) {
187
- if (oClassInfo.metadata.deprecated) {
188
- fnClass = function () {
189
- Log.warning('Usage of deprecated class: ' + sClassName);
190
- fnBaseClass.apply(this, arguments);
191
- };
192
- } else {
193
- fnClass = function () {
194
- fnBaseClass.apply(this, arguments);
195
- };
196
- }
197
- }
198
- fnClass.prototype = Object.create(fnBaseClass.prototype);
199
- fnClass.prototype.constructor = fnClass;
200
- oClassInfo.metadata.baseType = fnBaseClass.getMetadata().getName();
201
- } else {
202
- fnClass = fnClass || function () {
411
+ if (typeof fnBaseClass === "string") {
412
+ FNMetaImpl = oClassInfo;
413
+ oClassInfo = sClassName;
414
+ sClassName = fnBaseClass;
415
+ fnBaseClass = null;
416
+ }
417
+ assert(!fnBaseClass || isFunction(fnBaseClass));
418
+ assert(typeof sClassName === "string" && !!sClassName);
419
+ assert(!oClassInfo || typeof oClassInfo === "object");
420
+ assert(!FNMetaImpl || isFunction(FNMetaImpl));
421
+
422
+ // allow metadata class to preprocess
423
+ FNMetaImpl = FNMetaImpl || Metadata;
424
+ if (isFunction(FNMetaImpl.preprocessClassInfo)) {
425
+ oClassInfo = FNMetaImpl.preprocessClassInfo(oClassInfo);
426
+ }
427
+
428
+ // normalize oClassInfo
429
+ oClassInfo = oClassInfo || {};
430
+ oClassInfo.metadata = oClassInfo.metadata || {};
431
+ if (!oClassInfo.hasOwnProperty('constructor')) {
432
+ oClassInfo.constructor = undefined;
433
+ }
434
+ var fnClass = oClassInfo.constructor;
435
+ assert(!fnClass || isFunction(fnClass));
436
+
437
+ // ensure defaults
438
+ if (fnBaseClass) {
439
+ // default constructor just delegates to base class
440
+ if (!fnClass) {
441
+ if (oClassInfo.metadata.deprecated) {
442
+ // create default factory with deprecation warning
443
+ fnClass = function () {
444
+ Log.warning("Usage of deprecated class: " + sClassName);
445
+ fnBaseClass.apply(this, arguments);
203
446
  };
204
- delete oClassInfo.metadata.baseType;
205
- }
206
- oClassInfo.constructor = fnClass;
207
- ObjectPath.set(sClassName, fnClass);
208
- var oMetadata = new FNMetaImpl(sClassName, oClassInfo);
209
- fnClass.getMetadata = fnClass.prototype.getMetadata = function () {
210
- return oMetadata;
211
- };
212
- if (!fnClass.getMetadata().isFinal()) {
213
- fnClass.extend = function (sSCName, oSCClassInfo, fnSCMetaImpl) {
214
- return Metadata.createClass(fnClass, sSCName, oSCClassInfo, fnSCMetaImpl || FNMetaImpl);
447
+ } else {
448
+ // create default factory
449
+ fnClass = function () {
450
+ fnBaseClass.apply(this, arguments);
215
451
  };
452
+ }
216
453
  }
217
- return fnClass;
454
+ // create prototype chain
455
+ fnClass.prototype = Object.create(fnBaseClass.prototype);
456
+ fnClass.prototype.constructor = fnClass;
457
+ // enforce correct baseType
458
+ oClassInfo.metadata.baseType = fnBaseClass;
459
+ } else {
460
+ // default constructor does nothing
461
+ fnClass = fnClass || function () {};
462
+ // enforce correct baseType
463
+ delete oClassInfo.metadata.baseType;
464
+ }
465
+ oClassInfo.constructor = fnClass;
466
+
467
+ // make the class visible as JS Object
468
+ ObjectPath.set(sClassName, fnClass);
469
+
470
+ // add metadata
471
+ var oMetadata = new FNMetaImpl(sClassName, oClassInfo);
472
+ fnClass.getMetadata = fnClass.prototype.getMetadata = function () {
473
+ return oMetadata;
474
+ };
475
+
476
+ // enrich function
477
+ if (!fnClass.getMetadata().isFinal()) {
478
+ fnClass.extend = function (sSCName, oSCClassInfo, fnSCMetaImpl) {
479
+ return Metadata.createClass(fnClass, sSCName, oSCClassInfo, fnSCMetaImpl || FNMetaImpl);
480
+ };
481
+ }
482
+ return fnClass;
218
483
  };
219
484
  export default Metadata;