mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
convert static to instance: don't check interface inheritance for java 1.8+
check used references for java 1.8- as call sites would call abstract method of interface anyway (IDEA-187991)
This commit is contained in:
+6
-7
@@ -41,7 +41,6 @@ import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import java.util.HashMap;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -173,14 +172,14 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
|
||||
UsageInfo[] usagesIn = refUsages.get();
|
||||
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
|
||||
final Set<PsiMember> methods = Collections.singleton((PsiMember)myMethod);
|
||||
if (!myTargetClass.isInterface()) {
|
||||
RefactoringConflictsUtil.analyzeAccessibilityConflicts(methods, myTargetClass, conflicts, myNewVisibility);
|
||||
}
|
||||
else {
|
||||
//check that method to call would be still accessible from the call places
|
||||
RefactoringConflictsUtil.analyzeAccessibilityConflicts(methods, myTargetClass, conflicts, myNewVisibility);
|
||||
//additionally check that body of method contains only accessible in the inheritors references
|
||||
if (myTargetClass.isInterface() && !PsiUtil.isLanguageLevel8OrHigher(myTargetClass)) {
|
||||
for (final UsageInfo usage : usagesIn) {
|
||||
if (usage instanceof ImplementingClassUsageInfo) {
|
||||
RefactoringConflictsUtil
|
||||
.analyzeAccessibilityConflicts(methods, ((ImplementingClassUsageInfo)usage).getPsiClass(), conflicts, PsiModifier.PUBLIC);
|
||||
PsiClass targetClass = ((ImplementingClassUsageInfo)usage).getPsiClass();
|
||||
RefactoringConflictsUtil.checkUsedElements(myMethod, myMethod, methods, null, targetClass, targetClass, conflicts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface I {
|
||||
static void f<caret>oo(I i) {}
|
||||
}
|
||||
|
||||
class WithPrivateInner {
|
||||
private class Inner implements I {}
|
||||
}
|
||||
|
||||
class WithUsage {
|
||||
void n(I i) {
|
||||
I.foo(i);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface I {
|
||||
default void foo() {}
|
||||
}
|
||||
|
||||
class WithPrivateInner {
|
||||
private class Inner implements I {}
|
||||
}
|
||||
|
||||
class WithUsage {
|
||||
void n(I i) {
|
||||
i.foo();
|
||||
}
|
||||
}
|
||||
+4
@@ -37,6 +37,10 @@ public class ConvertToInstance8MethodTest extends ConvertToInstanceMethodTest {
|
||||
doTest(-1);
|
||||
}
|
||||
|
||||
public void testStaticMethodOfInterfaceWithNonAccessibleInheritor() {
|
||||
doTest(0);
|
||||
}
|
||||
|
||||
public void testConvertToInstanceMethodOfTheSameClassWithTypeParams() {
|
||||
try {
|
||||
doTest(-1);
|
||||
|
||||
Reference in New Issue
Block a user