From f103741944deef34bdb56f2362fdd15257993387 Mon Sep 17 00:00:00 2001 From: UNV Date: Sun, 21 Dec 2025 21:32:11 +0300 Subject: [PATCH] Localizing refactoring handlers after platform update. --- .../classes/PyClassRefactoringHandler.java | 13 +- .../PyExtractSuperclassHandler.java | 105 ++++----- .../classes/pullUp/PyPullUpHandler.java | 96 ++++---- .../classes/pullUp/PyPullUpProcessor.java | 80 ++++--- .../classes/pullUp/PyPullUpViewSwingImpl.java | 208 ++++++++---------- .../classes/pushDown/PyPushDownHandler.java | 101 ++++----- .../classes/pushDown/PyPushDownProcessor.java | 115 +++++----- .../PyInvertBooleanProcessor.java | 13 +- .../rename/RenamePyFileProcessor.java | 115 +++++----- 9 files changed, 423 insertions(+), 423 deletions(-) diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/PyClassRefactoringHandler.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/PyClassRefactoringHandler.java index 5ecb9e12..e7e3f5c0 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/PyClassRefactoringHandler.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/PyClassRefactoringHandler.java @@ -15,7 +15,6 @@ */ package com.jetbrains.python.impl.refactoring.classes; -import com.jetbrains.python.impl.PyBundle; import com.jetbrains.python.impl.psi.PyUtil; import com.jetbrains.python.psi.PyClass; import consulo.codeEditor.CaretModel; @@ -28,6 +27,7 @@ import consulo.language.editor.refactoring.util.CommonRefactoringUtil; import consulo.language.psi.PsiElement; import consulo.language.psi.PsiFile; +import consulo.localize.LocalizeValue; import consulo.project.Project; import consulo.python.impl.localize.PyLocalize; import consulo.ui.annotation.RequiredUIAccess; @@ -61,7 +61,7 @@ public void invoke(@Nonnull Project project, Editor editor, PsiFile file, DataCo CommonRefactoringUtil.showErrorHint( project, editor, - PyLocalize.refactoringIntroduceSelectionError().get(), + PyLocalize.refactoringIntroduceSelectionError(), getTitle(), "members.pull.up" ); @@ -89,7 +89,7 @@ private void doRefactor( CommonRefactoringUtil.checkReadOnlyStatus(project, file); PyClass clazz = PyUtil.getContainingClassOrSelf(element1); - if (!inClass(clazz, project, editor, "refactoring.pull.up.error.cannot.perform.refactoring.not.inside.class")) { + if (!inClass(clazz, project, editor, PyLocalize.refactoringPullUpErrorCannotPerformRefactoringNotInsideClass())) { return; } assert clazz != null; @@ -107,15 +107,16 @@ protected abstract void doRefactorImpl( ); @RequiredUIAccess - protected boolean inClass(@Nullable PyClass clazz, @Nonnull Project project, Editor editor, String errorMessageId) { + protected boolean inClass(@Nullable PyClass clazz, @Nonnull Project project, Editor editor, LocalizeValue errorMessage) { if (clazz == null) { - CommonRefactoringUtil.showErrorHint(project, editor, PyBundle.message(errorMessageId), getTitle(), getHelpId()); + CommonRefactoringUtil.showErrorHint(project, editor, errorMessage, getTitle(), getHelpId()); return false; } return true; } - protected abstract String getTitle(); + @Nonnull + protected abstract LocalizeValue getTitle(); protected abstract String getHelpId(); diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/extractSuperclass/PyExtractSuperclassHandler.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/extractSuperclass/PyExtractSuperclassHandler.java index bc410f8b..4bb87914 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/extractSuperclass/PyExtractSuperclassHandler.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/extractSuperclass/PyExtractSuperclassHandler.java @@ -15,67 +15,74 @@ */ package com.jetbrains.python.impl.refactoring.classes.extractSuperclass; -import jakarta.annotation.Nonnull; - -import consulo.codeEditor.Editor; -import consulo.language.editor.refactoring.RefactoringBundle; -import consulo.language.editor.refactoring.util.CommonRefactoringUtil; -import consulo.project.Project; -import com.jetbrains.python.impl.PyBundle; -import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.impl.psi.PyUtil; import com.jetbrains.python.impl.refactoring.classes.PyClassRefactoringHandler; import com.jetbrains.python.impl.refactoring.classes.PyMemberInfoStorage; import com.jetbrains.python.impl.vp.Creator; import com.jetbrains.python.impl.vp.ViewPresenterUtils; +import com.jetbrains.python.psi.PyClass; +import consulo.codeEditor.Editor; +import consulo.language.editor.refactoring.localize.RefactoringLocalize; +import consulo.language.editor.refactoring.util.CommonRefactoringUtil; +import consulo.localize.LocalizeValue; +import consulo.project.Project; +import consulo.python.impl.localize.PyLocalize; +import consulo.ui.annotation.RequiredUIAccess; +import jakarta.annotation.Nonnull; /** * @author Dennis.Ushakov */ -public class PyExtractSuperclassHandler extends PyClassRefactoringHandler -{ - public static final String REFACTORING_NAME = RefactoringBundle.message("extract.superclass.title"); - - - @Override - protected void doRefactorImpl(@Nonnull final Project project, @Nonnull final PyClass classUnderRefactoring, @Nonnull final PyMemberInfoStorage infoStorage, @Nonnull final Editor editor) - { - //TODO: Move to presenter - if(PyUtil.filterOutObject(infoStorage.getClassMemberInfos(classUnderRefactoring)).isEmpty()) - { - CommonRefactoringUtil.showErrorHint(project, editor, PyBundle.message("refactoring.extract.super.class.no.members.allowed"), RefactoringBundle.message("extract.superclass.elements" + - ".header"), null); - return; - } +public class PyExtractSuperclassHandler extends PyClassRefactoringHandler { + public static final LocalizeValue REFACTORING_NAME = RefactoringLocalize.extractSuperclassTitle(); - ViewPresenterUtils.linkViewWithPresenterAndLaunch(PyExtractSuperclassPresenter.class, PyExtractSuperclassView.class, new Creator() - { - @Nonnull - @Override - public PyExtractSuperclassPresenter createPresenter(@Nonnull final PyExtractSuperclassView view) - { - return new PyExtractSuperclassPresenterImpl(view, classUnderRefactoring, infoStorage); - } + @Override + @RequiredUIAccess + protected void doRefactorImpl( + @Nonnull final Project project, + @Nonnull final PyClass classUnderRefactoring, + @Nonnull final PyMemberInfoStorage infoStorage, + @Nonnull Editor editor + ) { + //TODO: Move to presenter + if (PyUtil.filterOutObject(infoStorage.getClassMemberInfos(classUnderRefactoring)).isEmpty()) { + CommonRefactoringUtil.showErrorHint( + project, + editor, + PyLocalize.refactoringExtractSuperClassNoMembersAllowed(), + RefactoringLocalize.extractSuperclassElementsHeader(), + null + ); + return; + } - @Nonnull - @Override - public PyExtractSuperclassView createView(@Nonnull final PyExtractSuperclassPresenter presenter) - { - return new PyExtractSuperclassViewSwingImpl(classUnderRefactoring, project, presenter); - } - }); - } + ViewPresenterUtils.linkViewWithPresenterAndLaunch( + PyExtractSuperclassPresenter.class, + PyExtractSuperclassView.class, + new Creator<>() { + @Nonnull + @Override + public PyExtractSuperclassPresenter createPresenter(@Nonnull PyExtractSuperclassView view) { + return new PyExtractSuperclassPresenterImpl(view, classUnderRefactoring, infoStorage); + } + @Nonnull + @Override + public PyExtractSuperclassView createView(@Nonnull PyExtractSuperclassPresenter presenter) { + return new PyExtractSuperclassViewSwingImpl(classUnderRefactoring, project, presenter); + } + } + ); + } - @Override - protected String getTitle() - { - return REFACTORING_NAME; - } + @Nonnull + @Override + protected LocalizeValue getTitle() { + return REFACTORING_NAME; + } - @Override - protected String getHelpId() - { - return "refactoring.extractSuperclass"; - } + @Override + protected String getHelpId() { + return "refactoring.extractSuperclass"; + } } diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpHandler.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpHandler.java index 6ebccb9d..13dfd7ca 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpHandler.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpHandler.java @@ -15,65 +15,67 @@ */ package com.jetbrains.python.impl.refactoring.classes.pullUp; -import jakarta.annotation.Nonnull; - -import consulo.codeEditor.Editor; -import consulo.project.Project; -import com.jetbrains.python.impl.PyBundle; -import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.impl.refactoring.classes.PyClassRefactoringHandler; import com.jetbrains.python.impl.refactoring.classes.PyMemberInfoStorage; import com.jetbrains.python.impl.vp.Creator; import com.jetbrains.python.impl.vp.ViewPresenterUtils; +import com.jetbrains.python.psi.PyClass; +import consulo.codeEditor.Editor; +import consulo.localize.LocalizeValue; +import consulo.project.Project; +import consulo.python.impl.localize.PyLocalize; +import jakarta.annotation.Nonnull; /** - * @author: Dennis.Ushakov + * @author Dennis.Ushakov */ -public class PyPullUpHandler extends PyClassRefactoringHandler -{ - public static final String REFACTORING_NAME = PyBundle.message("refactoring.pull.up.dialog.title"); - - @Override - protected void doRefactorImpl(@Nonnull final Project project, @Nonnull final PyClass classUnderRefactoring, @Nonnull final PyMemberInfoStorage infoStorage, @Nonnull final Editor editor) - { - //TODO: Move to vp (presenter) as well - final PyPullUpNothingToRefactorMessage nothingToRefactor = new PyPullUpNothingToRefactorMessage(project, editor, classUnderRefactoring); +public class PyPullUpHandler extends PyClassRefactoringHandler { + public static final LocalizeValue REFACTORING_NAME = PyLocalize.refactoringPullUpDialogTitle(); - if(PyAncestorsUtils.getAncestorsUnderUserControl(classUnderRefactoring).isEmpty()) - { - nothingToRefactor.showNothingToRefactor(); - return; - } + @Override + protected void doRefactorImpl( + @Nonnull final Project project, + @Nonnull final PyClass classUnderRefactoring, + @Nonnull final PyMemberInfoStorage infoStorage, + @Nonnull Editor editor + ) { + //TODO: Move to vp (presenter) as well + final PyPullUpNothingToRefactorMessage nothingToRefactor = + new PyPullUpNothingToRefactorMessage(project, editor, classUnderRefactoring); + if (PyAncestorsUtils.getAncestorsUnderUserControl(classUnderRefactoring).isEmpty()) { + nothingToRefactor.showNothingToRefactor(); + return; + } - ViewPresenterUtils.linkViewWithPresenterAndLaunch(PyPullUpPresenter.class, PyPullUpView.class, new Creator() - { - @Nonnull - @Override - public PyPullUpPresenter createPresenter(@Nonnull final PyPullUpView view) - { - return new PyPullUpPresenterImpl(view, infoStorage, classUnderRefactoring); - } - @Nonnull - @Override - public PyPullUpView createView(@Nonnull final PyPullUpPresenter presenter) - { - return new PyPullUpViewSwingImpl(project, presenter, classUnderRefactoring, nothingToRefactor); - } - }); - } + ViewPresenterUtils.linkViewWithPresenterAndLaunch( + PyPullUpPresenter.class, + PyPullUpView.class, + new Creator<>() { + @Nonnull + @Override + public PyPullUpPresenter createPresenter(@Nonnull PyPullUpView view) { + return new PyPullUpPresenterImpl(view, infoStorage, classUnderRefactoring); + } + @Nonnull + @Override + public PyPullUpView createView(@Nonnull PyPullUpPresenter presenter) { + return new PyPullUpViewSwingImpl(project, presenter, classUnderRefactoring, nothingToRefactor); + } + } + ); + } - @Override - protected String getTitle() - { - return REFACTORING_NAME; - } + @Nonnull + @Override + protected LocalizeValue getTitle() { + return REFACTORING_NAME; + } - @Override - protected String getHelpId() - { - return "refactoring.pullMembersUp"; - } + @Override + protected String getHelpId() { + return "refactoring.pullMembersUp"; + } } diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpProcessor.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpProcessor.java index 8e1e94f7..4bcb6928 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpProcessor.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpProcessor.java @@ -15,58 +15,54 @@ */ package com.jetbrains.python.impl.refactoring.classes.pullUp; -import java.util.Collection; - +import com.jetbrains.python.impl.refactoring.classes.membersManager.PyMemberInfo; +import com.jetbrains.python.impl.refactoring.classes.membersManager.PyMembersRefactoringBaseProcessor; +import com.jetbrains.python.psi.PyClass; +import com.jetbrains.python.psi.PyElement; +import consulo.localize.LocalizeValue; +import consulo.python.impl.localize.PyLocalize; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; -import com.jetbrains.python.impl.PyBundle; -import com.jetbrains.python.psi.PyClass; -import com.jetbrains.python.psi.PyElement; -import com.jetbrains.python.impl.refactoring.classes.membersManager.PyMemberInfo; -import com.jetbrains.python.impl.refactoring.classes.membersManager.PyMembersRefactoringBaseProcessor; +import java.util.Collection; /** * @author Ilya.Kazakevich */ -class PyPullUpProcessor extends PyMembersRefactoringBaseProcessor -{ - - PyPullUpProcessor(@Nonnull final PyClass from, @Nonnull final PyClass to, @Nonnull final Collection> membersToMove) - { - super(from.getProject(), membersToMove, from, to); - } - +class PyPullUpProcessor extends PyMembersRefactoringBaseProcessor { + PyPullUpProcessor( + @Nonnull PyClass from, + @Nonnull PyClass to, + @Nonnull Collection> membersToMove + ) { + super(from.getProject(), membersToMove, from, to); + } - @Override - protected String getCommandName() - { - return PyPullUpHandler.REFACTORING_NAME; - } + @Nonnull + @Override + protected LocalizeValue getCommandName() { + return PyPullUpHandler.REFACTORING_NAME; + } - @Override - public String getProcessedElementsHeader() - { - return PyBundle.message("refactoring.pull.up.dialog.move.members.to.class"); - } + @Override + public String getProcessedElementsHeader() { + return PyLocalize.refactoringPullUpDialogMoveMembersToClass().get(); + } - @Override - public String getCodeReferencesText(final int usagesCount, final int filesCount) - { - return PyBundle.message("refactoring.pull.up.dialog.members.to.be.moved"); - } + @Override + public String getCodeReferencesText(int usagesCount, int filesCount) { + return PyLocalize.refactoringPullUpDialogMembersToBeMoved().get(); + } - @Nullable - @Override - public String getCommentReferencesText(final int usagesCount, final int filesCount) - { - return getCodeReferencesText(usagesCount, filesCount); - } + @Nullable + @Override + public String getCommentReferencesText(int usagesCount, int filesCount) { + return getCodeReferencesText(usagesCount, filesCount); + } - @Nullable - @Override - protected String getRefactoringId() - { - return "refactoring.python.pull.up"; - } + @Nullable + @Override + protected String getRefactoringId() { + return "refactoring.python.pull.up"; + } } diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpViewSwingImpl.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpViewSwingImpl.java index 1b2ebfbd..4b3f0c76 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpViewSwingImpl.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pullUp/PyPullUpViewSwingImpl.java @@ -15,122 +15,108 @@ */ package com.jetbrains.python.impl.refactoring.classes.pullUp; -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; - -import jakarta.annotation.Nonnull; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JLabel; - -import consulo.language.editor.refactoring.RefactoringBundle; -import consulo.project.Project; -import consulo.ui.ex.awt.ComboBox; -import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.impl.refactoring.classes.membersManager.vp.MembersBasedViewSwingImpl; import com.jetbrains.python.impl.refactoring.classes.ui.PyClassCellRenderer; +import com.jetbrains.python.psi.PyClass; +import consulo.language.editor.refactoring.localize.RefactoringLocalize; +import consulo.project.Project; +import consulo.ui.ex.awt.ComboBox; +import consulo.ui.ex.awt.JBUI; +import jakarta.annotation.Nonnull; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; /** * @author Ilya.Kazakevich - * Pull up view implementation + * Pull up view implementation */ -class PyPullUpViewSwingImpl extends MembersBasedViewSwingImpl implements PyPullUpView, ItemListener -{ - @Nonnull - private final ComboBox myParentsCombo; - @Nonnull - private final DefaultComboBoxModel myParentsComboBoxModel; - @Nonnull - private final PyPullUpNothingToRefactorMessage myNothingToRefactorMessage; - - /** - * @param project project where refactoring takes place - * @param presenter presenter for this view - * @param clazz class to refactor - * @param nothingToRefactorMessage class that displays message "nothing to refactor" when presenter calls {@link #showNothingToRefactor()} - */ - PyPullUpViewSwingImpl(@Nonnull final Project project, - @Nonnull final PyPullUpPresenter presenter, - @Nonnull final PyClass clazz, - @Nonnull final PyPullUpNothingToRefactorMessage nothingToRefactorMessage) - { - super(project, presenter, RefactoringBundle.message("members.to.be.pulled.up"), true); - setTitle(PyPullUpHandler.REFACTORING_NAME); - myNothingToRefactorMessage = nothingToRefactorMessage; - - myParentsComboBoxModel = new DefaultComboBoxModel(); - - myParentsCombo = new ComboBox(myParentsComboBoxModel); - myParentsCombo.setRenderer(new PyClassCellRenderer()); - - final JLabel mainLabel = new JLabel(); - mainLabel.setText(RefactoringBundle.message("pull.up.members.to", PyClassCellRenderer.getClassText(clazz))); - mainLabel.setLabelFor(myParentsCombo); - - - myTopPanel.setLayout(new GridBagLayout()); - final GridBagConstraints gbConstraints = new GridBagConstraints(); - - gbConstraints.insets = new Insets(4, 8, 4, 8); - gbConstraints.weighty = 1; - gbConstraints.weightx = 1; - gbConstraints.gridy = 0; - gbConstraints.gridwidth = GridBagConstraints.REMAINDER; - gbConstraints.fill = GridBagConstraints.BOTH; - gbConstraints.anchor = GridBagConstraints.WEST; - myTopPanel.add(mainLabel, gbConstraints); - myTopPanel.add(mainLabel, gbConstraints); - gbConstraints.gridy++; - myTopPanel.add(myParentsCombo, gbConstraints); - - gbConstraints.gridy++; - myCenterPanel.add(myPyMemberSelectionPanel, BorderLayout.CENTER); - } - - @Override - @Nonnull - protected String getHelpId() - { - return "python.reference.pullMembersUp"; - } - - - @Nonnull - @Override - public PyClass getSelectedParent() - { - return (PyClass) myParentsComboBoxModel.getSelectedItem(); - } - - @Override - public void showNothingToRefactor() - { - myNothingToRefactorMessage.showNothingToRefactor(); - } - - @Override - public void configure(@Nonnull final PyPullUpViewInitializationInfo configInfo) - { - super.configure(configInfo); - for(final PyClass parent : configInfo.getParents()) - { - myParentsComboBoxModel.addElement(parent); - } - myPresenter.parentChanged(); - myParentsCombo.addItemListener(this); - } - - @Override - public void itemStateChanged(final ItemEvent e) - { - if(e.getStateChange() == ItemEvent.SELECTED) - { - myPyMemberSelectionPanel.redraw(); - myPresenter.parentChanged(); - } - } +class PyPullUpViewSwingImpl extends MembersBasedViewSwingImpl implements PyPullUpView, ItemListener { + @Nonnull + private final ComboBox myParentsCombo; + @Nonnull + private final DefaultComboBoxModel myParentsComboBoxModel; + @Nonnull + private final PyPullUpNothingToRefactorMessage myNothingToRefactorMessage; + + /** + * @param project project where refactoring takes place + * @param presenter presenter for this view + * @param clazz class to refactor + * @param nothingToRefactorMessage class that displays message "nothing to refactor" when presenter calls {@link #showNothingToRefactor()} + */ + PyPullUpViewSwingImpl( + @Nonnull Project project, + @Nonnull PyPullUpPresenter presenter, + @Nonnull PyClass clazz, + @Nonnull PyPullUpNothingToRefactorMessage nothingToRefactorMessage + ) { + super(project, presenter, RefactoringLocalize.membersToBePulledUp().get(), true); + setTitle(PyPullUpHandler.REFACTORING_NAME); + myNothingToRefactorMessage = nothingToRefactorMessage; + + myParentsComboBoxModel = new DefaultComboBoxModel<>(); + + myParentsCombo = new ComboBox(myParentsComboBoxModel); + myParentsCombo.setRenderer(new PyClassCellRenderer()); + + JLabel mainLabel = new JLabel(); + mainLabel.setText(RefactoringLocalize.pullUpMembersTo(PyClassCellRenderer.getClassText(clazz)).get()); + mainLabel.setLabelFor(myParentsCombo); + + myTopPanel.setLayout(new GridBagLayout()); + GridBagConstraints gbConstraints = new GridBagConstraints(); + + gbConstraints.insets = JBUI.insets(4, 8); + gbConstraints.weighty = 1; + gbConstraints.weightx = 1; + gbConstraints.gridy = 0; + gbConstraints.gridwidth = GridBagConstraints.REMAINDER; + gbConstraints.fill = GridBagConstraints.BOTH; + gbConstraints.anchor = GridBagConstraints.WEST; + myTopPanel.add(mainLabel, gbConstraints); + myTopPanel.add(mainLabel, gbConstraints); + gbConstraints.gridy++; + myTopPanel.add(myParentsCombo, gbConstraints); + + gbConstraints.gridy++; + myCenterPanel.add(myPyMemberSelectionPanel, BorderLayout.CENTER); + } + + @Nonnull + @Override + protected String getHelpId() { + return "python.reference.pullMembersUp"; + } + + @Nonnull + @Override + public PyClass getSelectedParent() { + return (PyClass) myParentsComboBoxModel.getSelectedItem(); + } + + @Override + public void showNothingToRefactor() { + myNothingToRefactorMessage.showNothingToRefactor(); + } + + @Override + public void configure(@Nonnull PyPullUpViewInitializationInfo configInfo) { + super.configure(configInfo); + for (PyClass parent : configInfo.getParents()) { + myParentsComboBoxModel.addElement(parent); + } + myPresenter.parentChanged(); + myParentsCombo.addItemListener(this); + } + + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + myPyMemberSelectionPanel.redraw(); + myPresenter.parentChanged(); + } + } } diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pushDown/PyPushDownHandler.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pushDown/PyPushDownHandler.java index 88181e78..8d332d59 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pushDown/PyPushDownHandler.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pushDown/PyPushDownHandler.java @@ -15,67 +15,70 @@ */ package com.jetbrains.python.impl.refactoring.classes.pushDown; -import jakarta.annotation.Nonnull; - -import consulo.codeEditor.Editor; -import consulo.language.editor.refactoring.RefactoringBundle; -import consulo.project.Project; -import consulo.language.editor.refactoring.util.CommonRefactoringUtil; -import consulo.application.util.query.Query; -import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.impl.psi.search.PyClassInheritorsSearch; import com.jetbrains.python.impl.refactoring.classes.PyClassRefactoringHandler; import com.jetbrains.python.impl.refactoring.classes.PyMemberInfoStorage; import com.jetbrains.python.impl.vp.Creator; import com.jetbrains.python.impl.vp.ViewPresenterUtils; +import com.jetbrains.python.psi.PyClass; +import consulo.application.util.query.Query; +import consulo.codeEditor.Editor; +import consulo.language.editor.refactoring.localize.RefactoringLocalize; +import consulo.language.editor.refactoring.util.CommonRefactoringUtil; +import consulo.localize.LocalizeValue; +import consulo.project.Project; +import consulo.ui.annotation.RequiredUIAccess; +import jakarta.annotation.Nonnull; /** * @author Dennis.Ushakov */ -public class PyPushDownHandler extends PyClassRefactoringHandler -{ - public static final String REFACTORING_NAME = RefactoringBundle.message("push.members.down.title"); - - @Override - protected void doRefactorImpl(@Nonnull final Project project, @Nonnull final PyClass classUnderRefactoring, @Nonnull final PyMemberInfoStorage infoStorage, @Nonnull Editor editor) - { +public class PyPushDownHandler extends PyClassRefactoringHandler { + public static final LocalizeValue REFACTORING_NAME = RefactoringLocalize.pushMembersDownTitle(); - //TODO: Move to presenter? - final Query query = PyClassInheritorsSearch.search(classUnderRefactoring, false); - if(query.findFirst() == null) - { - final String message = RefactoringBundle.message("class.0.does.not.have.inheritors", classUnderRefactoring.getName()); - CommonRefactoringUtil.showErrorHint(project, editor, message, getTitle(), getHelpId()); - return; - } + @Override + @RequiredUIAccess + protected void doRefactorImpl( + @Nonnull final Project project, + @Nonnull final PyClass classUnderRefactoring, + @Nonnull final PyMemberInfoStorage infoStorage, + @Nonnull Editor editor + ) { + //TODO: Move to presenter? + Query query = PyClassInheritorsSearch.search(classUnderRefactoring, false); + if (query.findFirst() == null) { + LocalizeValue message = RefactoringLocalize.class0DoesNotHaveInheritors(classUnderRefactoring.getName()); + CommonRefactoringUtil.showErrorHint(project, editor, message, getTitle(), getHelpId()); + return; + } - ViewPresenterUtils.linkViewWithPresenterAndLaunch(PyPushDownPresenter.class, PyPushDownView.class, new Creator() - { - @Nonnull - @Override - public PyPushDownPresenter createPresenter(@Nonnull PyPushDownView view) - { - return new PyPushDownPresenterImpl(project, view, classUnderRefactoring, infoStorage); - } + ViewPresenterUtils.linkViewWithPresenterAndLaunch( + PyPushDownPresenter.class, + PyPushDownView.class, + new Creator<>() { + @Nonnull + @Override + public PyPushDownPresenter createPresenter(@Nonnull PyPushDownView view) { + return new PyPushDownPresenterImpl(project, view, classUnderRefactoring, infoStorage); + } - @Nonnull - @Override - public PyPushDownView createView(@Nonnull PyPushDownPresenter presenter) - { - return new PyPushDownViewSwingImpl(classUnderRefactoring, project, presenter); - } - }); - } + @Nonnull + @Override + public PyPushDownView createView(@Nonnull PyPushDownPresenter presenter) { + return new PyPushDownViewSwingImpl(classUnderRefactoring, project, presenter); + } + } + ); + } - @Override - protected String getTitle() - { - return REFACTORING_NAME; - } + @Nonnull + @Override + protected LocalizeValue getTitle() { + return REFACTORING_NAME; + } - @Override - protected String getHelpId() - { - return "members.push.down"; - } + @Override + protected String getHelpId() { + return "members.push.down"; + } } diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pushDown/PyPushDownProcessor.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pushDown/PyPushDownProcessor.java index 4c890f5c..57bfb125 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pushDown/PyPushDownProcessor.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/pushDown/PyPushDownProcessor.java @@ -15,77 +15,76 @@ */ package com.jetbrains.python.impl.refactoring.classes.pushDown; -import java.util.Collection; - -import jakarta.annotation.Nonnull; -import jakarta.annotation.Nullable; - -import consulo.project.Project; -import consulo.language.editor.refactoring.RefactoringBundle; -import consulo.usage.UsageViewBundle; -import com.jetbrains.python.psi.PyClass; -import com.jetbrains.python.psi.PyElement; import com.jetbrains.python.impl.psi.search.PyClassInheritorsSearch; import com.jetbrains.python.impl.refactoring.classes.membersManager.PyMemberInfo; import com.jetbrains.python.impl.refactoring.classes.membersManager.PyMembersRefactoringBaseProcessor; +import com.jetbrains.python.psi.PyClass; +import com.jetbrains.python.psi.PyElement; +import consulo.language.editor.refactoring.localize.RefactoringLocalize; +import consulo.localize.LocalizeValue; +import consulo.project.Project; +import consulo.usage.localize.UsageLocalize; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; + +import java.util.Collection; /** * @author Dennis.Ushakov */ -public class PyPushDownProcessor extends PyMembersRefactoringBaseProcessor -{ - - private static final String HEADER = RefactoringBundle.message("push.down.members.elements.header", ""); - - public PyPushDownProcessor(@Nonnull final Project project, @Nonnull final Collection> membersToMove, @Nonnull final PyClass from) - { - super(project, membersToMove, from, getChildren(from)); - } +public class PyPushDownProcessor extends PyMembersRefactoringBaseProcessor { + private static final LocalizeValue HEADER = RefactoringLocalize.pushDownMembersElementsHeader(); - @Nonnull - private static PyClass[] getChildren(@Nonnull final PyClass from) - { - final Collection all = getInheritors(from); - return all.toArray(new PyClass[all.size()]); - } + public PyPushDownProcessor( + @Nonnull Project project, + @Nonnull Collection> membersToMove, + @Nonnull PyClass from + ) { + super(project, membersToMove, from, getChildren(from)); + } - /** - * @param from class to check for inheritors - * @return inheritors of class - */ - @Nonnull - static Collection getInheritors(@Nonnull final PyClass from) - { - return PyClassInheritorsSearch.search(from, false).findAll(); - } + @Nonnull + private static PyClass[] getChildren(@Nonnull PyClass from) { + Collection all = getInheritors(from); + return all.toArray(new PyClass[all.size()]); + } + /** + * @param from class to check for inheritors + * @return inheritors of class + */ + @Nonnull + static Collection getInheritors(@Nonnull PyClass from) { + return PyClassInheritorsSearch.search(from, false).findAll(); + } - public String getProcessedElementsHeader() - { - return HEADER; - } + @Override + public String getProcessedElementsHeader() { + return HEADER.get(); + } - public String getCodeReferencesText(int usagesCount, int filesCount) - { - return RefactoringBundle.message("classes.to.push.down.members.to", UsageViewBundle.getReferencesString(usagesCount, filesCount)); - } + @Override + public String getCodeReferencesText(int usagesCount, int filesCount) { + return RefactoringLocalize.classesToPushDownMembersTo( + " (" + UsageLocalize.occurenceInfoReference(usagesCount, filesCount) + ")" + ).get(); + } - @Nullable - public String getCommentReferencesText(int usagesCount, int filesCount) - { - return null; - } + @Nullable + @Override + public String getCommentReferencesText(int usagesCount, int filesCount) { + return null; + } - @Override - protected String getCommandName() - { - return PyPushDownHandler.REFACTORING_NAME; - } + @Nonnull + @Override + protected LocalizeValue getCommandName() { + return PyPushDownHandler.REFACTORING_NAME; + } - @Nullable - @Override - protected String getRefactoringId() - { - return "refactoring.python.push.down"; - } + @Nullable + @Override + protected String getRefactoringId() { + return "refactoring.python.push.down"; + } } diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/invertBoolean/PyInvertBooleanProcessor.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/invertBoolean/PyInvertBooleanProcessor.java index d6cc342a..fac1f019 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/invertBoolean/PyInvertBooleanProcessor.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/invertBoolean/PyInvertBooleanProcessor.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.jetbrains.python.impl.refactoring.invertBoolean; import com.jetbrains.python.PyNames; @@ -29,6 +28,7 @@ import consulo.language.psi.search.ReferencesSearch; import consulo.language.psi.util.PsiTreeUtil; import consulo.language.util.IncorrectOperationException; +import consulo.localize.LocalizeValue; import consulo.ui.annotation.RequiredUIAccess; import consulo.usage.MoveRenameUsageInfo; import consulo.usage.UsageInfo; @@ -39,7 +39,7 @@ import java.util.*; /** - * User : ktisha + * @author ktisha */ public class PyInvertBooleanProcessor extends BaseRefactoringProcessor { private PsiElement myElement; @@ -48,6 +48,7 @@ public class PyInvertBooleanProcessor extends BaseRefactoringProcessor { private final Map myToInvert = new HashMap<>(); private final SmartPointerManager mySmartPointerManager; + @RequiredReadAction public PyInvertBooleanProcessor(@Nonnull PsiElement namedElement, @Nonnull String newName) { super(namedElement.getProject()); myElement = namedElement; @@ -94,7 +95,7 @@ protected UsageInfo[] findUsages() { } for (SmartPsiElementPointer pointer : toInvert) { - PyExpression expression = (PyExpression)pointer.getElement(); + PyExpression expression = (PyExpression) pointer.getElement(); if (!expressionsToUsages.containsKey(expression) && expression != null) { UsageInfo usageInfo = new UsageInfo(expression); expressionsToUsages.put(expression, usageInfo); @@ -141,7 +142,7 @@ else if (element instanceof PyReferenceExpression refExpr) { @Nonnull private static UsageInfo[] extractUsagesForElement(@Nonnull PsiElement element, @Nonnull UsageInfo[] usages) { - ArrayList extractedUsages = new ArrayList<>(usages.length); + List extractedUsages = new ArrayList<>(usages.length); for (UsageInfo usage : usages) { if (usage instanceof MoveRenameUsageInfo usageInfo && element.equals(usageInfo.getReferencedElement())) { extractedUsages.add(usageInfo); @@ -207,7 +208,7 @@ else if (expression instanceof PyPrefixExpression prefixExpression) { @Nonnull @Override - protected String getCommandName() { - return RefactoringLocalize.invertBooleanTitle().get(); + protected LocalizeValue getCommandName() { + return RefactoringLocalize.invertBooleanTitle(); } } diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/rename/RenamePyFileProcessor.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/rename/RenamePyFileProcessor.java index b5d30d0a..330ec29b 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/rename/RenamePyFileProcessor.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/rename/RenamePyFileProcessor.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.jetbrains.python.impl.refactoring.rename; import com.jetbrains.python.PyNames; import com.jetbrains.python.psi.PyFile; import com.jetbrains.python.psi.PyImportElement; import com.jetbrains.python.psi.PyImportStatementBase; +import consulo.annotation.access.RequiredReadAction; import consulo.annotation.component.ExtensionImpl; import consulo.codeEditor.Editor; import consulo.language.editor.refactoring.rename.RenamePsiFileProcessorBase; @@ -29,11 +29,13 @@ import consulo.language.psi.PsiReference; import consulo.language.psi.ResolveResult; import consulo.language.psi.util.PsiTreeUtil; +import consulo.localize.LocalizeValue; import consulo.usage.UsageInfo; import consulo.util.io.FileUtil; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; + import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -44,69 +46,72 @@ */ @ExtensionImpl(id = "pyFile") public class RenamePyFileProcessor extends RenamePsiFileProcessorBase { - @Override - public boolean canProcessElement(@Nonnull PsiElement element) { - return element instanceof PyFile; - } + @Override + public boolean canProcessElement(@Nonnull PsiElement element) { + return element instanceof PyFile; + } - @Override - public PsiElement substituteElementToRename(PsiElement element, @Nullable Editor editor) { - PyFile file = (PyFile) element; - if (file.getName().equals(PyNames.INIT_DOT_PY)) { - return file.getParent(); + @Override + @RequiredReadAction + public PsiElement substituteElementToRename(PsiElement element, @Nullable Editor editor) { + PyFile file = (PyFile) element; + if (PyNames.INIT_DOT_PY.equals(file.getName())) { + return file.getParent(); + } + return element; } - return element; - } - @Nonnull - @Override - public Collection findReferences(PsiElement element) { - final List results = new ArrayList(); - for (PsiReference reference : super.findReferences(element)) { - if (isNotAliasedInImportElement(reference)) { - results.add(reference); - } + @Nonnull + @Override + @RequiredReadAction + public Collection findReferences(PsiElement element) { + List results = new ArrayList<>(); + for (PsiReference reference : super.findReferences(element)) { + if (isNotAliasedInImportElement(reference)) { + results.add(reference); + } + } + return results; } - return results; - } - @Override - public void findCollisions(PsiElement element, - final String newName, - Map allRenames, - List result) { - final String newFileName = FileUtil.getNameWithoutExtension(newName); - if (!PyNames.isIdentifier(newFileName)) { - List usages = new ArrayList(result); - for (UsageInfo usageInfo : usages) { - final PyImportStatementBase importStatement = PsiTreeUtil.getParentOfType(usageInfo.getElement(), PyImportStatementBase.class); - if (importStatement != null) { - result.add(new UnresolvableCollisionUsageInfo(importStatement, element) { - @Override - public String getDescription() { - return "The name '" + newFileName + "' is not a valid Python identifier. Cannot update import statement in '" + - importStatement.getContainingFile().getName() + "'"; + @Override + @RequiredReadAction + public void findCollisions( + PsiElement element, + String newName, + Map allRenames, + List result + ) { + final String newFileName = FileUtil.getNameWithoutExtension(newName); + if (!PyNames.isIdentifier(newFileName)) { + List usages = new ArrayList<>(result); + for (UsageInfo usageInfo : usages) { + final PyImportStatementBase importStatement = + PsiTreeUtil.getParentOfType(usageInfo.getElement(), PyImportStatementBase.class); + if (importStatement != null) { + result.add(new UnresolvableCollisionUsageInfo(importStatement, element) { + @Override + public LocalizeValue getDescription() { + return LocalizeValue.localizeTODO( + "The name '" + newFileName + "' is not a valid Python identifier. Cannot update import statement in '" + + importStatement.getContainingFile().getName() + "'" + ); + } + }); + } } - }); } - } } - } - private static boolean isNotAliasedInImportElement(@Nonnull PsiReference reference) { - boolean include = true; - if (reference instanceof PsiPolyVariantReference) { - final ResolveResult[] results = ((PsiPolyVariantReference)reference).multiResolve(false); - for (ResolveResult result : results) { - final PsiElement resolved = result.getElement(); - if (resolved instanceof PyImportElement) { - if (((PyImportElement)resolved).getAsName() != null) { - include = false; - break; - } + @RequiredReadAction + private static boolean isNotAliasedInImportElement(@Nonnull PsiReference reference) { + if (reference instanceof PsiPolyVariantReference polyRef) { + for (ResolveResult result : polyRef.multiResolve(false)) { + if (result.getElement() instanceof PyImportElement importElem && importElem.getAsName() != null) { + return false; + } + } } - } + return true; } - return include; - } }