[java] pull up: don't transform super calls unnecessary (IDEA-277680)

GitOrigin-RevId: 4dce57984e4dd79813781493614d19bb2ec0c535
This commit is contained in:
Anna Kozlova
2021-09-28 21:10:46 +00:00
committed by intellij-monorepo-bot
parent 1673673d88
commit d92c835832
4 changed files with 43 additions and 21 deletions
@@ -766,8 +766,6 @@ public class JavaPullUpHelper implements PullUpHelper<MemberInfo> {
}
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<MemberInfo> {
}
}
@Override
public void visitSuperExpression(PsiSuperExpression expression) {
expression.replace(myThisExpression);
}
@Override
public void visitClass(PsiClass aClass) {
@@ -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 f<caret>oo() {
if (!super.foo()) {
return false;
}
return Math.random() > 0.5;
}
}
@@ -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 {
}
@@ -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);