mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Introduce field - don't offer initializing in constructor for static fields (IDEA-341676)
GitOrigin-RevId: 761d6740ac1302a8bf1615225a6757b678d92f37
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c0997ef509
commit
7157fcb5e8
+5
-7
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.refactoring.introduceField;
|
||||
|
||||
import com.intellij.codeInsight.TestFrameworks;
|
||||
@@ -143,8 +143,8 @@ public class IntroduceFieldDialogPanel extends IntroduceFieldCentralPanel {
|
||||
myRbInConstructor = new JRadioButton();
|
||||
myRbInConstructor.setFocusable(false);
|
||||
myRbInConstructor.setText(RefactoringBundle.message("class.constructors.radio"));
|
||||
|
||||
|
||||
boolean inOnlyConstructor = myIsCurrentMethodConstructor && myParentClass.getConstructors().length == 1;
|
||||
myRbInConstructor.setEnabled(!myWillBeDeclaredStatic && !inOnlyConstructor);
|
||||
|
||||
initializationPanel.add(myRbInCurrentMethod);
|
||||
initializationPanel.add(myRbInFieldDeclaration);
|
||||
@@ -171,9 +171,6 @@ public class IntroduceFieldDialogPanel extends IntroduceFieldCentralPanel {
|
||||
myRbInFieldDeclaration.addItemListener(finalUpdater);
|
||||
if (myRbInSetUp != null) myRbInSetUp.addItemListener(finalUpdater);
|
||||
|
||||
// modifiersPanel.add(myCbFinal);
|
||||
// modifiersPanel.add(myCbStatic);
|
||||
|
||||
JPanel groupPanel = new JPanel(new GridLayout(1, 2));
|
||||
groupPanel.add(initializationPanel);
|
||||
|
||||
@@ -190,7 +187,8 @@ public class IntroduceFieldDialogPanel extends IntroduceFieldCentralPanel {
|
||||
if (locals) {
|
||||
myRbInFieldDeclaration.setEnabled(false);
|
||||
}
|
||||
myRbInConstructor.setEnabled(initializedInConstructor);
|
||||
boolean inOnlyConstructor = myIsCurrentMethodConstructor && myParentClass.getConstructors().length == 1;
|
||||
myRbInConstructor.setEnabled(initializedInConstructor && !myWillBeDeclaredStatic && !inOnlyConstructor);
|
||||
enableFinal(false);
|
||||
if (myRbInSetUp != null){
|
||||
if (!initializedInSetup) {
|
||||
|
||||
+6
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.refactoring.introduceField;
|
||||
|
||||
import com.intellij.codeInsight.TestFrameworks;
|
||||
@@ -25,7 +25,7 @@ import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel {
|
||||
private @Nullable JComboBox myInitializerCombo;
|
||||
private @Nullable JComboBox<BaseExpressionToFieldHandler.InitializationPlace> myInitializerCombo;
|
||||
private DefaultComboBoxModel<BaseExpressionToFieldHandler.InitializationPlace> myInitialisersPlaceModel;
|
||||
|
||||
public IntroduceFieldPopupPanel(PsiClass parentClass,
|
||||
@@ -50,6 +50,10 @@ public class IntroduceFieldPopupPanel extends IntroduceFieldCentralPanel {
|
||||
if (!myAllowInitInMethod) {
|
||||
myInitialisersPlaceModel.removeElement(BaseExpressionToFieldHandler.InitializationPlace.IN_CURRENT_METHOD);
|
||||
}
|
||||
boolean inOnlyConstructor = myIsCurrentMethodConstructor && myParentClass.getConstructors().length == 1;
|
||||
if (myWillBeDeclaredStatic || inOnlyConstructor) {
|
||||
myInitialisersPlaceModel.removeElement(BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR);
|
||||
}
|
||||
} else {
|
||||
myInitialisersPlaceModel.removeAllElements();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user