diff --git a/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConvertToRecordProcessor.java b/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConvertToRecordProcessor.java index 4e0a8ae36a52..f7bdf6237401 100644 --- a/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConvertToRecordProcessor.java +++ b/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConvertToRecordProcessor.java @@ -154,7 +154,7 @@ public class ConvertToRecordProcessor extends BaseRefactoringProcessor { } } RefactoringConflictsUtil.getInstance() - .analyzeAccessibilityConflictsAfterMemberMove(conflictingFields, myRecordCandidate.getPsiClass(), conflicts, PRIVATE); + .analyzeAccessibilityConflictsAfterMemberMove(myRecordCandidate.getPsiClass(), conflicts, PRIVATE, conflictingFields); if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) { if (!ConflictsInTestsException.isTestIgnore()) { diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodProcessor.java b/java/java-impl-refactorings/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodProcessor.java index 41d02b43aef3..79f1fe1cb5b5 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodProcessor.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodProcessor.java @@ -172,7 +172,7 @@ public final class ConvertToInstanceMethodProcessor extends BaseRefactoringProce MultiMap conflicts = new MultiMap<>(); final Set methods = Collections.singleton(myMethod); //check that method to call would be still accessible from the call places - RefactoringConflictsUtil.getInstance().analyzeAccessibilityConflictsAfterMemberMove(methods, myTargetClass, conflicts, myNewVisibility); + RefactoringConflictsUtil.getInstance().analyzeAccessibilityConflictsAfterMemberMove(myTargetClass, conflicts, myNewVisibility, methods); //additionally check that body of method contains only accessible in the inheritors references if (myTargetClass.isInterface() && !PsiUtil.isLanguageLevel8OrHigher(myTargetClass)) { for (final UsageInfo usage : usagesIn) { diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java b/java/java-impl-refactorings/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java index a017204e2f3c..76f572fedf43 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java @@ -260,8 +260,9 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori Set movedMembers = new HashSet<>(pushDownConflicts.getMovedMembers()); movedMembers.addAll(Arrays.asList(mySuperClass.getConstructors())); RefactoringConflictsUtil.getInstance() - .analyzeAccessibilityConflictsAfterMemberMove(movedMembers, targetClass, conflicts, null, targetClass, pushDownConflicts.getAbstractMembers(), - Conditions.alwaysTrue()); + .analyzeAccessibilityConflictsAfterMemberMove(movedMembers, targetClass, null, targetClass, + pushDownConflicts.getAbstractMembers(), Conditions.alwaysTrue(), conflicts + ); } } } diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/memberPullUp/PullUpConflictsUtil.java b/java/java-impl-refactorings/src/com/intellij/refactoring/memberPullUp/PullUpConflictsUtil.java index a16e68dabbe5..d2e27f037313 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/memberPullUp/PullUpConflictsUtil.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/memberPullUp/PullUpConflictsUtil.java @@ -111,8 +111,9 @@ public final class PullUpConflictsUtil { } } RefactoringConflictsUtil.getInstance() - .analyzeAccessibilityConflictsAfterMemberMove(movedMembers, superClass, conflicts, VisibilityUtil.ESCALATE_VISIBILITY, targetRepresentativeElement, - abstrMethods, Conditions.alwaysTrue()); + .analyzeAccessibilityConflictsAfterMemberMove(movedMembers, superClass, VisibilityUtil.ESCALATE_VISIBILITY, + targetRepresentativeElement, abstrMethods, Conditions.alwaysTrue(), conflicts + ); if (superClass != null) { if (movedMembers2Super) { checkSuperclassMembers(superClass, infos, conflicts); diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/memberPushDown/PushDownConflicts.java b/java/java-impl-refactorings/src/com/intellij/refactoring/memberPushDown/PushDownConflicts.java index bde8f497bcf8..bfeda02b50f5 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/memberPushDown/PushDownConflicts.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/memberPushDown/PushDownConflicts.java @@ -181,8 +181,11 @@ public class PushDownConflicts { } } } - RefactoringConflictsUtil.getInstance().analyzeAccessibilityConflictsAfterMemberMove(myMovedMembers, targetClass, myConflicts, null, context, myAbstractMembers, - ref -> !InheritanceUtil.hasEnclosingInstanceInScope(myClass, ref.getElement(), true, false)); + RefactoringConflictsUtil.getInstance().analyzeAccessibilityConflictsAfterMemberMove(myMovedMembers, targetClass, null, context, + myAbstractMembers, + ref -> !InheritanceUtil.hasEnclosingInstanceInScope(myClass, ref.getElement(), true, false), + myConflicts + ); } diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java b/java/java-impl-refactorings/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java index ef8fc7b02e89..56c7cda48ab8 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java @@ -97,13 +97,14 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{ members.add(myMethod); if (myTargetVariable instanceof PsiField) members.add((PsiMember)myTargetVariable); if (!myTargetClass.isInterface()) { - RefactoringConflictsUtil.getInstance().analyzeAccessibilityConflictsAfterMemberMove(members, myTargetClass, conflicts, myNewVisibility); + RefactoringConflictsUtil.getInstance().analyzeAccessibilityConflictsAfterMemberMove(myTargetClass, conflicts, myNewVisibility, + members); } else { for (final UsageInfo usage : usages) { if (usage instanceof InheritorUsageInfo) { RefactoringConflictsUtil.getInstance().analyzeAccessibilityConflictsAfterMemberMove( - members, ((InheritorUsageInfo)usage).getInheritor(), conflicts, myNewVisibility); + ((InheritorUsageInfo)usage).getInheritor(), conflicts, myNewVisibility, members); } } } diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/util/RefactoringConflictsUtilImpl.java b/java/java-impl-refactorings/src/com/intellij/refactoring/util/RefactoringConflictsUtilImpl.java index 5921ac43133f..5e24a6371090 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/util/RefactoringConflictsUtilImpl.java +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/util/RefactoringConflictsUtilImpl.java @@ -44,27 +44,27 @@ public final class RefactoringConflictsUtilImpl implements RefactoringConflictsU @Override public void analyzeHierarchyConflictsAfterMethodModifierChange(@NotNull PsiMethod method, - @NotNull MultiMap conflicts, - @NotNull @PsiModifier.ModifierConstant String modifier) { + @NotNull @PsiModifier.ModifierConstant String modifier, + @NotNull MultiMap conflicts) { JavaChangeSignatureUsageProcessor.ConflictSearcher.searchForHierarchyConflicts(method, conflicts, modifier); } @Override - public void analyzeAccessibilityConflictsAfterMemberMove(@NotNull Set membersToMove, - @NotNull PsiClass targetClass, + public void analyzeAccessibilityConflictsAfterMemberMove(@NotNull PsiClass targetClass, @NotNull MultiMap conflicts, - @Nullable String newVisibility) { - analyzeAccessibilityConflictsAfterMemberMove(membersToMove, targetClass, conflicts, newVisibility, targetClass, null, Conditions.alwaysTrue()); + @Nullable String newVisibility, @NotNull Set membersToMove) { + analyzeAccessibilityConflictsAfterMemberMove(membersToMove, targetClass, newVisibility, targetClass, null, Conditions.alwaysTrue(), + conflicts); } @Override public void analyzeAccessibilityConflictsAfterMemberMove(@NotNull Set membersToMove, @Nullable PsiClass targetClass, - @NotNull MultiMap conflicts, @Nullable String newVisibility, @NotNull PsiElement context, @Nullable Set abstractMethods, - @NotNull Condition ignorePredicate) { + @NotNull Condition ignorePredicate, + @NotNull MultiMap conflicts) { if (VisibilityUtil.ESCALATE_VISIBILITY.equals(newVisibility)) { //Still need to check for access object newVisibility = PsiModifier.PUBLIC; } @@ -243,11 +243,11 @@ public final class RefactoringConflictsUtilImpl implements RefactoringConflictsU } @Override - public void analyzeModuleConflicts(final Project project, - final Collection scopes, - final UsageInfo[] usages, - final VirtualFile vFile, - final MultiMap conflicts) { + public void analyzeModuleConflicts(@NotNull Project project, + @Nullable Collection scopes, + UsageInfo[] usages, + @NotNull VirtualFile vFile, + @NotNull MultiMap conflicts) { if (scopes == null) return; for (final PsiElement scope : scopes) { if (scope instanceof PsiPackage) return; @@ -395,7 +395,9 @@ public final class RefactoringConflictsUtilImpl implements RefactoringConflictsU } @Override - public void analyzeMethodConflictsAfterParameterDelete(MultiMap conflicts, PsiMethod method, PsiParameter parameter) { + public void analyzeMethodConflictsAfterParameterDelete(@NotNull PsiMethod method, + @NotNull PsiParameter parameter, + @NotNull MultiMap conflicts) { JavaSafeDeleteProcessor.collectMethodConflicts(conflicts, method, parameter); } } diff --git a/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java b/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java index 31b6ba922eb1..672e680e0d3a 100644 --- a/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java @@ -319,7 +319,7 @@ public class SameParameterValueInspection extends GlobalJavaBatchInspectionTool Map> paramsToInline = new HashMap<>(); for (PsiMethod psiMethod : methods) { PsiParameter psiParameter = psiMethod.getParameterList().getParameters()[parameterIndex]; - RefactoringConflictsUtil.getInstance().analyzeMethodConflictsAfterParameterDelete(conflicts, psiMethod, psiParameter); + RefactoringConflictsUtil.getInstance().analyzeMethodConflictsAfterParameterDelete(psiMethod, psiParameter, conflicts); final Collection refsToInline = ReferencesSearch.search(psiParameter).findAll(); for (PsiReference reference : refsToInline) { PsiElement referenceElement = reference.getElement(); diff --git a/java/java-impl/src/com/intellij/refactoring/util/RefactoringConflictsUtil.java b/java/java-impl/src/com/intellij/refactoring/util/RefactoringConflictsUtil.java index a8ad26392af9..80b4790c82c2 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/RefactoringConflictsUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/RefactoringConflictsUtil.java @@ -25,16 +25,16 @@ public interface RefactoringConflictsUtil { * Analyzes accessibility after members move to other place (for example class) and contributes to the conflicts map if needed. * Ensures that all references to members will be able to resolve after move. * - * @param membersToMove set of members to be moved * @param targetClass class to which all members will be moved * @param conflicts map of conflicts to which this method will contribute * @param newVisibility visibility of all members after move + * @param membersToMove set of members to be moved */ - @Contract(mutates = "param3") - void analyzeAccessibilityConflictsAfterMemberMove(@NotNull Set membersToMove, - @NotNull PsiClass targetClass, + @Contract(mutates = "param4") + void analyzeAccessibilityConflictsAfterMemberMove(@NotNull PsiClass targetClass, @NotNull MultiMap conflicts, - @Nullable @PsiModifier.ModifierConstant String newVisibility); + @Nullable @PsiModifier.ModifierConstant String newVisibility, + @NotNull Set membersToMove); /** * Analyzes accessibility after members move to other place (for example class) and contributes to the conflicts map if needed. @@ -42,33 +42,33 @@ public interface RefactoringConflictsUtil { * * @param membersToMove set of members to be moved * @param targetClass class to which all members will be moved - * @param conflicts map of conflicts to which this method will contribute * @param newVisibility visibility of all members after move * @param context place where members are expected to be moved (maybe useful if targetClass is null) * @param abstractMethods methods to keep abstract in new place * @param ignorePredicate whether we need to check accessibility of a particular reference to a member + * @param conflicts map of conflicts to which this method will contribute */ - @Contract(mutates = "param3") + @Contract(mutates = "param7") void analyzeAccessibilityConflictsAfterMemberMove(@NotNull Set membersToMove, @Nullable PsiClass targetClass, - @NotNull MultiMap conflicts, @Nullable String newVisibility, @NotNull @PsiModifier.ModifierConstant PsiElement context, @Nullable Set abstractMethods, - @NotNull Condition ignorePredicate); + @NotNull Condition ignorePredicate, + @NotNull MultiMap conflicts); /** * Ensures that inheritor overloads will be able to access this method after change of visibility modifier as well as super methods will * be compatible with new modifier. Conflicts will be written to the conflict map. * * @param method method which changes its visibility modifier - * @param conflicts map of conflicts to which this method will contribute * @param modifier new visibility modifier of the method + * @param conflicts map of conflicts to which this method will contribute */ - @Contract(mutates = "param2") + @Contract(mutates = "param3") void analyzeHierarchyConflictsAfterMethodModifierChange(@NotNull PsiMethod method, - @NotNull MultiMap conflicts, - @NotNull @PsiModifier.ModifierConstant String modifier); + @NotNull @PsiModifier.ModifierConstant String modifier, + @NotNull MultiMap conflicts); /** * Searches for conflicts appearing because of move of elements from one module to another. @@ -79,18 +79,21 @@ public interface RefactoringConflictsUtil { * @param conflicts map of conflicts to which this method will contribute */ @Contract(mutates = "param5") - void analyzeModuleConflicts(Project project, - Collection scopes, + void analyzeModuleConflicts(@NotNull Project project, + @Nullable Collection scopes, UsageInfo[] usages, - VirtualFile vFile, - MultiMap conflicts); + @NotNull VirtualFile vFile, + @NotNull MultiMap conflicts); /** * Analyses conflicts appearing after deletion of a given parameter (for example, method will have the same erasure as existing one). * - * @param conflicts map of conflicts to which this method will contribute * @param method method in which parameter will be deleted * @param parameter parameter to delete + * @param conflicts map of conflicts to which this method will contribute */ - void analyzeMethodConflictsAfterParameterDelete(MultiMap conflicts, PsiMethod method, PsiParameter parameter); + @Contract(mutates = "param3") + void analyzeMethodConflictsAfterParameterDelete(@NotNull PsiMethod method, + @NotNull PsiParameter parameter, + @NotNull MultiMap conflicts); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/modifiers/ChangeModifierIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/modifiers/ChangeModifierIntention.java index c83211a9163e..f6fc4f56b9e3 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/modifiers/ChangeModifierIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/modifiers/ChangeModifierIntention.java @@ -414,7 +414,8 @@ public class ChangeModifierIntention extends BaseElementAtCaretIntentionAction { copy.setModifierProperty(modifier.toPsiModifier(), true); if (member instanceof PsiMethod) { - RefactoringConflictsUtil.getInstance().analyzeHierarchyConflictsAfterMethodModifierChange((PsiMethod)member, conflicts, modifier.toPsiModifier()); + RefactoringConflictsUtil.getInstance().analyzeHierarchyConflictsAfterMethodModifierChange((PsiMethod)member, + modifier.toPsiModifier(), conflicts); } final Query search = ReferencesSearch.search(member, useScope);