[java-refactoring] Refactoring dialog: avoid updating var-type state on every updateControls()

It should be updated only on type change (which happens rarely, especially because in many cases, we do not allow to change the type at all)
Fixes IDEA-360822 Introduce Variable: "Replace all occurrences" (Alt+A) triggers flood of exceptions
Slow operations are still possible but should not cause 'flood'. Given that dialog mode in refactorings is rarely used (it's non-default), current fix looks good enough


(cherry picked from commit 6ad7e2826b11e1f39598e991201ba05620acae84)

IJ-CR-149663

GitOrigin-RevId: 39bd201313a72d262d03283fd93ae5a6a64cecd0
This commit is contained in:
Tagir Valeev
2024-11-19 17:39:30 +00:00
committed by intellij-monorepo-bot
parent 99a6645e5d
commit b0321520e6
@@ -234,7 +234,7 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
myCbVarType.setEnabled(Comparing.equal(myTypeSelector.getSelectedType(), CommonJavaRefactoringUtil.getTypeByExpressionWithExpectedType(myExpression)));
updateVarType();
}
}
});
@@ -246,10 +246,17 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable
panel.add(myCbVarType, gbConstraints);
updateControls();
updateVarType();
return panel;
}
public void updateVarType() {
if (myCbVarType != null) {
myCbVarType.setEnabled(Comparing.equal(myTypeSelector.getSelectedType(), CommonJavaRefactoringUtil.getTypeByExpressionWithExpectedType(myExpression)));
}
}
private void updateControls() {
if (myCbReplaceWrite != null) {
if (myCbReplaceAll.isSelected()) {
@@ -276,10 +283,6 @@ class IntroduceVariableDialog extends DialogWrapper implements IntroduceVariable
myCbFinal.setEnabled(true);
myCbFinal.setSelected(myCbFinalState);
}
if (myCbVarType != null) {
myCbVarType.setEnabled(Comparing.equal(myTypeSelector.getSelectedType(), myExpression.getType()));
}
}
@Override