Skip to content

Commit f1ed3f0

Browse files
authored
Merge pull request #31 from unv-unv/compilation-fix
Fixing compilation of MembersConflictDialog and RenamePyElementProcessor
2 parents cc66466 + fe7d4a5 commit f1ed3f0

File tree

2 files changed

+109
-94
lines changed

2 files changed

+109
-94
lines changed

python-impl/src/main/java/com/jetbrains/python/impl/refactoring/classes/membersManager/MembersConflictDialog.java

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,68 @@
1515
*/
1616
package com.jetbrains.python.impl.refactoring.classes.membersManager;
1717

18-
import java.util.Collection;
19-
20-
import jakarta.annotation.Nonnull;
21-
18+
import com.jetbrains.python.psi.PyClass;
19+
import consulo.language.editor.refactoring.localize.RefactoringLocalize;
2220
import consulo.language.editor.refactoring.ui.ConflictsDialog;
2321
import consulo.language.editor.refactoring.ui.RefactoringUIUtil;
24-
import consulo.project.Project;
2522
import consulo.language.psi.PsiElement;
26-
import consulo.language.editor.refactoring.RefactoringBundle;
23+
import consulo.localize.LocalizeValue;
24+
import consulo.project.Project;
25+
import consulo.python.impl.localize.PyLocalize;
2726
import consulo.util.collection.MultiMap;
28-
import com.jetbrains.python.impl.PyBundle;
29-
import com.jetbrains.python.psi.PyClass;
27+
import jakarta.annotation.Nonnull;
28+
29+
import java.util.Collection;
3030

3131
/**
3232
* Displays error messages about fact that destination class already contains some member infos
3333
* or members under refactoring would not be available at the new place.
3434
*
3535
* @author Ilya.Kazakevich
3636
*/
37-
public class MembersConflictDialog extends ConflictsDialog
38-
{
39-
/**
40-
* @param project project under refactoring
41-
* @param duplicatesConflict duplicates conflicts : that means destination class has the same member.
42-
* If member "foo" already exists in class "bar": pass [bar] -] [foo].
43-
* @param dependenciesConflicts dependency conflict: list of elements used by member under refactoring and would not be available
44-
* at new destination. If user wants to move method, that uses field "bar" which would not be available at new class,
45-
* pass [bar] field
46-
*/
47-
public MembersConflictDialog(@Nonnull final Project project, @Nonnull final MultiMap<PyClass, PyMemberInfo<?>> duplicatesConflict, @Nonnull final Collection<PyMemberInfo<?>>
48-
dependenciesConflicts)
49-
{
50-
super(project, convertDescription(duplicatesConflict, dependenciesConflicts), null, true, false);
51-
}
52-
53-
@Nonnull
54-
private static MultiMap<PsiElement, String> convertDescription(@Nonnull final MultiMap<PyClass, PyMemberInfo<?>> duplicateConflictDescriptions,
55-
@Nonnull final Collection<PyMemberInfo<?>> dependenciesConflicts)
56-
{
57-
final MultiMap<PsiElement, String> result = new MultiMap<>();
58-
for(final PyClass aClass : duplicateConflictDescriptions.keySet())
59-
{
60-
for(final PyMemberInfo<?> pyMemberInfo : duplicateConflictDescriptions.get(aClass))
61-
{
62-
final String message = RefactoringBundle.message("0.already.contains.a.1", RefactoringUIUtil.getDescription(aClass, false), RefactoringUIUtil.getDescription(pyMemberInfo.getMember(),
63-
false));
64-
result.putValue(aClass, message);
65-
}
66-
}
37+
public class MembersConflictDialog extends ConflictsDialog {
38+
/**
39+
* @param project project under refactoring
40+
* @param duplicatesConflict duplicates conflicts : that means destination class has the same member.
41+
* If member "foo" already exists in class "bar": pass [bar] -] [foo].
42+
* @param dependenciesConflicts dependency conflict: list of elements used by member under refactoring and would not be available
43+
* at new destination. If user wants to move method, that uses field "bar" which would not be available at new class,
44+
* pass [bar] field
45+
*/
46+
public MembersConflictDialog(
47+
@Nonnull Project project,
48+
@Nonnull MultiMap<PyClass, PyMemberInfo<?>> duplicatesConflict,
49+
@Nonnull Collection<PyMemberInfo<?>> dependenciesConflicts
50+
) {
51+
super(project, convertDescription(duplicatesConflict, dependenciesConflicts), null, true, false);
52+
}
6753

68-
for(final PyMemberInfo<?> memberUnderConflict : dependenciesConflicts)
69-
{
70-
result.putValue(memberUnderConflict.getMember(), PyBundle.message("refactoring.will.not.be.accessible", RefactoringUIUtil.getDescription(memberUnderConflict.getMember(), false)));
71-
}
54+
@Nonnull
55+
private static MultiMap<PsiElement, LocalizeValue> convertDescription(
56+
@Nonnull MultiMap<PyClass, PyMemberInfo<?>> duplicateConflictDescriptions,
57+
@Nonnull Collection<PyMemberInfo<?>> dependenciesConflicts
58+
) {
59+
MultiMap<PsiElement, LocalizeValue> result = new MultiMap<>();
60+
for (PyClass aClass : duplicateConflictDescriptions.keySet()) {
61+
for (PyMemberInfo<?> pyMemberInfo : duplicateConflictDescriptions.get(aClass)) {
62+
LocalizeValue message = RefactoringLocalize.zeroAlreadyContainsA1(
63+
RefactoringUIUtil.getDescription(aClass, false),
64+
RefactoringUIUtil.getDescription(
65+
pyMemberInfo.getMember(),
66+
false
67+
)
68+
);
69+
result.putValue(aClass, message);
70+
}
71+
}
7272

73+
for (PyMemberInfo<?> memberUnderConflict : dependenciesConflicts) {
74+
result.putValue(
75+
memberUnderConflict.getMember(),
76+
PyLocalize.refactoringWillNotBeAccessible(RefactoringUIUtil.getDescription(memberUnderConflict.getMember(), false))
77+
);
78+
}
7379

74-
return result;
75-
}
80+
return result;
81+
}
7682
}

python-impl/src/main/java/com/jetbrains/python/impl/refactoring/rename/RenamePyElementProcessor.java

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
package com.jetbrains.python.impl.refactoring.rename;
1717

18+
import consulo.annotation.access.RequiredReadAction;
1819
import consulo.language.editor.refactoring.rename.RenamePsiElementProcessor;
1920
import consulo.language.psi.PsiElement;
2021
import consulo.language.psi.util.PsiTreeUtil;
22+
import consulo.localize.LocalizeValue;
2123
import consulo.util.collection.MultiMap;
2224
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
2325
import com.jetbrains.python.psi.PyClass;
@@ -29,55 +31,62 @@
2931
/**
3032
* @author yole
3133
*/
32-
public abstract class RenamePyElementProcessor extends RenamePsiElementProcessor
33-
{
34-
@Override
35-
public void findExistingNameConflicts(PsiElement element, String newName, MultiMap<PsiElement, String> conflicts)
36-
{
37-
PyElement container = PsiTreeUtil.getParentOfType(element, ScopeOwner.class);
38-
if(container instanceof PyFile)
39-
{
40-
PyFile pyFile = (PyFile) container;
41-
PyClass conflictingClass = pyFile.findTopLevelClass(newName);
42-
if(conflictingClass != null)
43-
{
44-
conflicts.putValue(conflictingClass, "A class named '" + newName + "' is already defined in " + pyFile.getName());
45-
}
46-
PyFunction conflictingFunction = pyFile.findTopLevelFunction(newName);
47-
if(conflictingFunction != null)
48-
{
49-
conflicts.putValue(conflictingFunction, "A function named '" + newName + "' is already defined in " + pyFile.getName());
50-
}
51-
PyTargetExpression conflictingVariable = pyFile.findTopLevelAttribute(newName);
52-
if(conflictingVariable != null)
53-
{
54-
conflicts.putValue(conflictingFunction, "A variable named '" + newName + "' is already defined in " + pyFile.getName());
55-
}
56-
}
57-
else if(container instanceof PyClass)
58-
{
59-
PyClass pyClass = (PyClass) container;
60-
PyClass conflictingClass = pyClass.findNestedClass(newName, true);
61-
if(conflictingClass != null)
62-
{
63-
conflicts.putValue(conflictingClass, "A class named '" + newName + "' is already defined in class '" + pyClass.getName() + "'");
64-
}
65-
PyFunction conflictingFunction = pyClass.findMethodByName(newName, true, null);
66-
if(conflictingFunction != null)
67-
{
68-
conflicts.putValue(conflictingFunction, "A function named '" + newName + "' is already defined in class '" + pyClass.getName() + "'");
69-
}
70-
PyTargetExpression conflictingAttribute = pyClass.findClassAttribute(newName, true, null);
71-
if(conflictingAttribute != null)
72-
{
73-
conflicts.putValue(conflictingAttribute, "An attribute named '" + newName + "' is already defined in class '" + pyClass.getName() + "'");
74-
}
75-
}
76-
}
34+
public abstract class RenamePyElementProcessor extends RenamePsiElementProcessor {
35+
@Override
36+
@RequiredReadAction
37+
public void findExistingNameConflicts(PsiElement element, String newName, MultiMap<PsiElement, LocalizeValue> conflicts) {
38+
PyElement container = PsiTreeUtil.getParentOfType(element, ScopeOwner.class);
39+
if (container instanceof PyFile pyFile) {
40+
PyClass conflictingClass = pyFile.findTopLevelClass(newName);
41+
if (conflictingClass != null) {
42+
conflicts.putValue(
43+
conflictingClass,
44+
LocalizeValue.localizeTODO("A class named '" + newName + "' is already defined in " + pyFile.getName())
45+
);
46+
}
47+
PyFunction conflictingFunction = pyFile.findTopLevelFunction(newName);
48+
if (conflictingFunction != null) {
49+
conflicts.putValue(
50+
conflictingFunction,
51+
LocalizeValue.localizeTODO("A function named '" + newName + "' is already defined in " + pyFile.getName())
52+
);
53+
}
54+
PyTargetExpression conflictingVariable = pyFile.findTopLevelAttribute(newName);
55+
if (conflictingVariable != null) {
56+
conflicts.putValue(
57+
conflictingFunction,
58+
LocalizeValue.localizeTODO("A variable named '" + newName + "' is already defined in " + pyFile.getName())
59+
);
60+
}
61+
}
62+
else if (container instanceof PyClass) {
63+
PyClass pyClass = (PyClass) container;
64+
PyClass conflictingClass = pyClass.findNestedClass(newName, true);
65+
if (conflictingClass != null) {
66+
conflicts.putValue(
67+
conflictingClass,
68+
LocalizeValue.localizeTODO("A class named '" + newName + "' is already defined in class '" + pyClass.getName() + "'")
69+
);
70+
}
71+
PyFunction conflictingFunction = pyClass.findMethodByName(newName, true, null);
72+
if (conflictingFunction != null) {
73+
conflicts.putValue(
74+
conflictingFunction,
75+
LocalizeValue.localizeTODO("A function named '" + newName + "' is already defined in class '" + pyClass.getName() + "'")
76+
);
77+
}
78+
PyTargetExpression conflictingAttribute = pyClass.findClassAttribute(newName, true, null);
79+
if (conflictingAttribute != null) {
80+
conflicts.putValue(
81+
conflictingAttribute,
82+
LocalizeValue.localizeTODO("An attribute named '" + newName + "' is already defined in class '" + pyClass.getName() + "'")
83+
);
84+
}
85+
}
86+
}
7787

78-
@Override
79-
public String getHelpID(PsiElement element)
80-
{
81-
return "python.reference.rename";
82-
}
88+
@Override
89+
public String getHelpID(PsiElement element) {
90+
return "python.reference.rename";
91+
}
8392
}

0 commit comments

Comments
 (0)