[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
This commit is contained in:
Nikita Eshkeev
2021-08-02 12:16:34 +03:00
committed by intellij-monorepo-bot
parent 3c56aa21ed
commit 5fe869da3b
2 changed files with 7 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import com.intellij.lang.ASTNode;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.*;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -91,8 +92,11 @@ public class PsiCaseLabelElementListImpl extends CompositePsiElement implements
@NotNull PsiElement place) {
// Do not resolve elements from the list of elements of the case rule
if (lastParent != null) return true;
for (PsiCaseLabelElement label : getElements()) {
if (place == label) return true;
final PsiCaseLabelElement[] elements = getElements();
if (ContainerUtil.exists(elements, e -> e == place)) return true;
for (PsiCaseLabelElement label : elements) {
boolean shouldKeepGoing = label.processDeclarations(processor, state, null, place);
if (!shouldKeepGoing) return false;
}

View File

@@ -3,7 +3,7 @@ class Main {
void f(Object obj) {
switch (obj) {
case i<caret>, Integer i:
case Integer i, i<caret>:
System.out.println(i);
}
}