import { Import } from "../Languages/Imports/Import" ; import { ListSortMembersSyntax , ListSortMemberType } from "../Languages/Properties/Syntax/ListSortMembersSyntax" ; import { LineResults } from "../LineResults" ; import { CommandNames } from "../Names/CommandNames" ; import { Command } from "./Command" ; /**
 * Sorts a list in-place by keyed members.
 */ export abstract class ListSortMembersCommand extends Command { param parameters returns public render ( parameters ) { const sortMembers = this . getSortMembersForm ( ) ; if ( sortMembers . type === ListSortMemberType . KeyComparator ) { return this . renderAsKeyComparator ( sortMembers , parameters ) ; } return this . renderAsKeyShorthand ( sortMembers , parameters ) ; } returns protected abstract getSortMembersForm ( ) ; param sortMembers param parameters returns private renderAsKeyComparator ( sortMembers , parameters ) { const imports = [ ] ; const list = parameters [ 1 ] ; const privacy = parameters [ 2 ] ; const memberKey = parameters [ 4 ] ; const instanceNameA = parameters [ 3 ] + "A" ; const memberVariableALine = this . context . convertParsed ( [ CommandNames . MemberVariable , privacy , instanceNameA , memberKey ] ) ; imports . push ( ... memberVariableALine . addedImports ) ; const instanceNameB = parameters [ 3 ] + "B" ; const memberVariableBLine = this . context . convertParsed ( [ CommandNames . MemberVariable , privacy , instanceNameB , memberKey ] ) ; imports . push ( ... memberVariableBLine . addedImports ) ; let output = list ; output += sortMembers . lambdaLeft ; output += instanceNameA + ", " + instanceNameB ; output += sortMembers . lambdaMiddleLeft ; output += memberVariableALine . commandResults [ 0 ] . text ; output += sortMembers . lambdaMiddleRight ; output += memberVariableBLine . commandResults [ 0 ] . text ; output += sortMembers . lambdaRight ; return LineResults . newSingleLine ( output ) . withImports ( sortMembers . requiredImports ) . withAddSemicolon ( true ) ; } param sortMembers param parameters returns private renderAsKeyShorthand ( sortMembers , parameters ) { const imports = [ ] ; const listName = parameters [ 1 ] ; const privacy = parameters [ 2 ] ; const instanceName = parameters [ 3 ] ; const memberKey = parameters [ 4 ] ; const memberVariableLine = this . context . convertParsed ( [ CommandNames . MemberVariable , privacy , instanceName , memberKey ] ) ; imports . push ( ... memberVariableLine . addedImports ) ; let output = listName ; output += sortMembers . lambdaLeft ; output += instanceName ; output += sortMembers . lambdaMiddleLeft ; output += memberVariableLine . commandResults [ 0 ] . text ; output += sortMembers . lambdaRight ; return LineResults . newSingleLine ( output ) . withImports ( sortMembers . requiredImports ) . withAddSemicolon ( true ) ; } }