Skip to content

Commit 639690e

Browse files
authored
Merge pull request #29 from cesarParra/sobject-switch-fix
Fixes potential issue when switching on an SObject
2 parents e7fe7d2 + 2014596 commit 639690e

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

js/apex-reflection-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cparra/apex-reflection",
3-
"version": "2.15.0",
3+
"version": "2.16.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

lib/src/antlr/grammars/apex/ApexParser.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,7 @@ class ApexParser extends Parser {
24402440
case 3:
24412441
enterOuterAlt(_localctx, 3);
24422442
state = 748;
2443-
id();
2443+
typeRef();
24442444
state = 749;
24452445
id();
24462446
break;
@@ -8958,7 +8958,7 @@ class ApexParser extends Parser {
89588958
'\u{2}\u{2}\u{2}\u{2EA}\u{2ED}\u{3}\u{2}\u{2}\u{2}\u{2EB}\u{2E9}\u{3}'
89598959
'\u{2}\u{2}\u{2}\u{2EB}\u{2EC}\u{3}\u{2}\u{2}\u{2}\u{2EC}\u{2F2}\u{3}'
89608960
'\u{2}\u{2}\u{2}\u{2ED}\u{2EB}\u{3}\u{2}\u{2}\u{2}\u{2EE}\u{2EF}\u{5}'
8961-
'\u{120}\u{91}\u{2}\u{2EF}\u{2F0}\u{5}\u{120}\u{91}\u{2}\u{2F0}\u{2F2}'
8961+
'\u{30}\u{19}\u{2}\u{2EF}\u{2F0}\u{5}\u{120}\u{91}\u{2}\u{2F0}\u{2F2}'
89628962
'\u{3}\u{2}\u{2}\u{2}\u{2F1}\u{2E5}\u{3}\u{2}\u{2}\u{2}\u{2F1}\u{2E6}'
89638963
'\u{3}\u{2}\u{2}\u{2}\u{2F1}\u{2EE}\u{3}\u{2}\u{2}\u{2}\u{2F2}\u{5B}\u{3}'
89648964
'\u{2}\u{2}\u{2}\u{2F3}\u{2F5}\u{7}\u{E4}\u{2}\u{2}\u{2F4}\u{2F3}\u{3}'
@@ -10564,8 +10564,8 @@ class WhenValueContext extends ParserRuleContext {
1056410564
WhenLiteralContext? whenLiteral(int i) => getRuleContext<WhenLiteralContext>(i);
1056510565
List<TerminalNode> COMMAs() => getTokens(ApexParser.TOKEN_COMMA);
1056610566
TerminalNode? COMMA(int i) => getToken(ApexParser.TOKEN_COMMA, i);
10567-
List<IdContext> ids() => getRuleContexts<IdContext>();
10568-
IdContext? id(int i) => getRuleContext<IdContext>(i);
10567+
TypeRefContext? typeRef() => getRuleContext<TypeRefContext>(0);
10568+
IdContext? id() => getRuleContext<IdContext>(0);
1056910569
WhenValueContext([ParserRuleContext? parent, int? invokingState]) : super(parent, invokingState);
1057010570
@override
1057110571
int get ruleIndex => RULE_whenValue;

lib/src/antlr/grammars/apex/ApexParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ whenControl
295295
whenValue
296296
: ELSE
297297
| whenLiteral (COMMA whenLiteral)*
298-
| id id
298+
| typeRef id
299299
;
300300

301301
whenLiteral

lib/src/antlr/grammars/apex/ApexParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

test/apex_listener_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,26 @@ void main() {
12351235
apexWalkerDefinition),
12361236
returnsNormally);
12371237
});
1238+
1239+
test('Supports switch when', () {
1240+
final apexWalkerDefinition = ApexWalkerDefinition();
1241+
var classBody = '''
1242+
public class MyClass {
1243+
public void doSomething() {
1244+
switch on Account.SObjectType.newSObject() {
1245+
when Schema.Account someAccount {
1246+
System.debug(someAccount.Name);
1247+
}
1248+
}
1249+
}
1250+
}
1251+
''';
1252+
1253+
expect(
1254+
() => Walker.walk(CaseInsensitiveInputStream.fromString(classBody),
1255+
apexWalkerDefinition),
1256+
returnsNormally);
1257+
});
12381258
});
12391259

12401260
group('Parses Apex Interfaces', () {

0 commit comments

Comments
 (0)