introduce variable: ensure first conflicts are resolved and then type assignability is checked (IDEA-159366)

This commit is contained in:
Anna Kozlova
2016-08-12 16:08:28 +03:00
parent a8329b0821
commit 1efdbd06df
4 changed files with 29 additions and 3 deletions
@@ -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);
}
});
}
@@ -0,0 +1,8 @@
class Test {
private int[][] weights;
public void out(int u) {
System.out.println(weig<caret>hts);
}
}
@@ -0,0 +1,9 @@
class Test {
private int[][] weights;
public void out(int u) {
int[][] weights = this.weights;
System.out.println(weights);
}
}
@@ -143,6 +143,15 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
});
}
public void testConflictWithFieldNoCast() throws Exception {
doTest(new Pass<AbstractInplaceIntroducer>() {
@Override
public void pass(AbstractInplaceIntroducer introducer) {
type("weights");
}
});
}
public void testCast() throws Exception {
doTestTypeChange("Integer");
}