diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/JavaVariableInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/JavaVariableInplaceIntroducer.java index da2362e4d463..3ceb522cef64 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/JavaVariableInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/JavaVariableInplaceIntroducer.java @@ -212,12 +212,12 @@ public class JavaVariableInplaceIntroducer extends AbstractJavaInplaceIntroducer myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); ApplicationManager.getApplication().runWriteAction(() -> { - if (psiVariable.getInitializer() != null) { - appendTypeCasts(getOccurrenceMarkers(), file, myProject, psiVariable); - } if (myConflictResolver != null && myInsertedName != null && isIdentifier(myInsertedName, psiVariable.getLanguage())) { myConflictResolver.apply(psiVariable.getName()); } + if (psiVariable.getInitializer() != null) { + appendTypeCasts(getOccurrenceMarkers(), file, myProject, psiVariable); + } }); } diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceVariable/conflictWithFieldNoCast.java b/java/java-tests/testData/refactoring/inplaceIntroduceVariable/conflictWithFieldNoCast.java new file mode 100644 index 000000000000..148720e2e4f2 --- /dev/null +++ b/java/java-tests/testData/refactoring/inplaceIntroduceVariable/conflictWithFieldNoCast.java @@ -0,0 +1,8 @@ +class Test { + + private int[][] weights; + + public void out(int u) { + System.out.println(weights); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceVariable/conflictWithFieldNoCast_after.java b/java/java-tests/testData/refactoring/inplaceIntroduceVariable/conflictWithFieldNoCast_after.java new file mode 100644 index 000000000000..50c5418dc497 --- /dev/null +++ b/java/java-tests/testData/refactoring/inplaceIntroduceVariable/conflictWithFieldNoCast_after.java @@ -0,0 +1,9 @@ +class Test { + + private int[][] weights; + + public void out(int u) { + int[][] weights = this.weights; + System.out.println(weights); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceVariableTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceVariableTest.java index 732677495101..321a3b1d9970 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceVariableTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceVariableTest.java @@ -143,6 +143,15 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe }); } + public void testConflictWithFieldNoCast() throws Exception { + doTest(new Pass() { + @Override + public void pass(AbstractInplaceIntroducer introducer) { + type("weights"); + } + }); + } + public void testCast() throws Exception { doTestTypeChange("Integer"); }