mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
unimplement: do not delete methods which override super methods (IDEA-58918)
This commit is contained in:
@@ -25,6 +25,10 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class UnimplementInterfaceAction implements IntentionAction {
|
||||
private String myName = "Interface";
|
||||
|
||||
@@ -86,8 +90,13 @@ public class UnimplementInterfaceAction implements IntentionAction {
|
||||
|
||||
psiReference.getElement().delete();
|
||||
|
||||
final Set<PsiMethod> superMethods = new HashSet<PsiMethod>();
|
||||
for (PsiClass aClass : psiClass.getSupers()) {
|
||||
Collections.addAll(superMethods, aClass.getAllMethods());
|
||||
}
|
||||
final PsiMethod[] psiMethods = targetClass.getAllMethods();
|
||||
for (PsiMethod psiMethod : psiMethods) {
|
||||
if (superMethods.contains(psiMethod)) continue;
|
||||
final PsiMethod[] implementingMethods = psiClass.findMethodsBySignature(psiMethod, false);
|
||||
for (PsiMethod implementingMethod : implementingMethods) {
|
||||
implementingMethod.delete();
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Unimplement Interface" "true"
|
||||
class A {
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
interface II {}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Unimplement Interface" "true"
|
||||
class A implements I<caret>I {
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
interface II {}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
public class UnimplementIntentionTest extends LightQuickFixTestCase {
|
||||
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/unimplement";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user