@@ -33,12 +33,12 @@ let $definition := xdmp:xslt-eval(
3333 <xsl:if test = "preceding-sibling::apidoc:param[not(@class) or @class = 'javascript'][@name = current()/@name]" >2 </xsl:if>
3434 <xsl:if test = "not($is-multi) and string(@optional) = 'true'" >?</xsl:if>
3535 <xsl:text>: </xsl:text>
36- <xsl:value-of select = "local:fixType(@type)" />
36+ <xsl:value-of select = "local:fixType(@type, true() )" />
3737 <xsl:if test = "$is-multi" >[]</xsl:if>
3838 <xsl:if test = "not(position() = last())" >, </xsl:if>
3939 </xsl:for-each>
4040 <xsl:text>): </xsl:text>
41- <xsl:value-of select = "local:fixType(string(apidoc:return[not(@class) or @class = 'javascript']))" />
41+ <xsl:value-of select = "local:fixType(string(apidoc:return[not(@class) or @class = 'javascript']), false() )" />
4242 <xsl:text>; </xsl:text>
4343 </xsl:template>
4444
@@ -89,34 +89,82 @@ let $definition := xdmp:xslt-eval(
8989
9090 <xsl:function name = "local:fixType" >
9191 <xsl:param name = "pType" />
92+ <xsl:param name = "isForParameter" />
9293
93- <xsl:variable name = "preType" select = "replace(replace($pType, '^(.+)[?+*](,\.\.\.)?$', '$1'), ' ', '')" />
94+ <xsl:variable name = "preTypeAndCardinality" select = "replace(replace($pType, '^([^,]+)(,\.\.\.)?$', '$1'), ' ', '')" />
95+ <xsl:variable name = "lastCharacter" select = "substring($preTypeAndCardinality, string-length($preTypeAndCardinality))" />
96+ <xsl:variable name = "preType" select = "if (matches($lastCharacter, '^[?*+]$')) then substring($preTypeAndCardinality, 1, string-length($preTypeAndCardinality) - 1) else $preTypeAndCardinality" />
97+ <xsl:variable name = "isArray" select = "matches($lastCharacter, '^[*+]$')" />
9498 <xsl:variable name = "type" select = "if (substring($preType, 1, 1) = '(') then substring($preType, 2, string-length($preType) - 2) else $preType" />
9599
96- <xsl:value-of select = "local:fixEachType($type)" />
100+ <xsl:value-of select = "local:fixEachType($type, $isArray, $isForParameter )" />
97101 </xsl:function>
98102
99103 <xsl:function name = "local:fixEachType" >
100104 <xsl:param name = "typeUnion" />
105+ <xsl:param name = "isArray" />
106+ <xsl:param name = "isForParameter" />
101107
102108 <xsl:variable name = "type" select = "substring-before(concat($typeUnion,'|'),'|')" />
103109
104110 <xsl:choose>
105- <xsl:when test = "$type = ('document-node()')" >DocumentNode< any> </xsl:when>
106- <xsl:when test = "$type = ('binary()', 'element()', 'node()')" >MLNode< any> </xsl:when>
111+ <xsl:when test = "matches($type, '^function\(.*\)as(.+)$')" >
112+ <xsl:value-of select = "local:fixFunctionType($type, $isArray)" />
113+ </xsl:when>
114+ <xsl:when test = "$isArray" >
115+ <xsl:choose>
116+ <xsl:when test = "$type = ('document-node()', 'binary()', 'element()', 'node()')" >
117+ <xsl:value-of select = "local:fixArrayType('any', $isForParameter)" />
118+ </xsl:when>
119+ <xsl:otherwise>
120+ <xsl:value-of select = "local:fixArrayType(string-join(local:fixSingleType($type, $isForParameter), ''), $isForParameter)" />
121+ </xsl:otherwise>
122+ </xsl:choose>
123+ </xsl:when>
124+ <xsl:otherwise>
125+ <xsl:value-of select = "local:fixSingleType($type, $isForParameter)" />
126+ </xsl:otherwise>
127+ </xsl:choose>
128+
129+ <xsl:if test = "contains($typeUnion, '|')" >
130+ <xsl:value-of select = "concat('|', string-join(local:fixEachType(substring-after($typeUnion, '|'), $isArray, $isForParameter), ''))" />
131+ </xsl:if>
132+ </xsl:function>
133+
134+ <xsl:function name = "local:fixArrayType" >
135+ <xsl:param name = "type" />
136+ <xsl:param name = "isForParameter" />
137+ <xsl:value-of select = "concat(concat(if($isForParameter) then 'MLArray< ' else 'ValueIterator< ', $type), '> ')" />
138+ </xsl:function>
139+
140+ <xsl:function name = "local:fixSingleType" >
141+ <xsl:param name = "type" />
142+ <xsl:param name = "isForParameter" />
143+ <xsl:choose>
144+ <xsl:when test = "$type = 'ValueIterator'" >ValueIterator< any> </xsl:when>
145+ <xsl:when test = "$type = 'document-node()'" >DocumentNode< any> </xsl:when>
146+ <xsl:when test = "$type = ('binary()')" >MLNode< any> </xsl:when>
147+ <xsl:when test = "$type = ('element()', 'node()', 'item()')" >
148+ <xsl:choose>
149+ <xsl:when test = "$isForParameter" >MLNodeOrObject< any> </xsl:when>
150+ <xsl:otherwise>MLNode< any> </xsl:otherwise>
151+ </xsl:choose>
152+ </xsl:when>
107153 <xsl:when test = "$type = ('empty-sequence()', 'Null')" >void</xsl:when>
108- <xsl:when test = "$type = ('String', 'item()', ' xs:anyURI', 'xs:NCName', 'xs:string', 'xs:time', 'xs:unsignedLong ', 'xs:duration', 'xs:dayTimeDuration')" >string</xsl:when>
154+ <xsl:when test = "$type = ('String', 'xs:anyURI', 'xs:NCName', 'xs:string', 'xs:time', 'xs:duration', 'xs:dayTimeDuration')" >string</xsl:when>
109155 <xsl:when test = "$type = ('json:array', 'Array')" >Array< any> </xsl:when>
110- <xsl:when test = "$type = 'ValueIterator'" >ValueIterator< any> </xsl:when>
111156 <xsl:when test = "$type = ('json:object', 'map:map')" >{[ key:string] :any} </xsl:when>
112157 <xsl:when test = "$type = ('function()', 'xdmp:function', 'function(*', 'function(*)')" >() => any</xsl:when>
113158 <xsl:when test = "$type = 'xs:boolean'" >boolean</xsl:when>
114159 <xsl:when test = "$type = 'xs:anyAtomicType'" >any</xsl:when>
115160 <xsl:when test = "$type = ('xs:dateTime', 'xs:date')" >Date</xsl:when>
116- <xsl:when test = "$type = ('Int', 'double', 'xs:numeric', 'numeric', 'xs:decimal', 'xs:double', 'xs:int', 'xs:float', 'xs:integer', 'xs:long', 'xs:nonNegativeInteger', 'xs:positiveInteger', 'xs:unsignedInt')" >number</xsl:when>
117- <xsl:when test = "matches($type, '^(schema-)?[Ee]lement\([^)]+\)$')" >MLNode< any> </xsl:when>
118- <xsl:when test = "matches($type, '^function\(')" >
119- <xsl:value-of select = "local:fixFunctionType($type)" />
161+ <xsl:when test = "$type = ('Int', 'double', 'xs:numeric', 'numeric', 'xs:decimal', 'xs:double', 'xs:unsignedLong', 'xs:int', 'xs:float', 'xs:integer', 'xs:long', 'xs:nonNegativeInteger', 'xs:positiveInteger', 'xs:unsignedInt')" >number</xsl:when>
162+ <xsl:when test = "matches($type, '^(schema-)?[Ee]lement\([^)]+\)$')" >
163+ <xsl:choose>
164+ <!-- TODO: Can we perform generics on this? -->
165+ <xsl:when test = "$isForParameter" >MLNodeOrObject< any> </xsl:when>
166+ <xsl:otherwise>MLNode< any> </xsl:otherwise>
167+ </xsl:choose>
120168 </xsl:when>
121169 <xsl:otherwise>
122170 <xsl:variable name = "local-name" select = "replace($type, '^([^:.]+[:.])?([^\(\)]+)\(?\)?$', '$2')" />
@@ -133,25 +181,33 @@ let $definition := xdmp:xslt-eval(
133181 </xsl:choose>
134182 </xsl:otherwise>
135183 </xsl:choose>
136- <xsl:if test = "contains($typeUnion, '|')" >
137- <xsl:value-of select = "concat('|', string-join(local:fixEachType(substring-after($typeUnion, '|')), ''))" />
138- </xsl:if>
139184 </xsl:function>
140185
141186 <xsl:function name = "local:fixFunctionType" >
142187 <xsl:param name = "type" />
188+ <xsl:param name = "isArray" />
143189 <xsl:text>(</xsl:text>
144- <xsl:value-of select = "local:fixParameters(replace($type, '^function\((.+)\)as(.+)?$', '$1'), 1)" />
190+ <xsl:if test = "matches($type, '^function\((.+)\)as(.+)$')" >
191+ <xsl:value-of select = "local:fixParameters(replace($type, '^function\((.+)\)as(.+)$', '$1'), 1)" />
192+ </xsl:if>
145193 <xsl:text>)=> </xsl:text>
146- <xsl:value-of select = "local:fixType(replace($type, '^function\((.+)\)as(.+)?$', '$2'))" />
194+ <xsl:variable name = "returnType" select = "local:fixType(replace($type, '^function\(.*\)as(.+)$', '$1'), false())" />
195+ <xsl:choose>
196+ <xsl:when test = "$isArray" >
197+ <xsl:value-of select = "local:fixArrayType($returnType, false())" />
198+ </xsl:when>
199+ <xsl:otherwise>
200+ <xsl:value-of select = "$returnType" />
201+ </xsl:otherwise>
202+ </xsl:choose>
147203 </xsl:function>
148204
149205 <xsl:function name = "local:fixParameters" >
150206 <xsl:param name = "parameters" />
151207 <xsl:param name = "number" />
152208 <xsl:value-of select = "concat(concat('p', $number), ':')" />
153209 <xsl:variable name = "type" select = "substring-before(concat($parameters,','),',')" />
154- <xsl:value-of select = "local:fixType($type)" />
210+ <xsl:value-of select = "local:fixType($type, true() )" />
155211 <xsl:if test = "contains($parameters, ',')" >
156212 <xsl:value-of select = "concat(',', string-join(local:fixParameters(substring-after($parameters, ','), $number + 1), ''))" />
157213 </xsl:if>
0 commit comments