/**
 * Copyright (c) 2016-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import * as ObjC from './objc' ; import * as ObjectSpec from './object-spec' ; function commentWithFirstSpaceIfNecessary ( comment ) { return comment . charAt ( 0 ) == ' ' ? comment : ' ' + comment ; } export function commentsAsBlockFromStringArray ( commentsAsStrings ) { if ( commentsAsStrings . length == 0 ) { return [ ] ; } const commentBody = commentsAsStrings . map ( function ( comment ) : ObjC . Comment { return { content : ' *' + commentWithFirstSpaceIfNecessary ( comment ) } ; } ) ; return [ { content : '/**' } ] . concat ( commentBody ) . concat ( { content : ' */' } ) ; } export function singleLineCommentsBlockFromStringArray ( commentsAsStrings ) { return commentsAsStrings . map ( ( comment ) => { return { content : [ '//' , comment ] . filter ( Boolean ) . join ( ' ' ) } ; } ) ; } function repeat ( string , times ) { return times > 1 ? string + repeat ( string , times - 1 ) : string ; } function paramCommentsFromAttribute ( attribute ) { const prefix = ` @param ${ attribute . name } ` ; const whitespace = repeat ( ' ' , prefix . length ) ; return attribute . comments . map ( ( comment , index ) => { return index === 0 ? prefix + comment . trim ( ) : whitespace + comment . trim ( ) ; } ) ; } export function paramCommentsFromAttributes ( attributes ) { return ( [ ] as string [ ] ) . concat ( ... attributes . map ( paramCommentsFromAttribute ) ) ; } export function prefixedParamCommentsFromAttributes ( prefix , attributes ) { const paramComments = paramCommentsFromAttributes ( attributes ) ; const separator = paramComments . length > 0 && prefix . length > 0 ? [ '' ] : [ ] ; return prefix . concat ( separator , paramComments ) ; }