Skip to content

Commit

Permalink
Support Type Ref In Switch Statements
Browse files Browse the repository at this point in the history
See apex-dev-tools/apex-parser#56
(apexfmt already supported the other change in there, case-insensitive
hex characters)
  • Loading branch information
cwarden committed Nov 14, 2024
1 parent 106241c commit 884c4dd
Show file tree
Hide file tree
Showing 5 changed files with 1,856 additions and 1,812 deletions.
12 changes: 12 additions & 0 deletions formatter/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ OneDayDischargeFollowUp.twoHoursDelay,
`inquiry.Admitted_Day__c = ('0' + dayOfWeek) + '-' + dayAbbreviation;`,
`inquiry.Admitted_Day__c = ('0' + dayOfWeek) + '-' + dayAbbreviation;`,
},
{
`String a = 'Fran\u00E7ois';`,
`String a = 'Fran\u00E7ois';`,
},
{
`switch on Schema.Account.getSobjectType().newSObject() { when Schema.Account a { system.debug('doot'); } }`,
`switch on Schema.Account.getSobjectType().newSObject() {
when Schema.Account a {
system.debug('doot');
}
}`,
},
}
for _, tt := range tests {
input := antlr.NewInputStream(tt.input)
Expand Down
2 changes: 2 additions & 0 deletions formatter/visitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ func (v *FormatVisitor) VisitWhenValue(ctx *parser.WhenValueContext) interface{}
switch {
case ctx.ELSE() != nil:
return "else"
case ctx.TypeRef() != nil:
return fmt.Sprintf("%s %s", v.visitRule(ctx.TypeRef()), v.visitRule(ctx.Id(0)))
case len(ctx.AllId()) == 2:
return fmt.Sprintf("%s %s", v.visitRule(ctx.Id(0)), v.visitRule(ctx.Id(1)))
default:
Expand Down
1 change: 1 addition & 0 deletions grammar/ApexParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ whenValue
: ELSE
| whenLiteral (COMMA whenLiteral)*
| id id
| typeRef id
;

whenLiteral
Expand Down
2 changes: 1 addition & 1 deletion parser/ApexParser.interp

Large diffs are not rendered by default.

Loading

0 comments on commit 884c4dd

Please sign in to comment.