@@ -4,7 +4,7 @@ import { MarkdownGenerator, MarkdownBuilder, Contracts as MarkdownContracts } fr
44import * as path from "path" ;
55
66import { ApiItemReference } from "./contracts/api-item-reference" ;
7- import { ApiItemKindsAdditional } from "./contracts/plugin" ;
7+ import { ApiItemKindsAdditional , PluginResultData } from "./contracts/plugin" ;
88import { Logger } from "./utils/logger" ;
99
1010export namespace GeneratorHelpers {
@@ -306,6 +306,43 @@ export namespace GeneratorHelpers {
306306 return `${ apiItem . Name } ${ $extends } ${ defaultType } ` ;
307307 }
308308
309+ export function ClassToString (
310+ apiItem : Contracts . ApiClassDto ,
311+ typeParameters ?: Contracts . ApiTypeParameterDto [ ] ,
312+ alias ?: string
313+ ) : string {
314+ const name = alias || apiItem . Name ;
315+ // Abstract
316+ const abstract = apiItem . IsAbstract ? "abstract " : "" ;
317+
318+ // TypeParameters
319+ let typeParametersString : string ;
320+ if ( typeParameters != null && typeParameters . length > 0 ) {
321+ const params : string [ ] = typeParameters . map ( TypeParameterToString ) ;
322+ typeParametersString = `<${ params . join ( ", " ) } >` ;
323+ } else {
324+ typeParametersString = "" ;
325+ }
326+
327+ // Extends
328+ let extendsString : string ;
329+ if ( apiItem . Extends != null ) {
330+ extendsString = ` extends ${ apiItem . Extends . Text } ` ;
331+ } else {
332+ extendsString = "" ;
333+ }
334+
335+ // Implements
336+ let implementsString : string ;
337+ if ( apiItem . Implements != null && apiItem . Implements . length > 0 ) {
338+ implementsString = ` implements ${ apiItem . Implements . map ( x => x . Text ) . join ( ", " ) } ` ;
339+ } else {
340+ implementsString = "" ;
341+ }
342+
343+ return `${ abstract } class ${ name } ${ typeParametersString } ${ extendsString } ${ implementsString } ` ;
344+ }
345+
309346 export function ApiFunctionToSimpleString (
310347 alias : string ,
311348 apiItem : Contracts . ApiFunctionDto ,
@@ -319,6 +356,66 @@ export namespace GeneratorHelpers {
319356 return `${ name } (${ parametersString } )` ;
320357 }
321358
359+ export function ApiClassMethodToString (
360+ apiItem : Contracts . ApiClassMethodDto ,
361+ parameters : Contracts . ApiParameterDto [ ] ,
362+ alias ?: string
363+ ) : string {
364+ const name = alias || apiItem . Name ;
365+
366+ const optional = apiItem . IsOptional ? "?" : "" ;
367+ const abstract = apiItem . IsAbstract ? " abstract" : "" ;
368+ const async = apiItem . IsAsync ? " async" : "" ;
369+ const $static = apiItem . IsStatic ? " static" : "" ;
370+ const functionHeader = CallableParametersToString ( `${ name } ${ optional } ` , parameters , apiItem . ReturnType ) ;
371+
372+ return `${ apiItem . AccessModifier } ${ $static } ${ abstract } ${ async } ${ functionHeader } ` . trim ( ) ;
373+ }
374+
375+ export function ApiClassPropertyToString ( apiItem : Contracts . ApiClassPropertyDto , alias ?: string ) : string {
376+ const name = alias || apiItem . Name ;
377+
378+ const optional = apiItem . IsOptional ? "?" : "" ;
379+ const abstract = apiItem . IsAbstract ? " abstract" : "" ;
380+ const $static = apiItem . IsStatic ? " static" : "" ;
381+
382+ return `${ apiItem . AccessModifier } ${ $static } ${ abstract } ${ name } ${ optional } : ${ apiItem . Type . Text } ;` ;
383+ }
384+
385+ export function CallableParametersToSimpleString ( text : string , parameters : Contracts . ApiParameterDto [ ] ) : string {
386+ const parametersString = parameters
387+ . map ( x => x . Name )
388+ . join ( ", " ) ;
389+
390+ return `${ text } (${ parametersString } )` ;
391+ }
392+
393+ export function CallableParametersToString (
394+ text : string ,
395+ parameters : Contracts . ApiParameterDto [ ] ,
396+ returnType ?: Contracts . TypeDto
397+ ) : string {
398+ // Parameters
399+ let parametersString : string ;
400+ if ( parameters != null && parameters . length > 0 ) {
401+ parametersString = parameters
402+ . map ( x => `${ x . Name } : ${ x . Type . Text } ` )
403+ . join ( ", " ) ;
404+ } else {
405+ parametersString = "" ;
406+ }
407+
408+ // ReturnType
409+ let returnTypeString : string ;
410+ if ( returnType != null ) {
411+ returnTypeString = `: ${ returnType . Text } ` ;
412+ } else {
413+ returnTypeString = "" ;
414+ }
415+
416+ return `${ text } (${ parametersString } )${ returnTypeString } ` ;
417+ }
418+
322419 export function GetApiItemsFromReference < T extends Contracts . ApiItemDto > (
323420 items : Contracts . ApiItemReference [ ] ,
324421 extractedData : ExtractDto
@@ -344,4 +441,21 @@ export namespace GeneratorHelpers {
344441 export function StandardisePath ( pathString : string ) : string {
345442 return pathString . split ( path . sep ) . join ( "/" ) ;
346443 }
444+
445+ export function MergePluginResultData < T extends PluginResultData > ( a : T , b : Partial < PluginResultData > ) : T {
446+ a . Headings = a . Headings . concat ( b . Headings || [ ] ) ;
447+ a . Members = ( a . Members || [ ] ) . concat ( b . Members || [ ] ) ;
448+ a . Result = a . Result . concat ( b . Result || [ ] ) ;
449+ a . UsedReferences = a . UsedReferences . concat ( b . UsedReferences || [ ] ) ;
450+
451+ return a ;
452+ }
453+
454+ export function GetDefaultPluginResultData ( ) : PluginResultData {
455+ return {
456+ Headings : [ ] ,
457+ Result : [ ] ,
458+ UsedReferences : [ ]
459+ } ;
460+ }
347461}
0 commit comments