mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 02:09:59 +07:00
[java-inspections] UnrollLoopAction: track class conflicts (IDEA-331850)
GitOrigin-RevId: 314a8f32ca768b18f337bc584b1a8bfe3941248e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b45abaca53
commit
7c7e99ab98
@@ -256,12 +256,17 @@ public class UnrollLoopAction extends PsiUpdateModCommandAction<PsiLoopStatement
|
||||
if (statement instanceof PsiDeclarationStatement declaration) {
|
||||
if (expressions.size() > 1) return false;
|
||||
for (PsiElement element : declaration.getDeclaredElements()) {
|
||||
PsiResolveHelper resolveHelper = PsiResolveHelper.getInstance(block.getProject());
|
||||
if (element instanceof PsiVariable variable) {
|
||||
String name = variable.getName();
|
||||
if (name != null) {
|
||||
if (PsiResolveHelper.getInstance(block.getProject()).resolveReferencedVariable(name, parentBlock) != null) {
|
||||
return false;
|
||||
}
|
||||
if (name != null && resolveHelper.resolveReferencedVariable(name, parentBlock) != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (element instanceof PsiClass psiClass) {
|
||||
String name = psiClass.getName();
|
||||
if (name != null && resolveHelper.resolveReferencedClass(name, parentBlock) != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Unroll loop" "true-preview"
|
||||
class X {
|
||||
void test() {
|
||||
{
|
||||
class Y {
|
||||
int a = 1;
|
||||
}
|
||||
}
|
||||
class Y {}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
class X {
|
||||
void test() {
|
||||
int y = 1 + 1;
|
||||
class Y {
|
||||
}
|
||||
System.out.println(y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Unroll loop" "true-preview"
|
||||
class X {
|
||||
void test() {
|
||||
<caret>for (int x : new int[]{1}) {
|
||||
class Y {
|
||||
int a = x;
|
||||
}
|
||||
}
|
||||
class Y {}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ class X {
|
||||
void test() {
|
||||
<caret>for (int x : new int[]{1}) {
|
||||
int y = x + 1;
|
||||
class Y{}
|
||||
System.out.println(y);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user