UParenthesizedExpression checks

17 views
Skip to first unread message

Jeremy Woods

unread,
Aug 18, 2021, 8:55:05 PM8/18/21
to lint-dev
Struggling with the UParenthesizedExpression expressions checks in tests.

How do I get the parenthesis from the middle of a UCallExpression. Say the parenthesize testMode takes my expression from:

```
variable?.someMethod()
```

to:

```
(variable)?.someMethod()
```

How do I get it back to where I can use `variable?.someMethod()`? `skipParenthesizedExprUp/Down()` don't seem to do anything here. The code relies on some processing that starts to breakdown if we can't strip out the parentheses internally.

Tor Norbye

unread,
Aug 31, 2021, 2:31:21 PM8/31/21
to lint-dev
I'm not sure I understood the question -- but if you have variable.someMethod() that's a UCallExpression where the receiver is a USimpleNameReferenceExpression ("variable"), and the method name is "someMethod".
If you instead have variable?.someMethod(), that's still a UCallExpression, and the methodName is still "someMethod", but now the receiver is instead a UParenthesizedExpression ("(variable)"). If you want to get the variable in this case, you'd do call.receiver.skipParenthesizedExprDown() -- this will be the same USimpleNameReferenceExpression as in the first case.

-- Tor
Reply all
Reply to author
Forward
0 new messages