From f0b1ead88dd5ae40306d3185c282ae965fd1b89d Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 6 Sep 2021 19:48:08 +0200 Subject: [PATCH] [java] inline super: ensure unrelated method is not modified (IDEA-277496) GitOrigin-RevId: 91fa4b369b7bb2e13490c44105aab70c8f3be36d --- .../memberPushDown/JavaPushDownDelegate.java | 15 +++++++-------- .../pushDown/MethodsInheritedFromSuper1.java | 12 ++++++++++++ .../MethodsInheritedFromSuper1_after.java | 12 ++++++++++++ .../intellij/java/refactoring/PushDownTest.java | 17 ++--------------- 4 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 java/java-tests/testData/refactoring/pushDown/MethodsInheritedFromSuper1.java create mode 100644 java/java-tests/testData/refactoring/pushDown/MethodsInheritedFromSuper1_after.java diff --git a/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java b/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java index eba37a7049b4..7c27534b4b5b 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPushDown/JavaPushDownDelegate.java @@ -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 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()) { diff --git a/java/java-tests/testData/refactoring/pushDown/MethodsInheritedFromSuper1.java b/java/java-tests/testData/refactoring/pushDown/MethodsInheritedFromSuper1.java new file mode 100644 index 000000000000..b6a8239e9795 --- /dev/null +++ b/java/java-tests/testData/refactoring/pushDown/MethodsInheritedFromSuper1.java @@ -0,0 +1,12 @@ +@interface Anno {} +interface A { + @Anno + default String m() {} +} + +class FooBar { + public String m() {} +} + +class B extends FooBar implements A { +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/pushDown/MethodsInheritedFromSuper1_after.java b/java/java-tests/testData/refactoring/pushDown/MethodsInheritedFromSuper1_after.java new file mode 100644 index 000000000000..8be3e6b9528c --- /dev/null +++ b/java/java-tests/testData/refactoring/pushDown/MethodsInheritedFromSuper1_after.java @@ -0,0 +1,12 @@ +@interface Anno {} +interface A { +} + +class FooBar { + public String m() {} +} + +class B extends FooBar implements A { + @Anno + public String m() {} +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java index a9b238afa0ff..821dbba2a18e 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/PushDownTest.java @@ -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();}