mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] make method static: adapt to static methods in anonymous classes, method references (IDEA-293090)
GitOrigin-RevId: c7a58c6e06726607fb5e97d74624a468d684a8ec
This commit is contained in:
committed by
intellij-monorepo-bot
parent
106750692a
commit
49b2bd2ca6
+6
-3
@@ -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-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.refactoring.makeStatic;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
@@ -304,7 +304,7 @@ public class MakeMethodStaticProcessor extends MakeMethodOrClassStaticProcessor<
|
||||
|
||||
final PsiClass memberClass = myMember.getContainingClass();
|
||||
if (instanceRef == null || instanceRef instanceof PsiSuperExpression) {
|
||||
PsiClass contextClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
|
||||
PsiClass contextClass = PsiTreeUtil.getParentOfType(methodRef, PsiClass.class);
|
||||
if (!InheritanceUtil.isInheritorOrSelf(contextClass, memberClass, true)) {
|
||||
instanceRef = factory.createExpressionFromText(memberClass.getQualifiedName() + ".this", null);
|
||||
} else {
|
||||
@@ -313,7 +313,7 @@ public class MakeMethodStaticProcessor extends MakeMethodOrClassStaticProcessor<
|
||||
newQualifier = null;
|
||||
}
|
||||
else {
|
||||
newQualifier = factory.createReferenceExpression(memberClass);
|
||||
newQualifier = memberClass == null || memberClass instanceof PsiAnonymousClass ? null : factory.createReferenceExpression(memberClass);
|
||||
}
|
||||
|
||||
if (mySettings.getNewParametersNumber() > 1) {
|
||||
@@ -386,6 +386,9 @@ public class MakeMethodStaticProcessor extends MakeMethodOrClassStaticProcessor<
|
||||
}
|
||||
|
||||
private boolean needLambdaConversion(PsiMethodReferenceExpression methodRef) {
|
||||
if (myMember.getContainingClass() instanceof PsiAnonymousClass) {
|
||||
return true;
|
||||
}
|
||||
if (mySettings.isMakeFieldParameters()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class MyTest {
|
||||
{
|
||||
new Runnable() {
|
||||
private static void print() {}
|
||||
@Override
|
||||
public void run() {
|
||||
Runnable r = () -> print();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class MyTest {
|
||||
{
|
||||
new Runnable() {
|
||||
private void pri<caret>nt() {}
|
||||
@Override
|
||||
public void run() {
|
||||
Runnable r = this::print;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
@@ -230,6 +216,10 @@ public class MakeMethodStaticTest extends LightRefactoringTestCase {
|
||||
doTest(true, true);
|
||||
}
|
||||
|
||||
public void testMethodReferenceInAnonymousClass() {
|
||||
BaseRefactoringProcessor.ConflictsInTestsException.withIgnoredConflicts(() -> doTest());
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user