Skip to content

Commit db66c0d

Browse files
committed
[INTERNAL] lib/processors/jsdoc: collect defaultClass information from runtime metadata
Cherry-picked from UI5/openui5@ead6e7fd6
1 parent 60022a8 commit db66c0d

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

lib/processors/jsdoc/lib/ui5/plugin.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,30 @@ function collectVisibilityInfo(settings, doclet, className, n) {
11871187
return visibility;
11881188
}
11891189

1190+
function convertDefaultClass(settings, doclet, n) {
1191+
const node = settings.defaultClass?.value;
1192+
if ( node == null ) {
1193+
// check if a @default tag is given (e.g. sap.ui.core.Element#customData)
1194+
// This is only taken into accout when there is no defaultClass property in the metadata
1195+
if ( doclet?.defaultvalue != null ) {
1196+
if ( typeof doclet.defaultvalue === "string" ) {
1197+
return doclet.defaultvalue;
1198+
}
1199+
error(`could not derive defaultClass for aggregation ${n} from default tag ${doclet.defaultvalue}`);
1200+
}
1201+
return undefined;
1202+
}
1203+
if ( node.type === Syntax.Identifier ) {
1204+
if ( currentModule.localNames[node.name]?.module ) {
1205+
return currentModule.localNames[node.name].module;
1206+
}
1207+
error(`could not derive defaultClass for aggregation ${n} from identifier ${node.name}`);
1208+
return "unknown";
1209+
}
1210+
error(`could not derive defaultClass for aggregation ${n} from node of type ${node.type}`);
1211+
return "unknown";
1212+
}
1213+
11901214
function collectClassInfo(extendCall, classDoclet) {
11911215

11921216
let baseType;
@@ -1349,6 +1373,7 @@ function collectClassInfo(extendCall, classDoclet) {
13491373
singularName : settings.singularName ? settings.singularName.value.value : guessSingularName(n),
13501374
cardinality : (settings.multiple && !settings.multiple.value.value) ? "0..1" : "0..n",
13511375
bindable : settings.bindable ? !!convertValue(settings.bindable.value) : false,
1376+
defaultClass: convertDefaultClass(settings, doclet, n),
13521377
methods: (methods = {
13531378
"get": "get" + N,
13541379
"destroy": "destroy" + N

lib/processors/jsdoc/lib/ui5/template/publish.js

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,9 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
12771277
if ( aggr.altTypes ) {
12781278
curr.altTypes = aggr.altTypes.slice();
12791279
}
1280+
if ( aggr.defaultClass ) {
1281+
attrib("defaultClass", aggr.defaultClass);
1282+
}
12801283
attrib("cardinality", aggr.cardinality, '0..n');
12811284
attrib("visibility", aggr.visibility, 'public');
12821285
if (aggr.stakeholders) {
@@ -1934,9 +1937,8 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
19341937
return obj[0];
19351938
}
19361939

1937-
function postProcessAPIJSON(api) {
1940+
function addExportInfo(symbols) {
19381941
const modules = {};
1939-
const symbols = api.symbols;
19401942

19411943
// collect modules and the symbols that refer to them
19421944
for ( let i = 0; i < symbols.length; i++) {
@@ -2058,6 +2060,13 @@ function postProcessAPIJSON(api) {
20582060
for ( const n in modules ) {
20592061
guessExports(n, modules[n]);
20602062
}
2063+
}
2064+
2065+
function postProcessAPIJSON(api) {
2066+
2067+
const symbols = api.symbols;
2068+
2069+
addExportInfo(symbols);
20612070

20622071
function findSymbol(name) {
20632072
if ( name == null || name === '' ) {
@@ -2086,6 +2095,28 @@ function postProcessAPIJSON(api) {
20862095
return (m && m[1]) || "";
20872096
}
20882097

2098+
// create a 2-level map of symbol names, first keyed by the exporting module and then by export name
2099+
const modules = Object.create(null);
2100+
for (const symbol of Object.values(externalSymbols)) {
2101+
if ( symbol.module && symbol.export !== undefined ) {
2102+
modules[symbol.module] ??= Object.create(null);
2103+
modules[symbol.module][symbol.export] = symbol.name;
2104+
}
2105+
}
2106+
for (const symbol of symbols) {
2107+
if ( symbol.module && symbol.export !== undefined ) {
2108+
modules[symbol.module] ??= Object.create(null);
2109+
modules[symbol.module][symbol.export] = symbol.name;
2110+
}
2111+
}
2112+
2113+
function findSymbolByModule(module, exportName) {
2114+
if (module === "unknown") {
2115+
return "unknown";
2116+
}
2117+
return modules[module]?.[exportName] ?? "unknown";
2118+
}
2119+
20892120
symbols.forEach((symbol) => {
20902121
// add note for enums which are not exposed by their name
20912122
if (symbol.kind === "enum" && symbol.export) {
@@ -2154,6 +2185,16 @@ function postProcessAPIJSON(api) {
21542185
}
21552186
}
21562187
}
2188+
/*
2189+
* Up to here, the defaultClass only contains a module name. Replace it with the corresponding API (type) name.
2190+
*/
2191+
if (Array.isArray(symbol["ui5-metadata"].aggregations)) {
2192+
for (const aggr of symbol["ui5-metadata"].aggregations) {
2193+
if (aggr.defaultClass != null) {
2194+
aggr.defaultClass = findSymbolByModule(aggr.defaultClass, "");
2195+
}
2196+
}
2197+
}
21572198
});
21582199

21592200
}

0 commit comments

Comments
 (0)