import { Import } from "../Languages/Imports/Import" ; import { LineResults } from "../LineResults" ; import { CommandNames } from "../Names/CommandNames" ; import { Command } from "./Command" ; import { CommandResult } from "./CommandResult" ; import { CommandMetadata } from "./Metadata/CommandMetadata" ; import { SingleParameter } from "./Metadata/Parameters/SingleParameter" ; import { addLineEnder } from "./Utilities" ; /**
 * Starts a foreach loop over a container's values.
 */ export class ForEachStartCommand extends Command { /**
     * Metadata on the command.
     */ private static metadata : CommandMetadata = new CommandMetadata ( CommandNames . ForEachStart ) . withDescription ( "Starts a foreach loop over a container's values" ) . withIndentation ( [ 1 ] ) . withParameters ( [ new SingleParameter ( "container" , "A container to iterate over." , true ) , new SingleParameter ( "valueName" , "The iteration variable." , true ) , new SingleParameter ( "valueType" , "The type of the container's values." , true ) , ] ) ; returns public getMetadata ( ) { return ForEachStartCommand . metadata ; } param parameters returns public render ( parameters ) { const imports = [ ] ; let line = this . language . syntax . loops . forEachStartLeft ; let output ; line += this . language . syntax . loops . forEachStartIteration ; if ( this . language . syntax . variables . declarationRequired ) { line += this . language . syntax . variables . declaration ; } if ( this . language . syntax . variables . explicitTypes && ! this . language . syntax . variables . typesAfterName ) { const typeLine = this . context . convertParsed ( [ CommandNames . Type , parameters [ 3 ] ] ) ; line += typeLine . commandResults [ 0 ] . text + " " ; imports . push ( ... typeLine . addedImports ) ; } line += parameters [ 2 ] ; line += this . language . syntax . loops . forEachStartSeparator ; line += parameters [ 1 ] ; output = [ new CommandResult ( line , 0 ) ] ; addLineEnder ( output , this . language . syntax . loops . forEachStartRight , 1 ) ; return new LineResults ( output ) . withImports ( imports ) ; } }