diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/membersManager/MembersConflictDialog.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/membersManager/MembersConflictDialog.java index ca195332..83d83110 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/membersManager/MembersConflictDialog.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/membersManager/MembersConflictDialog.java @@ -15,18 +15,18 @@ */ package com.jetbrains.python.impl.refactoring.classes.membersManager; -import java.util.Collection; - -import jakarta.annotation.Nonnull; - +import com.jetbrains.python.psi.PyClass; +import consulo.language.editor.refactoring.localize.RefactoringLocalize; import consulo.language.editor.refactoring.ui.ConflictsDialog; import consulo.language.editor.refactoring.ui.RefactoringUIUtil; -import consulo.project.Project; import consulo.language.psi.PsiElement; -import consulo.language.editor.refactoring.RefactoringBundle; +import consulo.localize.LocalizeValue; +import consulo.project.Project; +import consulo.python.impl.localize.PyLocalize; import consulo.util.collection.MultiMap; -import com.jetbrains.python.impl.PyBundle; -import com.jetbrains.python.psi.PyClass; +import jakarta.annotation.Nonnull; + +import java.util.Collection; /** * Displays error messages about fact that destination class already contains some member infos @@ -34,43 +34,49 @@ * * @author Ilya.Kazakevich */ -public class MembersConflictDialog extends ConflictsDialog -{ - /** - * @param project project under refactoring - * @param duplicatesConflict duplicates conflicts : that means destination class has the same member. - * If member "foo" already exists in class "bar": pass [bar] -] [foo]. - * @param dependenciesConflicts dependency conflict: list of elements used by member under refactoring and would not be available - * at new destination. If user wants to move method, that uses field "bar" which would not be available at new class, - * pass [bar] field - */ - public MembersConflictDialog(@Nonnull final Project project, @Nonnull final MultiMap> duplicatesConflict, @Nonnull final Collection> - dependenciesConflicts) - { - super(project, convertDescription(duplicatesConflict, dependenciesConflicts), null, true, false); - } - - @Nonnull - private static MultiMap convertDescription(@Nonnull final MultiMap> duplicateConflictDescriptions, - @Nonnull final Collection> dependenciesConflicts) - { - final MultiMap result = new MultiMap<>(); - for(final PyClass aClass : duplicateConflictDescriptions.keySet()) - { - for(final PyMemberInfo pyMemberInfo : duplicateConflictDescriptions.get(aClass)) - { - final String message = RefactoringBundle.message("0.already.contains.a.1", RefactoringUIUtil.getDescription(aClass, false), RefactoringUIUtil.getDescription(pyMemberInfo.getMember(), - false)); - result.putValue(aClass, message); - } - } +public class MembersConflictDialog extends ConflictsDialog { + /** + * @param project project under refactoring + * @param duplicatesConflict duplicates conflicts : that means destination class has the same member. + * If member "foo" already exists in class "bar": pass [bar] -] [foo]. + * @param dependenciesConflicts dependency conflict: list of elements used by member under refactoring and would not be available + * at new destination. If user wants to move method, that uses field "bar" which would not be available at new class, + * pass [bar] field + */ + public MembersConflictDialog( + @Nonnull Project project, + @Nonnull MultiMap> duplicatesConflict, + @Nonnull Collection> dependenciesConflicts + ) { + super(project, convertDescription(duplicatesConflict, dependenciesConflicts), null, true, false); + } - for(final PyMemberInfo memberUnderConflict : dependenciesConflicts) - { - result.putValue(memberUnderConflict.getMember(), PyBundle.message("refactoring.will.not.be.accessible", RefactoringUIUtil.getDescription(memberUnderConflict.getMember(), false))); - } + @Nonnull + private static MultiMap convertDescription( + @Nonnull MultiMap> duplicateConflictDescriptions, + @Nonnull Collection> dependenciesConflicts + ) { + MultiMap result = new MultiMap<>(); + for (PyClass aClass : duplicateConflictDescriptions.keySet()) { + for (PyMemberInfo pyMemberInfo : duplicateConflictDescriptions.get(aClass)) { + LocalizeValue message = RefactoringLocalize.zeroAlreadyContainsA1( + RefactoringUIUtil.getDescription(aClass, false), + RefactoringUIUtil.getDescription( + pyMemberInfo.getMember(), + false + ) + ); + result.putValue(aClass, message); + } + } + for (PyMemberInfo memberUnderConflict : dependenciesConflicts) { + result.putValue( + memberUnderConflict.getMember(), + PyLocalize.refactoringWillNotBeAccessible(RefactoringUIUtil.getDescription(memberUnderConflict.getMember(), false)) + ); + } - return result; - } + return result; + } } diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/rename/RenamePyElementProcessor.java b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/rename/RenamePyElementProcessor.java index b2265b90..bc79bfda 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/rename/RenamePyElementProcessor.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/refactoring/rename/RenamePyElementProcessor.java @@ -15,9 +15,11 @@ */ package com.jetbrains.python.impl.refactoring.rename; +import consulo.annotation.access.RequiredReadAction; import consulo.language.editor.refactoring.rename.RenamePsiElementProcessor; import consulo.language.psi.PsiElement; import consulo.language.psi.util.PsiTreeUtil; +import consulo.localize.LocalizeValue; import consulo.util.collection.MultiMap; import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; import com.jetbrains.python.psi.PyClass; @@ -29,55 +31,62 @@ /** * @author yole */ -public abstract class RenamePyElementProcessor extends RenamePsiElementProcessor -{ - @Override - public void findExistingNameConflicts(PsiElement element, String newName, MultiMap conflicts) - { - PyElement container = PsiTreeUtil.getParentOfType(element, ScopeOwner.class); - if(container instanceof PyFile) - { - PyFile pyFile = (PyFile) container; - PyClass conflictingClass = pyFile.findTopLevelClass(newName); - if(conflictingClass != null) - { - conflicts.putValue(conflictingClass, "A class named '" + newName + "' is already defined in " + pyFile.getName()); - } - PyFunction conflictingFunction = pyFile.findTopLevelFunction(newName); - if(conflictingFunction != null) - { - conflicts.putValue(conflictingFunction, "A function named '" + newName + "' is already defined in " + pyFile.getName()); - } - PyTargetExpression conflictingVariable = pyFile.findTopLevelAttribute(newName); - if(conflictingVariable != null) - { - conflicts.putValue(conflictingFunction, "A variable named '" + newName + "' is already defined in " + pyFile.getName()); - } - } - else if(container instanceof PyClass) - { - PyClass pyClass = (PyClass) container; - PyClass conflictingClass = pyClass.findNestedClass(newName, true); - if(conflictingClass != null) - { - conflicts.putValue(conflictingClass, "A class named '" + newName + "' is already defined in class '" + pyClass.getName() + "'"); - } - PyFunction conflictingFunction = pyClass.findMethodByName(newName, true, null); - if(conflictingFunction != null) - { - conflicts.putValue(conflictingFunction, "A function named '" + newName + "' is already defined in class '" + pyClass.getName() + "'"); - } - PyTargetExpression conflictingAttribute = pyClass.findClassAttribute(newName, true, null); - if(conflictingAttribute != null) - { - conflicts.putValue(conflictingAttribute, "An attribute named '" + newName + "' is already defined in class '" + pyClass.getName() + "'"); - } - } - } +public abstract class RenamePyElementProcessor extends RenamePsiElementProcessor { + @Override + @RequiredReadAction + public void findExistingNameConflicts(PsiElement element, String newName, MultiMap conflicts) { + PyElement container = PsiTreeUtil.getParentOfType(element, ScopeOwner.class); + if (container instanceof PyFile pyFile) { + PyClass conflictingClass = pyFile.findTopLevelClass(newName); + if (conflictingClass != null) { + conflicts.putValue( + conflictingClass, + LocalizeValue.localizeTODO("A class named '" + newName + "' is already defined in " + pyFile.getName()) + ); + } + PyFunction conflictingFunction = pyFile.findTopLevelFunction(newName); + if (conflictingFunction != null) { + conflicts.putValue( + conflictingFunction, + LocalizeValue.localizeTODO("A function named '" + newName + "' is already defined in " + pyFile.getName()) + ); + } + PyTargetExpression conflictingVariable = pyFile.findTopLevelAttribute(newName); + if (conflictingVariable != null) { + conflicts.putValue( + conflictingFunction, + LocalizeValue.localizeTODO("A variable named '" + newName + "' is already defined in " + pyFile.getName()) + ); + } + } + else if (container instanceof PyClass) { + PyClass pyClass = (PyClass) container; + PyClass conflictingClass = pyClass.findNestedClass(newName, true); + if (conflictingClass != null) { + conflicts.putValue( + conflictingClass, + LocalizeValue.localizeTODO("A class named '" + newName + "' is already defined in class '" + pyClass.getName() + "'") + ); + } + PyFunction conflictingFunction = pyClass.findMethodByName(newName, true, null); + if (conflictingFunction != null) { + conflicts.putValue( + conflictingFunction, + LocalizeValue.localizeTODO("A function named '" + newName + "' is already defined in class '" + pyClass.getName() + "'") + ); + } + PyTargetExpression conflictingAttribute = pyClass.findClassAttribute(newName, true, null); + if (conflictingAttribute != null) { + conflicts.putValue( + conflictingAttribute, + LocalizeValue.localizeTODO("An attribute named '" + newName + "' is already defined in class '" + pyClass.getName() + "'") + ); + } + } + } - @Override - public String getHelpID(PsiElement element) - { - return "python.reference.rename"; - } + @Override + public String getHelpID(PsiElement element) { + return "python.reference.rename"; + } }