mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-17 07:20:53 +07:00
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
10 lines
171 B
Java
10 lines
171 B
Java
class Main {
|
|
final int i = 2;
|
|
|
|
String test(Object obj) {
|
|
return switch (obj) {
|
|
case i<caret>, Integer i -> "hello";
|
|
default -> "nothing";
|
|
}
|
|
}
|
|
} |