From 71d9282b6c6eaabf3ea248f3d4950a0dd3ccebed Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Thu, 10 Nov 2016 19:06:26 +0100 Subject: [PATCH] cascade safe delete/make static: don't start for methods with overriders (IDEA-162814) --- .../makeStatic/MakeStaticJavaCallerChooser.java | 7 ++++--- .../safeDelete/SafeDeleteJavaCallerChooser.java | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeStaticJavaCallerChooser.java b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeStaticJavaCallerChooser.java index 0558f6bea3cd..a82e6b2d8623 100644 --- a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeStaticJavaCallerChooser.java +++ b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeStaticJavaCallerChooser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,13 +21,13 @@ import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiModifier; +import com.intellij.psi.search.searches.OverridingMethodsSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.changeSignature.MethodNodeBase; import com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser; import com.intellij.refactoring.changeSignature.inCallers.JavaMethodNode; import com.intellij.usageView.UsageInfo; import com.intellij.util.Consumer; -import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import java.util.ArrayList; @@ -49,7 +49,8 @@ abstract class MakeStaticJavaCallerChooser extends JavaCallerChooser { !containingMethod.hasModifierProperty(PsiModifier.STATIC) && !containingMethod.isConstructor() && containingMethod.findDeepestSuperMethods().length == 0 && - !containingMethod.equals(member)) { + !containingMethod.equals(member) && + OverridingMethodsSearch.search(containingMethod).findFirst() == null) { final PsiClass containingClass = containingMethod.getContainingClass(); if (containingClass != null) { final PsiClass gContainingClass = containingClass.getContainingClass(); diff --git a/java/java-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteJavaCallerChooser.java b/java/java-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteJavaCallerChooser.java index 63de4092b4db..a4b0d7223502 100644 --- a/java/java-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteJavaCallerChooser.java +++ b/java/java-impl/src/com/intellij/refactoring/safeDelete/SafeDeleteJavaCallerChooser.java @@ -23,6 +23,7 @@ import com.intellij.openapi.util.Ref; import com.intellij.psi.*; import com.intellij.psi.javadoc.PsiDocTag; import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.searches.OverridingMethodsSearch; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; @@ -134,7 +135,8 @@ abstract class SafeDeleteJavaCallerChooser extends JavaCallerChooser { final PsiParameter parameter = ContainerUtil.getFirstItem(paramRefs); if (parameter != null && !parameter.isVarArgs()) { final PsiElement scope = parameter.getDeclarationScope(); - if (scope instanceof PsiMethod && ((PsiMethod)scope).findDeepestSuperMethods().length == 0) { + if (scope instanceof PsiMethod && ((PsiMethod)scope).findDeepestSuperMethods().length == 0 && + OverridingMethodsSearch.search((PsiMethod)scope).findFirst() == null) { final int scopeParamIdx = ((PsiMethod)scope).getParameterList().getParameterIndex(parameter); final Ref ref = new Ref<>(false); if (ReferencesSearch.search(parameter, new LocalSearchScope(scope)).forEach(new Processor() {