From d92c8358329ec6b8bad288d7c4d89a4c8c72db1e Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 28 Sep 2021 15:28:44 +0200 Subject: [PATCH] [java] pull up: don't transform super calls unnecessary (IDEA-277680) GitOrigin-RevId: 4dce57984e4dd79813781493614d19bb2ec0c535 --- .../memberPullUp/JavaPullUpHelper.java | 6 ------ .../pullUp/SuperExprQualifying.java | 19 ++++++++++++++++++ .../pullUp/SuperExprQualifying_after.java | 19 ++++++++++++++++++ .../intellij/java/refactoring/PullUpTest.java | 20 +++++-------------- 4 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 java/java-tests/testData/refactoring/pullUp/SuperExprQualifying.java create mode 100644 java/java-tests/testData/refactoring/pullUp/SuperExprQualifying_after.java diff --git a/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHelper.java b/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHelper.java index b0e4dacfac3e..8d010dcc747e 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHelper.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHelper.java @@ -766,8 +766,6 @@ public class JavaPullUpHelper implements PullUpHelper { } private class ExplicitSuperDeleter extends JavaRecursiveElementWalkingVisitor { - private final PsiExpression myThisExpression = JavaPsiFacade.getElementFactory(myProject).createExpressionFromText("this", null); - @Override public void visitReferenceExpression(PsiReferenceExpression expression) { super.visitReferenceExpression(expression); @@ -779,10 +777,6 @@ public class JavaPullUpHelper implements PullUpHelper { } } - @Override - public void visitSuperExpression(PsiSuperExpression expression) { - expression.replace(myThisExpression); - } @Override public void visitClass(PsiClass aClass) { diff --git a/java/java-tests/testData/refactoring/pullUp/SuperExprQualifying.java b/java/java-tests/testData/refactoring/pullUp/SuperExprQualifying.java new file mode 100644 index 000000000000..65233605a7d5 --- /dev/null +++ b/java/java-tests/testData/refactoring/pullUp/SuperExprQualifying.java @@ -0,0 +1,19 @@ + +class A { + public boolean foo() { + return Math.random() > 0.5; + } +} + +class B extends A { +} + +class Test extends B { + @Override + public boolean foo() { + if (!super.foo()) { + return false; + } + return Math.random() > 0.5; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/pullUp/SuperExprQualifying_after.java b/java/java-tests/testData/refactoring/pullUp/SuperExprQualifying_after.java new file mode 100644 index 000000000000..94e253c3d268 --- /dev/null +++ b/java/java-tests/testData/refactoring/pullUp/SuperExprQualifying_after.java @@ -0,0 +1,19 @@ + +class A { + public boolean foo() { + return Math.random() > 0.5; + } +} + +class B extends A { + @Override + public boolean foo() { + if (!super.foo()) { + return false; + } + return Math.random() > 0.5; + } +} + +class Test extends B { +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/PullUpTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/PullUpTest.java index 5e0a6cfac038..dc8c37d5aa7e 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/PullUpTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/PullUpTest.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.JavaTestUtil; @@ -237,6 +223,10 @@ public class PullUpTest extends LightRefactoringTestCase { public void testPullUpFromAnonymousToInterface() { doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class, true)); } + + public void testSuperExprQualifying() { + doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class, false)); + } private void doTest(RefactoringTestUtil.MemberDescriptor... membersToFind) { doTest(true, membersToFind);