mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] inline super: ensure unrelated method is not modified (IDEA-277496)
GitOrigin-RevId: 91fa4b369b7bb2e13490c44105aab70c8f3be36d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1f0f1acfbc
commit
f0b1ead88d
+7
-8
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.refactoring.memberPushDown;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
@@ -238,15 +238,14 @@ public class JavaPushDownDelegate extends PushDownDelegate<MemberInfo, PsiMember
|
||||
}
|
||||
else if (member instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)member;
|
||||
PsiMethod methodBySignature = MethodSignatureUtil.findMethodBySuperSignature(targetClass, method.getSignature(substitutor), true);
|
||||
PsiMethod methodBySignature = MethodSignatureUtil.findMethodBySuperSignature(targetClass, method.getSignature(substitutor), false);
|
||||
boolean pushMethodToClass = methodBySignature == null;
|
||||
if (!pushMethodToClass) {
|
||||
//non-abstract method inherited from super class
|
||||
PsiClass containingClass = methodBySignature.getContainingClass();
|
||||
pushMethodToClass = containingClass == sourceClass ||
|
||||
containingClass != targetClass && methodBySignature.hasModifierProperty(PsiModifier.ABSTRACT);
|
||||
}
|
||||
if (pushMethodToClass) {
|
||||
if (Arrays.stream(targetClass.findMethodsBySignature(method, true))
|
||||
.map(m -> m.getContainingClass())
|
||||
.filter(Objects::nonNull).anyMatch(aClass -> aClass.isInheritor(sourceClass, true))) {
|
||||
continue;
|
||||
}
|
||||
newMember = (PsiMethod)targetClass.add(method);
|
||||
final PsiMethod oldMethod = (PsiMethod)memberInfo.getMember();
|
||||
if (sourceClass.isInterface() && !targetClass.isInterface()) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
@interface Anno {}
|
||||
interface A {
|
||||
@Anno
|
||||
default String <caret>m() {}
|
||||
}
|
||||
|
||||
class FooBar {
|
||||
public String m() {}
|
||||
}
|
||||
|
||||
class B extends FooBar implements A {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
@interface Anno {}
|
||||
interface A {
|
||||
}
|
||||
|
||||
class FooBar {
|
||||
public String m() {}
|
||||
}
|
||||
|
||||
class B extends FooBar implements A {
|
||||
@Anno
|
||||
public String m() {}
|
||||
}
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.
|
||||
*/
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
@@ -83,6 +69,7 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
public void testInterfaceStaticMethodToClass() { doTest(); }
|
||||
public void testThisSuperExpressions() {doTest();}
|
||||
public void testMethodsInheritedFromSuper() {doTest();}
|
||||
public void testMethodsInheritedFromSuper1() {doTest();}
|
||||
public void testCopyAnnotationsFromSuper() {doTest();}
|
||||
public void testKeepBodyFromInterfaceMethod() {doTest();}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user