Commit Graph

2 Commits

Author SHA1 Message Date
Nikita Eshkeev
5fe869da3b [java][switch resolve] IDEA-273929 Good code red - cannot resolve symbol in switch statement group
Check if the being resolved element is in the list of case label elements first and only if it's not, go deeper into case label elements' resolvers.

GitOrigin-RevId: 63280ccb3bbf95660c5f74f35dc5de4cf34752b6
2021-08-02 13:27:26 +00:00
Nikita Eshkeev
0e5e22a101 [java][resolve] IDEA-271676 Pattern matching for switch: fix resolve
Fix the resolution algorithm for both switch statements and switch expressions. The main obstacle is that the handler of a case expression is a child node of the labeled case rule and the handler of a case statement is the right sibling of the labeled case rule.

The fact that a case handler is the right sibling of a labeled case rule in switch statements complicates the resolving, because the scope of a pattern variable is bound only to the immediate case handler and cannot be accessible from different case handler, which might be invoked when there is no `break` statements between case rules. In order to restrict the scope of a pattern variable in a switch statement the following check is added: check if the analyzed PsiSwitchLabeledStatement is not followed by any other case rules and if so try to resolve an element using its pattern variables.

The scope of pattern variables for PsiSwitchLabeledRuleStatements is restricted only to their case handlers, so the resolve works there only if the lastParent is not null, which, according to the contract, contains the case's handler.

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 084b8b679b4070a67a996c3b50992622025d96ee
2021-06-23 00:33:25 +00:00