import { Argument , Decorator , DocstringParts , Exception , KeywordArgument , Returns , Yields , } from "../docstring_parts" ; export class TemplateData { public name : string ; public decorators : Decorator [ ] ; public args : Argument [ ] ; public kwargs : KeywordArgument [ ] ; public exceptions : Exception [ ] ; public returns : Returns ; public yields : Yields ; private includeName : boolean ; private includeExtendedSummary : boolean ; constructor ( docstringParts , guessTypes , includeName , includeExtendedSummary ) { this . name = docstringParts . name ; this . decorators = docstringParts . decorators ; this . args = docstringParts . args ; this . kwargs = docstringParts . kwargs ; this . exceptions = docstringParts . exceptions ; this . returns = docstringParts . returns ; this . yields = docstringParts . yields ; this . includeName = includeName ; this . includeExtendedSummary = includeExtendedSummary ; if ( ! guessTypes ) { this . removeTypes ( ) ; } this . addDefaultTypePlaceholders ( "[type]" ) ; } public placeholder ( ) { return ( text , render ) => { return "${@@@:" + render ( text ) + "}" ; } ; } public summaryPlaceholder ( ) { if ( this . includeName ) { return this . name + " ${@@@:[summary]}" ; } return "${@@@:[summary]}" ; } public extendedSummaryPlaceholder ( ) { if ( this . includeExtendedSummary ) { return "${@@@:[extended_summary]}" ; } return "" ; } public typePlaceholder ( ) { return "${@@@:" + this . type + "}" ; } public descriptionPlaceholder ( ) { return "${@@@:[description]}" ; } public argsExist ( ) { return this . args . length > 0 ; } public kwargsExist ( ) { return this . kwargs . length > 0 ; } public parametersExist ( ) { return this . args . length > 0 || this . kwargs . length > 0 ; } public exceptionsExist ( ) { return this . exceptions . length > 0 ; } public returnsExist ( ) { return this . returns !== undefined ; } public yieldsExist ( ) { return this . yields != undefined ; } private removeTypes ( ) { for ( const arg of this . args ) { arg . type = undefined ; } for ( const kwarg of this . kwargs ) { kwarg . type = undefined ; } if ( this . yieldsExist ( ) ) { this . yields . type = undefined ; } if ( this . returnsExist ( ) ) { this . returns . type = undefined ; } } private addDefaultTypePlaceholders ( placeholder ) { for ( const arg of this . args ) { if ( arg . type === undefined ) { arg . type = placeholder ; } } for ( const kwarg of this . kwargs ) { if ( kwarg . type === undefined ) { kwarg . type = placeholder ; } } const returns = this . returns ; if ( returns !== undefined && returns . type === undefined ) { returns . type = placeholder ; } const yields = this . yields ; if ( yields != undefined && yields . type == undefined ) { yields . type = placeholder ; } } }