mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: reject containing classes when members were called through inheritance chain
This commit is contained in:
@@ -405,6 +405,14 @@ public class ControlFlowUtil {
|
||||
if (parent instanceof PsiClass) {
|
||||
final PsiClass clss = (PsiClass)parent;
|
||||
if (PsiTreeUtil.isAncestor(targetClassMember, clss, false)) return false;
|
||||
PsiClass containingClass = PsiTreeUtil.getParentOfType(ref, PsiClass.class);
|
||||
while (containingClass != null) {
|
||||
if (containingClass.isInheritor(clss, true) &&
|
||||
PsiTreeUtil.isAncestor(targetClassMember, containingClass, false)) {
|
||||
return false;
|
||||
}
|
||||
containingClass = containingClass.getContainingClass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
public class Foo {
|
||||
public void update() {}
|
||||
}
|
||||
|
||||
class FooBar {
|
||||
{
|
||||
Foo tm = new Foo() {
|
||||
{
|
||||
<selection>update()</selection>;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
public class Foo {
|
||||
public void update() {}
|
||||
}
|
||||
|
||||
class FooBar {
|
||||
{
|
||||
Foo tm = new Foo() {
|
||||
{
|
||||
newMethod();
|
||||
}
|
||||
|
||||
private void newMethod() {
|
||||
update();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -583,6 +583,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testTargetAnonymous() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTestDisabledParam() throws PrepareFailedException {
|
||||
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
settings.ELSE_ON_NEW_LINE = true;
|
||||
|
||||
Reference in New Issue
Block a user