disable split into decl 7/ assignment for conflicting names (IDEA-173787)

for statement induces another declaration parent where another local variable could have been declared
This commit is contained in:
Anna Kozlova
2017-06-26 18:05:03 +03:00
parent 7082e31910
commit 339c14cd12
2 changed files with 18 additions and 3 deletions

View File

@@ -78,17 +78,23 @@ public class SplitDeclarationAction extends PsiElementBaseIntentionAction {
if (declaredElements.length == 1) {
PsiLocalVariable var = (PsiLocalVariable)declaredElements[0];
if (var.getInitializer() == null) return false;
PsiElement parent = decl.getParent();
if (parent instanceof PsiForStatement) {
String varName = var.getName();
if (varName == null ||
JavaPsiFacade.getInstance(decl.getProject()).getResolveHelper().resolveReferencedVariable(varName, parent.getParent()) != null) {
return false;
}
}
setText(CodeInsightBundle.message("intention.split.declaration.assignment.text"));
return true;
}
else if (declaredElements.length > 1) {
else {
if (decl.getParent() instanceof PsiForStatement) return false;
setText(CodeInsightBundle.message("intention.split.declaration.text"));
return true;
}
return false;
}
@Override

View File

@@ -0,0 +1,9 @@
// "Split into declaration and assignment" "false"
class Test {
{
for (int i<caret>=0; i<10; i++) {
System.out.println();
}
int i = 0;
}
}