import { LineResults } from "../LineResults" ; import { CommandNames } from "../Names/CommandNames" ; import { KeywordNames } from "../Names/KeywordNames" ; import { Command } from "./Command" ; import { CommandMetadata } from "./Metadata/CommandMetadata" ; import { KeywordParameter } from "./Metadata/Parameters/KeywordParameter" ; import { RepeatingParameters } from "./Metadata/Parameters/RepeatingParameters" ; import { SingleParameter } from "./Metadata/Parameters/SingleParameter" ; /**
 * Calls a standalone function.
 */ export class StandaloneFunctionCommand extends Command { /**
     * Metadata on the command.
     */ private static metadata : CommandMetadata = new CommandMetadata ( CommandNames . StandaloneFunction ) . withDescription ( "Calls a standalone function" ) . withParameters ( [ new KeywordParameter ( KeywordNames . Privacies , "The privacy of the function." , true ) , new SingleParameter ( "className" , "The name of the group the function is on." , true ) , new SingleParameter ( "functionName" , "The name of the function." , true ) , new RepeatingParameters ( "Function parameters" , [ new SingleParameter ( "parameterName" , "A named parameter for the function." , true ) , ] ) , ] ) ; returns public getMetadata ( ) { return StandaloneFunctionCommand . metadata ; } param parameters public render ( parameters ) { if ( this . language . syntax . standaloneFunctions . withinStaticClass ) { return this . renderWithinStaticClass ( parameters ) ; } return this . renderFloating ( parameters ) ; } param parameters returns private renderFloating ( parameters ) { let output = "" ; output += this . context . convertStringToCase ( parameters [ 3 ] , this . language . syntax . functions . case ) ; output += "(" ; if ( parameters . length > 4 ) { output += parameters [ 4 ] ; for ( let i = 5 ; i < parameters . length ; i += 1 ) { output += ", " ; output += parameters [ i ] ; } } output += ")" ; return LineResults . newSingleLine ( output ) . withAddSemicolon ( true ) ; } param parameters returns private renderWithinStaticClass ( parameters ) { parameters [ 0 ] = CommandNames . StaticFunction ; return this . context . convertParsed ( parameters ) ; } }