/
plugin.js
2407 lines (2139 loc) · 80.7 KB
/
plugin.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
/*
* JSDoc3 plugin for UI5 documentation generation.
*
* (c) Copyright 2009-2018 SAP SE or an SAP affiliate company.
* Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
*/
/* global require, exports, env */
/* eslint strict: [2, "global"]*/
'use strict';
/**
* UI5 plugin for JSDoc3 (3.3.0-alpha5)
*
* The plugin adds the following SAPUI5 specific tag definitions to JSDoc3
*
* disclaimer
*
* experimental
*
* final
*
* interface
*
* implements
*
* slot
*
* appenddocs
*
* customtag
*
* It furthermore listens to the following JSDoc3 events to implement additional functionality
*
* parseBegin
* to create short names for all file that are to be parsed
*
* fileBegin
* to write some line to the log (kind of a progress indicator)
*
* jsdocCommentFound
* to pre-process comments, empty lines are used as paragraph markers
* a default visibility is added, legacy tag combinations used in JSdoc2 are converted to JSDoc3 conventions
*
* newDoclet
*
* parseComplete
* remove undocumented/ignored/private doclets or duplicate doclets
*
*
* Last but not least, it implements an astNodeVisitor to detect UI5 specific "extend" calls and to create
* documentation for the properties, aggregations etc. that are created with the "extend" call.
*
* @module plugins/sapui5-jsdoc
*/
/* imports */
var Syntax = require('jsdoc/src/syntax').Syntax;
var Doclet = require('jsdoc/doclet').Doclet;
var fs = require('jsdoc/fs');
var path = require('jsdoc/path');
var pluginConfig = (env.conf && env.conf.templates && env.conf.templates.ui5) || {};
/* ---- global vars---- */
/**
* Potential path prefixes.
*
* Will be determined in the handler for the parseBegin event
*/
var pathPrefixes = [];
/**
* Prefixes of the UI5 unified resource name for the source files is NOT part of the file name.
* (e.g. when a common root namespaces has been omitted from the folder structure).
*
* The prefix will be prepended to all resource names.
*/
var resourceNamePrefixes = [];
/**
* A UI5 specific unique Id for all doclets.
*/
var docletUid = 0;
var currentProgram;
/**
* Information about the current module.
*
* The info object is created in the 'fileBegin' event handler and the 'resource' and 'module' properties
* are derived from the filename provided by the event. The derived information is only correct, when the
* resource name prefix is known for the directory from which a source is loaded (prefixes can be configured
* via sapui5.resourceNamePrefixes, for UI5 libraries it is empty by default).
*
* During AST visiting, the 'name' property and the 'localeNames' map will be filled.
* 'name' will be the name of the class defined by the module (assuming that there is only one).
* 'localNames' will contain information objects for each parameter of an AMD Factory function and for
* all shortcut variables that are defined top-level in the module factory function (e.g. something like
* var ButtonDesign = coreLibrary.ButtonDesign; ).
* An info object for a local name either can have a 'value' property (simple, constant value) or it can
* have a 'module' and optionally a 'path' value. In that case, the local name represents an AMD
* module import or a shortcut derived from such an import.
*
* See {@link getREsolvedObjectName} how the knowledge about locale names is used.
*
* @type {{name:string,resource:string,module:string,localName:Object<string,object>}}
*/
var currentModule;
var currentSource;
/**
* Cached UI5 metadata for encountered UI5 classes.
*
* The metadata is collected from the 'metadata' property of 'extend' calls. It is stored
* in this map keyed by the name of the class (as defined in the first parameter of the extend call).
* Only after all files have been parsed, the collected information can be associated with the
* corresponding JSDoc doclet (e.g. with the class documentation).
*/
var classInfos = Object.create(null);
/**
*
*/
var typeInfos = Object.create(null);
/**
* Cached designtime info for encountered sources.
*
* The designtime information is collected only for files named '*.designtime.js'.
* It is stored in this map keyed by the corresponding module name (e.g. 'sap/m/designtime/Button.designtime').
* Only after all files have been parsed, the collected information can be associated with runtime metadata
* that refers to that designtime module name.
*/
var designtimeInfos = Object.create(null);
/* ---- private functions ---- */
function ui5data(doclet) {
return doclet.__ui5 || (doclet.__ui5 = { id: ++docletUid });
}
var pendingMessageHeader;
function msgHeader(str) {
pendingMessageHeader = str;
}
function debug() {
if ( env.opts.debug ) {
console.log.apply(console, arguments);
}
}
function info() {
if ( env.opts.verbose || env.opts.debug ) {
if ( pendingMessageHeader ) {
console.log("");
pendingMessageHeader = null;
}
console.log.apply(console, arguments);
}
}
function warning(msg) {
if ( pendingMessageHeader ) {
if ( !env.opts.verbose && !env.opts.debug ) {
console.log(pendingMessageHeader);
} else {
console.log("");
}
pendingMessageHeader = null;
}
var args = Array.prototype.slice.apply(arguments);
// args[0] = "**** warning: " + args[0]; // TODO: fix warnings. For the moment disable them
console.log.apply(console, args);
}
function error(msg) {
if ( pendingMessageHeader && !env.opts.verbose && !env.opts.debug ) {
if ( !env.opts.verbose && !env.opts.debug ) {
console.log(pendingMessageHeader);
} else {
console.log("");
}
pendingMessageHeader = null;
}
var args = Array.prototype.slice.apply(arguments);
args[0] = "**** error: " + args[0];
// console.log.apply(console, args); // TODO: fix warnings. For the moment disable them
}
//---- path handling ---------------------------------------------------------
function ensureEndingSlash(path) {
path = path || '';
return path && path.slice(-1) !== '/' ? path + '/' : path;
}
function getRelativePath(filename) {
var relative = path.resolve(filename);
for ( var i = 0; i < pathPrefixes.length; i++ ) {
if ( relative.indexOf(pathPrefixes[i]) === 0 ) {
relative = relative.slice(pathPrefixes[i].length);
break;
}
}
return relative.replace(/\\/g, '/');
}
function getResourceName(filename) {
var resource = path.resolve(filename);
for ( var i = 0; i < pathPrefixes.length; i++ ) {
if ( resource.indexOf(pathPrefixes[i]) === 0 ) {
resource = resourceNamePrefixes[i] + resource.slice(pathPrefixes[i].length);
break;
}
}
return resource.replace(/\\/g, '/');
}
function getModuleName(resource) {
return resource.replace(/\.js$/,'');
}
/*
* resolves relative AMD module identifiers relative to a given base name
*/
function resolveModuleName(base, name) {
var stack = base.split('/');
stack.pop();
name.split('/').forEach(function(segment, i) {
if ( segment == '..' ) {
stack.pop();
} else if ( segment === '.' ) {
// ignore
} else {
if ( i === 0 ) {
stack = [];
}
stack.push(segment);
}
});
return stack.join('/');
}
// ---- AMD handling
function analyzeModuleDefinition(node) {
var args = node.arguments;
var arg = 0;
if ( arg < args.length
&& args[arg].type === Syntax.Literal && typeof args[arg].value === 'string' ) {
warning("module explicitly defined a module name '" + args[arg].value + "'");
currentModule.name = args[arg].value;
arg++;
}
if ( arg < args.length && args[arg].type === Syntax.ArrayExpression ) {
currentModule.dependencies = convertValue(args[arg], "string[]");
arg++;
}
if ( arg < args.length && args[arg].type === Syntax.FunctionExpression ) {
currentModule.factory = args[arg];
arg++;
}
if ( currentModule.dependencies && currentModule.factory ) {
for ( var i = 0; i < currentModule.dependencies.length && i < currentModule.factory.params.length; i++ ) {
var name = currentModule.factory.params[i].name;
var module = resolveModuleName(currentModule.module, currentModule.dependencies[i]);
debug(" import " + name + " from '" + module + "'");
currentModule.localNames[name] = {
module: module
// no (or empty) path
};
}
}
if ( currentModule.factory ) {
collectShortcuts(currentModule.factory.body);
}
}
/**
* Searches the given body for variable declarations that can be evaluated statically,
* either because they refer to known AMD modukle imports (e.g. shortcut varialbes)
* or because they have a (design time) constant value.
*
* @param {ASTNode} body
*/
function collectShortcuts(body) {
function checkAssignment(name, valueNode) {
if ( valueNode.type === Syntax.Literal ) {
currentModule.localNames[name] = {
value: valueNode.value
};
debug("compile time constant found ", name, valueNode.value);
} else if ( valueNode.type === Syntax.MemberExpression ) {
var _import = getLeftmostName(valueNode);
var local = _import && currentModule.localNames[_import];
if ( typeof local === 'object' && local.module ) {
currentModule.localNames[name] = {
module: local.module,
path: getObjectName(valueNode).split('.').slice(1).join('.') // TODO chaining if local has path
};
debug(" found local shortcut: ", name, currentModule.localNames[name]);
}
} else if ( isRequireSyncCall(valueNode) || isProbingRequireCall(valueNode) ) {
if ( valueNode.arguments[0]
&& valueNode.arguments[0].type === Syntax.Literal
&& typeof valueNode.arguments[0].value === 'string' ) {
currentModule.localNames[name] = {
module: valueNode.arguments[0].value
// no (or empty) path
};
debug(" found local import: %s = %s('%s')", name, valueNode.callee.property.name, valueNode.arguments[0].value);
}
} else if ( isExtendCall(valueNode) ) {
currentModule.localNames[name] = {
class: valueNode.arguments[0].value
// no (or empty) path
};
debug(" found local class definition: %s = .extend('%s', ...)", name, valueNode.arguments[0].value);
}
}
if ( body.type === Syntax.BlockStatement ) {
body.body.forEach(function ( stmt ) {
// console.log(stmt);
if ( stmt.type === Syntax.VariableDeclaration ) {
stmt.declarations.forEach(function(decl) {
if ( decl.init ) {
checkAssignment(decl.id.name, decl.init);
}
})
} else if ( stmt.type === Syntax.ExpressionStatement
&& stmt.expression.type === Syntax.AssignmentExpression
&& stmt.expression.left.type === Syntax.Identifier ) {
checkAssignment(stmt.expression.left.name, stmt.expression.right);
}
});
}
}
// ---- text handling ---------------------------------------------------------
var rPlural = /(children|ies|ves|oes|ses|ches|shes|xes|s)$/i;
var mSingular = {'children' : -3, 'ies' : 'y', 'ves' : 'f', 'oes' : -2, 'ses' : -2, 'ches' : -2, 'shes' : -2, 'xes' : -2, 's' : -1 };
function guessSingularName(sPluralName) {
return sPluralName.replace(rPlural, function($,sPlural) {
var vRepl = mSingular[sPlural.toLowerCase()];
return typeof vRepl === "string" ? vRepl : sPlural.slice(0,vRepl);
});
}
/**
* Creates a map of property values from an AST 'object literal' node.
*
* The values in the map are again AST 'property' nodes (representing key/value pairs).
* It would be more convenient to just return the values, but the property node is needed
* to find the corresponding (preceding) documentation comment.
*
* @param node
* @param defaultKey
* @returns {Map<string,Property>}
*/
function createPropertyMap(node, defaultKey) {
var result;
if ( node != null ) {
// if, instead of an object literal only a literal is given and there is a defaultKey, then wrap the literal in a map
if ( node.type === Syntax.Literal && defaultKey != null ) {
result = {};
result[defaultKey] = { type: Syntax.Property, value: node };
return result;
}
if ( node.type != Syntax.ObjectExpression ) {
// something went wrong, it's not an object literal
error("not an object literal:" + node.type + ":" + node.value);
// console.log(node.toSource());
return undefined;
}
// invariant: node.type == Syntax.ObjectExpression
result = {};
for (var i = 0; i < node.properties.length; i++) {
var prop = node.properties[i];
var name;
//console.log("objectproperty " + prop.type);
if ( prop.key.type === Syntax.Identifier ) {
name = prop.key.name;
} else if ( prop.key.type === Syntax.Literal ) {
name = String(prop.key.value);
} else {
name = prop.key.toSource();
}
//console.log("objectproperty " + prop.type + ":" + name);
result[name] = prop;
}
}
return result;
}
function isExtendCall(node) {
return (
node
&& node.type === Syntax.CallExpression
&& node.callee.type === Syntax.MemberExpression
&& node.callee.property.type === Syntax.Identifier
&& node.callee.property.name === 'extend'
&& node.arguments.length >= 2
&& node.arguments[0].type === Syntax.Literal
&& typeof node.arguments[0].value === "string"
&& node.arguments[1].type === Syntax.ObjectExpression
);
}
function isSapUiDefineCall(node) {
return (
node
&& node.type === Syntax.CallExpression
&& node.callee.type === Syntax.MemberExpression
&& node.callee.object.type === Syntax.MemberExpression
&& node.callee.object.object.type === Syntax.Identifier
&& node.callee.object.object.name === 'sap'
&& node.callee.object.property.type === Syntax.Identifier
&& node.callee.object.property.name === 'ui'
&& node.callee.property.type === Syntax.Identifier
&& node.callee.property.name === 'define'
);
}
function isCreateDataTypeCall(node) {
return (
node
&& node.type === Syntax.CallExpression
&& node.callee.type === Syntax.MemberExpression
&& /^(sap\.ui\.base\.)?DataType$/.test(getObjectName(node.callee.object))
&& node.callee.property.type === Syntax.Identifier
&& node.callee.property.name === 'createType'
);
}
function isRequireSyncCall(node) {
return (
node
&& node.type === Syntax.CallExpression
&& node.callee.type === Syntax.MemberExpression
&& node.callee.object.type === Syntax.MemberExpression
&& node.callee.object.object.type === Syntax.Identifier
&& node.callee.object.object.name === 'sap'
&& node.callee.object.property.type === Syntax.Identifier
&& node.callee.object.property.name === 'ui'
&& node.callee.property.type === Syntax.Identifier
&& node.callee.property.name === 'requireSync'
);
}
function isProbingRequireCall(node) {
return (
node
&& node.type === Syntax.CallExpression
&& node.callee.type === Syntax.MemberExpression
&& node.callee.object.type === Syntax.MemberExpression
&& node.callee.object.object.type === Syntax.Identifier
&& node.callee.object.object.name === 'sap'
&& node.callee.object.property.type === Syntax.Identifier
&& node.callee.object.property.name === 'ui'
&& node.callee.property.type === Syntax.Identifier
&& node.callee.property.name === 'require'
&& node.arguments.length === 1
&& node.arguments[0].type === Syntax.Literal
&& typeof node.arguments[0].value === 'string' // TODO generalize to statically analyzable constants
);
}
function getObjectName(node) {
if ( node.type === Syntax.MemberExpression && !node.computed && node.property.type === Syntax.Identifier ) {
var prefix = getObjectName(node.object);
return prefix ? prefix + "." + node.property.name : null;
} else if ( node.type === Syntax.Identifier ) {
return /* scope[node.name] ? scope[node.name] : */ node.name;
} else {
return null;
}
}
/*
* Checks whether the node is a qualified name (a.b.c) and if so,
* returns the leftmost identifier a
*/
function getLeftmostName(node) {
while ( node.type === Syntax.MemberExpression ) {
node = node.object;
}
if ( node.type === Syntax.Identifier ) {
return node.name;
}
// return undefined;
}
function getResolvedObjectName(node) {
var name = getObjectName(node);
var _import = getLeftmostName(node);
var local = _import && currentModule.localNames[_import];
if ( local && (local.class || local.module) ) {
var resolvedName;
if ( local.class ) {
resolvedName = local.class;
} else {
resolvedName = local.module.replace(/\//g, ".").replace(/\.library$/, "");
if ( local.path ) {
resolvedName = resolvedName + "." + local.path;
}
}
if ( name.indexOf('.') > 0 ) {
resolvedName = resolvedName + name.slice(name.indexOf('.'));
}
debug("resolved " + name + " to " + resolvedName);
return resolvedName;
}
return name;
}
function convertValue(node, type, propertyName) {
var value;
if ( node.type === Syntax.Literal ) {
// 'string' or number or true or false
return node.value;
} else if ( node.type === Syntax.UnaryExpression
&& node.prefix
&& node.argument.type === Syntax.Literal
&& typeof node.argument.value === 'number'
&& ( node.operator === '-' || node.operator === '+' )) {
// -n or +n
value = node.argument.value;
return node.operator === '-' ? -value : value;
} else if ( node.type === Syntax.MemberExpression && type ) {
// enum value (a.b.c)
value = getResolvedObjectName(node);
if ( value.indexOf(type + ".") === 0 ) {
// starts with fully qualified enum name -> cut off name
return value.slice(type.length + 1);
// } else if ( value.indexOf(type.split(".").slice(-1)[0] + ".") === 0 ) {
// // unqualified name might be a local name (just a guess - would need static code analysis for proper solution)
// return value.slice(type.split(".").slice(-1)[0].length + 1);
} else {
warning("did not understand default value '%s'%s, falling back to source", value, propertyName ? " of property '" + propertyName + "'" : "");
return value;
}
} else if ( node.type === Syntax.Identifier ) {
if ( node.name === 'undefined') {
// undefined
return undefined;
}
var local = currentModule.localNames[node.name];
if ( typeof local === 'object' && 'value' in local ) {
// TODO check type
return local.value;
}
} else if ( node.type === Syntax.ArrayExpression ) {
if ( node.elements.length === 0 ) {
// empty array literal
return "[]"; // TODO return this string or an empty array
}
if ( type && type.slice(-2) === "[]" ) {
var componentType = type.slice(0,-2);
return node.elements.map( function(elem) {
return convertValue(elem, componentType, propertyName);
});
}
} else if ( node.type === Syntax.ObjectExpression ) {
if ( node.properties.length === 0 && (type === 'object' || type === 'any') ) {
return {};
}
}
value = '???';
if ( currentSource && node.range ) {
value = currentSource.slice( node.range[0], node.range[1] );
}
error("unexpected type of default value (type='%s', source='%s')%s, falling back to '%s'", node.type, node.toString(), propertyName ? " of property '" + propertyName + "'" : "", value);
return value;
}
function convertStringArray(node) {
if ( node.type !== Syntax.ArrayExpression ) {
throw new Error("not an array");
}
var result = [];
for ( var i = 0; i < node.elements.length; i++ ) {
if ( node.elements[i].type !== Syntax.Literal || typeof node.elements[i].value !== 'string' ) {
throw new Error("not a string literal");
}
result.push(node.elements[i].value);
}
// console.log(result);
return result;
}
function convertDragDropValue(node, cardinality) {
var mDragDropValue;
var mDefaults = { draggable : false, droppable: false };
if ( node.type === Syntax.ObjectExpression ) {
mDragDropValue = (node.properties || []).reduce(function(oObject, oProperty) {
var sKey = convertValue(oProperty.key);
if (mDefaults.hasOwnProperty(sKey)) {
oObject[sKey] = convertValue(oProperty.value);
}
return oObject;
}, {});
} else if ( node.type === Syntax.Literal ) {
mDragDropValue = {
draggable : node.value,
droppable : node.value
};
} else {
throw new Error("not a valid dnd node");
}
return Object.assign(mDefaults, mDragDropValue);
}
function collectClassInfo(extendCall, classDoclet) {
var baseType;
if ( classDoclet && classDoclet.augments && classDoclet.augments.length === 1 ) {
baseType = classDoclet.augments[0];
}
if ( extendCall.callee.type === Syntax.MemberExpression ) {
var baseCandidate = getResolvedObjectName(extendCall.callee.object);
if ( baseCandidate && baseType == null ) {
baseType = baseCandidate;
} else if ( baseCandidate !== baseType ) {
error("documented base type '" + baseType + "' doesn't match technical base type '" + baseCandidate + "'");
}
}
var oClassInfo = {
name : extendCall.arguments[0].value,
baseType : baseType,
interfaces : [],
doc : classDoclet && classDoclet.description,
deprecation : classDoclet && classDoclet.deprecated,
since : classDoclet && classDoclet.since,
experimental : classDoclet && classDoclet.experimental,
specialSettings : {},
properties : {},
aggregations : {},
associations : {},
events : {},
methods : {},
annotations : {},
designtime: false
};
function upper(n) {
return n.slice(0,1).toUpperCase() + n.slice(1);
}
function each(node, defaultKey, callback) {
var map,n,settings,doclet;
map = node && createPropertyMap(node.value);
if ( map ) {
for (n in map ) {
if ( map.hasOwnProperty(n) ) {
doclet = getLeadingDoclet(map[n]);
settings = createPropertyMap(map[n].value, defaultKey);
if ( settings == null ) {
error("no valid metadata for " + n + " (AST type '" + map[n].value.type + "')");
continue;
}
callback(n, settings, doclet, map[n]);
}
}
}
}
var classInfoNode = extendCall.arguments[1];
var classInfoMap = createPropertyMap(classInfoNode);
if ( classInfoMap && classInfoMap.metadata && classInfoMap.metadata.value.type !== Syntax.ObjectExpression ) {
warning("class metadata exists but can't be analyzed. It is not of type 'ObjectExpression', but a '" + classInfoMap.metadata.value.type + "'.");
return null;
}
var metadata = classInfoMap && classInfoMap.metadata && createPropertyMap(classInfoMap.metadata.value);
if ( metadata ) {
debug(" analyzing metadata for '" + oClassInfo.name + "'");
oClassInfo["abstract"] = !!(metadata["abstract"] && metadata["abstract"].value.value);
oClassInfo["final"] = !!(metadata["final"] && metadata["final"].value.value);
oClassInfo.dnd = metadata.dnd && convertDragDropValue(metadata.dnd.value);
if ( metadata.interfaces ) {
oClassInfo.interfaces = convertStringArray(metadata.interfaces.value);
}
each(metadata.specialSettings, "type", function(n, settings, doclet) {
oClassInfo.specialSettings[n] = {
name : n,
doc : doclet && doclet.description,
since : doclet && doclet.since,
deprecation : doclet && doclet.deprecated,
experimental : doclet && doclet.experimental,
visibility : (settings.visibility && settings.visibility.value.value) || "public",
type : settings.type ? settings.type.value.value : "any"
};
});
oClassInfo.defaultProperty = (metadata.defaultProperty && metadata.defaultProperty.value.value) || undefined;
each(metadata.properties, "type", function(n, settings, doclet) {
var type;
var N = upper(n);
var methods;
oClassInfo.properties[n] = {
name : n,
doc : doclet && doclet.description,
since : doclet && doclet.since,
deprecation : doclet && doclet.deprecated,
experimental : doclet && doclet.experimental,
readonly : doclet && doclet.readonly,
visibility : (settings.visibility && settings.visibility.value.value) || "public",
type : (type = settings.type ? settings.type.value.value : "string"),
defaultValue : settings.defaultValue ? convertValue(settings.defaultValue.value, type, n) : null,
group : settings.group ? settings.group.value.value : 'Misc',
bindable : settings.bindable ? !!convertValue(settings.bindable.value) : false,
methods: (methods = {
"get": "get" + N,
"set": "set" + N
})
};
if ( oClassInfo.properties[n].bindable ) {
methods["bind"] = "bind" + N;
methods["unbind"] = "unbind" + N;
}
// if ( !settings.defaultValue ) {
// console.log("property without defaultValue: " + oClassInfo.name + "." + n);
//}
if ( oClassInfo.properties[n].visibility !== 'public' ) {
error("Property '" + n + "' uses visibility '" + oClassInfo.properties[n].visibility + "' which is not supported by the runtime");
}
});
oClassInfo.defaultAggregation = (metadata.defaultAggregation && metadata.defaultAggregation.value.value) || undefined;
each(metadata.aggregations, "type", function(n, settings, doclet) {
var N = upper(n);
var methods;
var aggr = oClassInfo.aggregations[n] = {
name: n,
doc : doclet && doclet.description,
deprecation : doclet && doclet.deprecated,
since : doclet && doclet.since,
experimental : doclet && doclet.experimental,
visibility : (settings.visibility && settings.visibility.value.value) || "public",
type : settings.type ? settings.type.value.value : "sap.ui.core.Control",
altTypes: settings.altTypes ? convertStringArray(settings.altTypes.value) : undefined,
singularName : settings.singularName ? settings.singularName.value.value : guessSingularName(n),
cardinality : (settings.multiple && !settings.multiple.value.value) ? "0..1" : "0..n",
bindable : settings.bindable ? !!convertValue(settings.bindable.value) : false,
methods: (methods = {
"get": "get" + N,
"destroy": "destroy" + N
})
};
aggr.dnd = settings.dnd && convertDragDropValue(settings.dnd.value, aggr.cardinality);
if ( aggr.cardinality === "0..1" ) {
methods["set"] = "set" + N;
} else {
var N1 = upper(aggr.singularName);
methods["insert"] = "insert" + N1;
methods["add"] = "add" + N1;
methods["remove"] = "remove" + N1;
methods["indexOf"] = "indexOf" + N1;
methods["removeAll"] = "removeAll" + N;
}
if ( aggr.bindable ) {
methods["bind"] = "bind" + N;
methods["unbind"] = "unbind" + N;
}
});
each(metadata.associations, "type", function(n, settings, doclet) {
var N = upper(n);
var methods;
oClassInfo.associations[n] = {
name: n,
doc : doclet && doclet.description,
deprecation : doclet && doclet.deprecated,
since : doclet && doclet.since,
experimental : doclet && doclet.experimental,
visibility : (settings.visibility && settings.visibility.value.value) || "public",
type : settings.type ? settings.type.value.value : "sap.ui.core.Control",
singularName : settings.singularName ? settings.singularName.value.value : guessSingularName(n),
cardinality : (settings.multiple && settings.multiple.value.value) ? "0..n" : "0..1",
methods: (methods = {
"get": "get" + N
})
};
if ( oClassInfo.associations[n].cardinality === "0..1" ) {
methods["set"] = "set" + N;
} else {
var N1 = upper(oClassInfo.associations[n].singularName);
methods["add"] = "add" + N1;
methods["remove"] = "remove" + N1;
methods["removeAll"] = "removeAll" + N;
}
if ( oClassInfo.associations[n].visibility !== 'public' ) {
error("Association '" + n + "' uses visibility '" + oClassInfo.associations[n].visibility + "' which is not supported by the runtime");
}
});
each(metadata.events, null, function(n, settings, doclet) {
var N = upper(n);
var info = oClassInfo.events[n] = {
name: n,
doc : doclet && doclet.description,
deprecation : doclet && doclet.deprecated,
since : doclet && doclet.since,
experimental : doclet && doclet.experimental,
visibility : /* (settings.visibility && settings.visibility.value.value) || */ "public",
allowPreventDefault : !!(settings.allowPreventDefault && settings.allowPreventDefault.value.value),
parameters : {},
methods: {
"attach": "attach" + N,
"detach": "detach" + N,
"fire": "fire" + N
}
};
each(settings.parameters, "type", function(pName, pSettings, pDoclet) {
info.parameters[pName] = {
name : pName,
doc : pDoclet && pDoclet.description,
deprecation : pDoclet && pDoclet.deprecated,
since : pDoclet && pDoclet.since,
experimental : pDoclet && pDoclet.experimental,
type : pSettings && pSettings.type ? pSettings.type.value.value : ""
};
});
});
var designtime = (metadata.designtime && convertValue(metadata.designtime.value)) || (metadata.designTime && convertValue(metadata.designTime.value));
if ( typeof designtime === 'string' || typeof designtime === 'boolean' ) {
oClassInfo.designtime = designtime;
}
// console.log(oClassInfo.name + ":" + JSON.stringify(oClassInfo, null, " "));
}
// remember class info by name
classInfos[oClassInfo.name] = oClassInfo;
return oClassInfo;
}
function collectDesigntimeInfo(dtNode) {
function each(node, defaultKey, callback) {
var map,n,settings,doclet;
map = node && createPropertyMap(node.value);
if ( map ) {
for (n in map ) {
if ( map.hasOwnProperty(n) ) {
doclet = getLeadingDoclet(map[n], true);
settings = createPropertyMap(map[n].value, defaultKey);
if ( settings == null ) {
error("no valid metadata for " + n + " (AST type '" + map[n].value.type + "')");
continue;
}
callback(n, settings, doclet, map[n]);
}
}
}
}
var oDesigntimeInfo;
var map = createPropertyMap(dtNode.argument);
if (map.annotations) {
oDesigntimeInfo = {
annotations: {}
};
each(map.annotations, null, function(n, settings, doclet) {
var appliesTo = [],
targets = [],
i, oAnno, iPos;
if (settings.appliesTo) {
for (i = 0; i < settings.appliesTo.value.elements.length; i++) {
appliesTo.push(settings.appliesTo.value.elements[i].value);
}
}
if (settings.target) {
for (i = 0; i < settings.target.value.elements.length; i++) {
targets.push(settings.target.value.elements[i].value);
}
}
oDesigntimeInfo.annotations[n] = {
name: n,
doc : doclet && doclet.description,
deprecation : doclet && doclet.deprecated,
since : doclet && doclet.since || settings.since && settings.since.value.value,
namespace: settings.namespace && settings.namespace.value.value,
annotation: settings.annotation && settings.annotation.value.value,
appliesTo: appliesTo,
target: targets,
interpretation: settings.interpretation && settings.interpretation.value.value,
defaultValue: settings.defaultValue && settings.defaultValue.value.value
};
oAnno = oDesigntimeInfo.annotations[n].annotation;
iPos = oAnno && oAnno.lastIndexOf(".");
if ( !oDesigntimeInfo.annotations[n].namespace && iPos > 0 ) {
oDesigntimeInfo.annotations[n].namespace = oAnno.slice(0, iPos);
oDesigntimeInfo.annotations[n].annotation = oAnno.slice(iPos + 1);
}
})
}
return oDesigntimeInfo;
}
function determineValueRangeBorder(range, expression, varname, inverse) {
if ( expression.type === Syntax.BinaryExpression ) {
var value;
if ( expression.left.type === Syntax.Identifier && expression.left.name === varname && expression.right.type === Syntax.Literal ) {
value = expression.right.value;
} else if ( expression.left.type === Syntax.Literal && expression.right.type === Syntax.Identifier && expression.right.name === varname ) {
inverse = !inverse;
value = expression.left.value;
} else {
return false;
}
switch (expression.operator) {
case '<':
range[inverse ? 'minExclusive' : 'maxExclusive'] = value;
break;
case '<=':
range[inverse ? 'minInclusive' : 'maxInclusive'] = value;
break;
case '>=':
range[inverse ? 'maxInclusive' : 'minInclusive'] = value;
break;
case '>':
range[inverse ? 'maxExclusive' : 'minExclusive'] = value;
break;
default:
return false;
}
return true;
}
return false;
}
function determineValueRange(expression, varname, inverse) {
var range = {};
if ( expression.type === Syntax.LogicalExpression
&& expression.operator === '&&'
&& expression.left.type === Syntax.BinaryExpression
&& expression.right.type === Syntax.BinaryExpression
&& determineValueRangeBorder(range, expression.left, varname, inverse)
&& determineValueRangeBorder(range, expression.right, varname, inverse) ) {
return range;
} else if ( expression.type === Syntax.BinaryExpression