mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
push down: show conflict on attempt to push implements to anonymous
EA-118269 - NPE: JavaPushDownDelegate.pushDownToClass
This commit is contained in:
@@ -102,6 +102,10 @@ public class JavaPushDownDelegate extends PushDownDelegate<MemberInfo, PsiMember
|
||||
context = (PsiElement)newClassContext;
|
||||
}
|
||||
}
|
||||
if (targetClass instanceof PsiAnonymousClass &&
|
||||
toMove.stream().map(MemberInfoBase::getOverrides).anyMatch(Objects::nonNull)) {
|
||||
conflicts.putValue(targetClass, "Unable to push implements to anonymous class");
|
||||
}
|
||||
new PushDownConflicts((PsiClass)pushDownData.getSourceClass(), toMove.toArray(new MemberInfo[0]), conflicts)
|
||||
.checkTargetClassConflicts(targetClass, context);
|
||||
}
|
||||
@@ -304,10 +308,11 @@ public class JavaPushDownDelegate extends PushDownDelegate<MemberInfo, PsiMember
|
||||
}
|
||||
}
|
||||
PsiJavaCodeReferenceElement classRef = classType != null ? factory.createReferenceElementByType(classType) : factory.createClassReferenceElement(psiClass);
|
||||
if (psiClass.isInterface() && !targetClass.isInterface()) {
|
||||
targetClass.getImplementsList().add(classRef);
|
||||
} else {
|
||||
targetClass.getExtendsList().add(classRef);
|
||||
PsiReferenceList extendsImplementsList = psiClass.isInterface() && !targetClass.isInterface()
|
||||
? targetClass.getImplementsList()
|
||||
: targetClass.getExtendsList();
|
||||
if (extendsImplementsList != null) {
|
||||
extendsImplementsList.add(classRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
interface I {}
|
||||
class Test implements I {}
|
||||
class C {
|
||||
{
|
||||
Test a = new Test() {};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
interface I {}
|
||||
class Test {}
|
||||
class C {
|
||||
{
|
||||
Test a = new Test() {};
|
||||
}
|
||||
}
|
||||
@@ -108,6 +108,10 @@ public class PushDownTest extends LightRefactoringTestCase {
|
||||
doTestImplements(true, true);
|
||||
}
|
||||
|
||||
public void testPassingImplementsToAnonymous() {
|
||||
doTestImplements(false, true);
|
||||
}
|
||||
|
||||
public void testInterfaceVisibilityInClass() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user