mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
IDEA-115867 Copy to temp final variable does not work correctly inside expression without braces
This commit is contained in:
+7
-2
@@ -30,6 +30,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.controlFlow.ControlFlowUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ConcurrentWeakHashMap;
|
||||
import gnu.trove.THashMap;
|
||||
@@ -204,9 +205,13 @@ public class VariableAccessFromInnerClassFix implements IntentionAction {
|
||||
PsiUtil.setModifierProperty(newVariable, PsiModifier.FINAL, true);
|
||||
PsiElement statement = getStatementToInsertBefore();
|
||||
if (statement == null) return;
|
||||
statement.getParent().addBefore(copyDecl, statement);
|
||||
PsiExpression newExpression = factory.createExpressionFromText(newName, myVariable);
|
||||
replaceReferences(myClass, myVariable, newExpression);
|
||||
if (RefactoringUtil.isLoopOrIf(statement.getParent())) {
|
||||
RefactoringUtil.putStatementInLoopBody(copyDecl, statement.getParent(), statement);
|
||||
} else {
|
||||
statement.getParent().addBefore(copyDecl, statement);
|
||||
}
|
||||
}
|
||||
|
||||
private PsiElement getStatementToInsertBefore() {
|
||||
@@ -217,7 +222,7 @@ public class VariableAccessFromInnerClassFix implements IntentionAction {
|
||||
PsiElement statement = myClass;
|
||||
nextInnerClass:
|
||||
do {
|
||||
statement = PsiUtil.getEnclosingStatement(statement);
|
||||
statement = RefactoringUtil.getParentStatement(statement, false);
|
||||
|
||||
if (statement == null || statement.getParent() == null) {
|
||||
return null;
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Copy 'i' to temp final variable" "true"
|
||||
class ParamTypeBug {
|
||||
private static String strings[] = new String[]{ "a", "b", "c" };
|
||||
|
||||
public static void main(final String ... args){
|
||||
if (args.length == 1){
|
||||
for(int i = 0; i < strings.length; i++) {
|
||||
final int finalI = i;
|
||||
new Thread(){
|
||||
public void run(){
|
||||
new String(strings[finalI]);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Copy 'i' to temp final variable" "true"
|
||||
class ParamTypeBug {
|
||||
private static String strings[] = new String[]{ "a", "b", "c" };
|
||||
|
||||
public static void main(final String ... args){
|
||||
if (args.length == 1){
|
||||
for(int i = 0; i < strings.length; i++)
|
||||
new Thread(){
|
||||
public void run(){
|
||||
new String(strings[<caret>i]);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user