mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
inline superclass: don't change superconstructor if interface was inlined (IDEA-152481)
This commit is contained in:
+32
-30
@@ -167,43 +167,45 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori
|
||||
}
|
||||
}
|
||||
|
||||
final PsiMethod[] superConstructors = mySuperClass.getConstructors();
|
||||
for (PsiMethod constructor : targetClass.getConstructors()) {
|
||||
final PsiCodeBlock constrBody = constructor.getBody();
|
||||
LOG.assertTrue(constrBody != null);
|
||||
final PsiStatement[] statements = constrBody.getStatements();
|
||||
if (statements.length > 0) {
|
||||
final PsiStatement firstConstrStatement = statements[0];
|
||||
if (firstConstrStatement instanceof PsiExpressionStatement) {
|
||||
final PsiExpression expression = ((PsiExpressionStatement)firstConstrStatement).getExpression();
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)expression).getMethodExpression();
|
||||
if (methodExpression.getText().equals(PsiKeyword.SUPER)) {
|
||||
final PsiMethod superConstructor = ((PsiMethodCallExpression)expression).resolveMethod();
|
||||
if (superConstructor != null && superConstructor.getBody() != null) {
|
||||
usages.add(new InlineSuperCallUsageInfo((PsiMethodCallExpression)expression));
|
||||
continue;
|
||||
if (!mySuperClass.isInterface()) {
|
||||
final PsiMethod[] superConstructors = mySuperClass.getConstructors();
|
||||
for (PsiMethod constructor : targetClass.getConstructors()) {
|
||||
final PsiCodeBlock constrBody = constructor.getBody();
|
||||
LOG.assertTrue(constrBody != null);
|
||||
final PsiStatement[] statements = constrBody.getStatements();
|
||||
if (statements.length > 0) {
|
||||
final PsiStatement firstConstrStatement = statements[0];
|
||||
if (firstConstrStatement instanceof PsiExpressionStatement) {
|
||||
final PsiExpression expression = ((PsiExpressionStatement)firstConstrStatement).getExpression();
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)expression).getMethodExpression();
|
||||
if (methodExpression.getText().equals(PsiKeyword.SUPER)) {
|
||||
final PsiMethod superConstructor = ((PsiMethodCallExpression)expression).resolveMethod();
|
||||
if (superConstructor != null && superConstructor.getBody() != null) {
|
||||
usages.add(new InlineSuperCallUsageInfo((PsiMethodCallExpression)expression));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//insert implicit call to super
|
||||
for (PsiMethod superConstructor : superConstructors) {
|
||||
if (superConstructor.getParameterList().getParametersCount() == 0) {
|
||||
final PsiExpression expression = JavaPsiFacade.getElementFactory(myProject).createExpressionFromText("super()", constructor);
|
||||
usages.add(new InlineSuperCallUsageInfo((PsiMethodCallExpression)expression, constrBody));
|
||||
|
||||
//insert implicit call to super
|
||||
for (PsiMethod superConstructor : superConstructors) {
|
||||
if (superConstructor.getParameterList().getParametersCount() == 0) {
|
||||
final PsiExpression expression = JavaPsiFacade.getElementFactory(myProject).createExpressionFromText("super()", constructor);
|
||||
usages.add(new InlineSuperCallUsageInfo((PsiMethodCallExpression)expression, constrBody));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (targetClass.getConstructors().length == 0) {
|
||||
//copy default constructor
|
||||
for (PsiMethod superConstructor : superConstructors) {
|
||||
if (superConstructor.getParameterList().getParametersCount() == 0) {
|
||||
usages.add(new CopyDefaultConstructorUsageInfo(targetClass, superConstructor));
|
||||
break;
|
||||
if (targetClass.getConstructors().length == 0) {
|
||||
//copy default constructor
|
||||
for (PsiMethod superConstructor : superConstructors) {
|
||||
if (superConstructor.getParameterList().getParametersCount() == 0) {
|
||||
usages.add(new CopyDefaultConstructorUsageInfo(targetClass, superConstructor));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class A implements I {
|
||||
A(int i) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
abstract class Test extends A {
|
||||
public Test(boolean mode) {
|
||||
super(mode? 1: 0);
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class A implements I {
|
||||
A(int i) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
interface Super {}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
abstract class Test extends A implements Super {
|
||||
public Test(boolean mode) {
|
||||
super(mode? 1: 0);
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@ public class InlineSuperClassTest extends MultiFileTestCase {
|
||||
public void testInlineSuperclassExtendsList() { doTest(); }
|
||||
public void testInterfaceHierarchyWithSubstitution() { doTest(); }
|
||||
public void testTypeParameterBound() { doTest();}
|
||||
public void testInlineInterfaceDoNotChangeConstructor() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
doTest(false, false);
|
||||
|
||||
Reference in New Issue
Block a user