mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
inplace introduce: correct types when replace all occurrences/not all occurrences (EA-20168 - assert: PsiJavaCodeReferenceElementImpl.multiResolve)
This commit is contained in:
+18
-6
@@ -48,6 +48,8 @@ import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
|
||||
import com.intellij.refactoring.util.occurences.OccurenceManager;
|
||||
import com.intellij.ui.StateRestoringCheckBox;
|
||||
import com.intellij.ui.TitlePanel;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -261,14 +263,24 @@ public class InplaceIntroduceConstantPopup {
|
||||
}
|
||||
|
||||
public void performInplaceIntroduce() {
|
||||
startIntroduceTemplate(false);
|
||||
startIntroduceTemplate(false, null);
|
||||
}
|
||||
|
||||
private void startIntroduceTemplate(final boolean replaceAllOccurrences) {
|
||||
private void startIntroduceTemplate(final boolean replaceAllOccurrences, @Nullable final PsiType fieldDefaultType) {
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
public void run() {
|
||||
myTypeSelectorManager.setAllOccurences(replaceAllOccurrences);
|
||||
final PsiType defaultType = myTypeSelectorManager.getTypeSelector().getSelectedType();
|
||||
PsiType defaultType = myTypeSelectorManager.getTypeSelector().getSelectedType();
|
||||
if (fieldDefaultType != null) {
|
||||
if (replaceAllOccurrences) {
|
||||
if (ArrayUtil.find(myTypeSelectorManager.getTypesForAll(), fieldDefaultType) != -1) {
|
||||
defaultType = fieldDefaultType;
|
||||
}
|
||||
}
|
||||
else if (ArrayUtil.find(myTypeSelectorManager.getTypesForOne(), fieldDefaultType) != -1) {
|
||||
defaultType = fieldDefaultType;
|
||||
}
|
||||
}
|
||||
final String propName = myLocalVariable != null ? JavaCodeStyleManager
|
||||
.getInstance(myProject).variableNameToPropertyName(myLocalVariable.getName(), VariableKind.LOCAL_VARIABLE) : null;
|
||||
final String[] names = IntroduceConstantDialog.createNameSuggestionGenerator(propName, myExpr, JavaCodeStyleManager.getInstance(myProject))
|
||||
@@ -337,7 +349,7 @@ public class InplaceIntroduceConstantPopup {
|
||||
private SmartTypePointer myFieldTypePointer;
|
||||
|
||||
public FieldInplaceIntroducer(PsiField field) {
|
||||
super(myProject, new TypeExpression(myProject, myTypeSelectorManager.getTypesForAll()),
|
||||
super(myProject, new TypeExpression(myProject, myReplaceAllCb.isSelected() ? myTypeSelectorManager.getTypesForAll() : myTypeSelectorManager.getTypesForOne()),
|
||||
myEditor, field, false,
|
||||
myTypeSelectorManager.getTypesForAll().length > 1,
|
||||
myExpr != null && myExpr.isPhysical() ? myEditor.getDocument().createRangeMarker(myExpr.getTextRange()) : null, InplaceIntroduceConstantPopup.this.getOccurrenceMarkers(),
|
||||
@@ -456,8 +468,8 @@ public class InplaceIntroduceConstantPopup {
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
templateState.gotoEnd(true);
|
||||
myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myFieldTypePointer.getType(), null, myExpr, myOccurrences);
|
||||
startIntroduceTemplate(isReplaceAllOccurrences());
|
||||
myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myExpr, myOccurrences);
|
||||
startIntroduceTemplate(isReplaceAllOccurrences(), myFieldTypePointer.getType());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+17
-6
@@ -35,6 +35,8 @@ import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer;
|
||||
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
|
||||
import com.intellij.refactoring.util.occurences.OccurenceManager;
|
||||
import com.intellij.ui.TitlePanel;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -151,15 +153,24 @@ public class InplaceIntroduceFieldPopup {
|
||||
}
|
||||
|
||||
public void startTemplate() {
|
||||
startTemplate(false);
|
||||
startTemplate(false, null);
|
||||
}
|
||||
|
||||
public void startTemplate(final boolean replaceAllOccurrences) {
|
||||
public void startTemplate(final boolean replaceAllOccurrences, @Nullable final PsiType fieldDefaultType) {
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
public void run() {
|
||||
myTypeSelectorManager.setAllOccurences(replaceAllOccurrences);
|
||||
|
||||
final PsiType defaultType = myTypeSelectorManager.getTypeSelector().getSelectedType();
|
||||
PsiType defaultType = myTypeSelectorManager.getTypeSelector().getSelectedType();
|
||||
if (fieldDefaultType != null) {
|
||||
if (replaceAllOccurrences) {
|
||||
if (ArrayUtil.find(myTypeSelectorManager.getTypesForAll(), fieldDefaultType) != -1) {
|
||||
defaultType = fieldDefaultType;
|
||||
}
|
||||
} else if (ArrayUtil.find(myTypeSelectorManager.getTypesForOne(), fieldDefaultType) != -1){
|
||||
defaultType = fieldDefaultType;
|
||||
}
|
||||
}
|
||||
|
||||
final SuggestedNameInfo suggestedNameInfo =
|
||||
IntroduceFieldDialog.createGenerator(myStatic, myLocalVariable, myInitializerExpression, myLocalVariable != null)
|
||||
@@ -227,7 +238,7 @@ public class InplaceIntroduceFieldPopup {
|
||||
private SmartTypePointer myFieldTypePointer;
|
||||
|
||||
public FieldInplaceIntroducer(PsiVariable psiVariable) {
|
||||
super(myProject, new TypeExpression(myProject, myTypeSelectorManager.getTypesForAll()),
|
||||
super(myProject, new TypeExpression(myProject, myIntroduceFieldPanel.isReplaceAllOccurrences() ? myTypeSelectorManager.getTypesForAll() : myTypeSelectorManager.getTypesForOne()),
|
||||
myEditor, psiVariable, false,
|
||||
myTypeSelectorManager.getTypesForAll().length > 1,
|
||||
myInitializerExpression != null && myInitializerExpression.isPhysical() ? myEditor.getDocument().createRangeMarker(myInitializerExpression.getTextRange()) : null, InplaceIntroduceFieldPopup.this.getOccurrenceMarkers(),
|
||||
@@ -296,8 +307,8 @@ public class InplaceIntroduceFieldPopup {
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
templateState.gotoEnd(true);
|
||||
myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myFieldTypePointer.getType(), null, myInitializerExpression, myOccurrences);
|
||||
startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences());
|
||||
myTypeSelectorManager = new TypeSelectorManagerImpl(myProject, myDefaultParameterTypePointer.getType(), null, myInitializerExpression, myOccurrences);
|
||||
startTemplate(myIntroduceFieldPanel.isReplaceAllOccurrences(), myFieldTypePointer.getType());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+7
-1
@@ -116,7 +116,9 @@ public abstract class IntroduceFieldCentralPanel {
|
||||
if (myCbReplaceAll != null && myAllowInitInMethod) {
|
||||
updateInitializerSelection();
|
||||
}
|
||||
updateTypeSelector();
|
||||
if (shouldUpdateTypeSelector()) {
|
||||
updateTypeSelector();
|
||||
}
|
||||
}
|
||||
};
|
||||
ItemListener finalUpdater = new ItemListener() {
|
||||
@@ -137,6 +139,10 @@ public abstract class IntroduceFieldCentralPanel {
|
||||
protected void updateInitializerSelection() {
|
||||
}
|
||||
|
||||
protected boolean shouldUpdateTypeSelector() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private JPanel appendCheckboxes(ItemListener itemListener) {
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1,1,0,0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0,0,0,0), 0,0);
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
|
||||
+5
@@ -232,6 +232,11 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel {
|
||||
return allowFinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldUpdateTypeSelector() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected JPanel composeWholePanel(JComponent initializerPlacePanel, JPanel checkboxPanel) {
|
||||
final JPanel panel = new JPanel(new GridBagLayout());
|
||||
final GridBagConstraints constraints =
|
||||
|
||||
+3
-2
@@ -456,8 +456,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
|
||||
final IntroduceVariableSettings settings =
|
||||
getSettings(project, editor, expr, occurrences, typeSelectorManager, inFinalContext, hasWriteAccess, validator, choice);
|
||||
if (!settings.isOK()) return;
|
||||
typeSelectorManager.setAllOccurences(choice != OccurrencesChooser.ReplaceChoice.NO);
|
||||
final TypeExpression expression = new TypeExpression(project, typeSelectorManager.getTypesForAll());
|
||||
final boolean allOccurences = choice != OccurrencesChooser.ReplaceChoice.NO;
|
||||
typeSelectorManager.setAllOccurences(allOccurences);
|
||||
final TypeExpression expression = new TypeExpression(project, allOccurences ? typeSelectorManager.getTypesForAll() : typeSelectorManager.getTypesForOne());
|
||||
final RangeMarker exprMarker = editor.getDocument().createRangeMarker(expr.getTextRange());
|
||||
final SuggestedNameInfo suggestedName = getSuggestedName(settings.getSelectedType(), expr);
|
||||
final List<RangeMarker> occurrenceMarkers = new ArrayList<RangeMarker>();
|
||||
|
||||
@@ -133,6 +133,10 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
|
||||
return myTypesForAll;
|
||||
}
|
||||
|
||||
public PsiType[] getTypesForOne() {
|
||||
return myTypesForMain;
|
||||
}
|
||||
|
||||
public PsiType getDefaultType() {
|
||||
if (myDefaultType.isValid()) {
|
||||
return myDefaultType;
|
||||
|
||||
Reference in New Issue
Block a user