mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make static: process anonymous class usages (EA-21912 - assert: MakeClassStaticProcessor.changeExternalUsage)
This commit is contained in:
+20
-10
@@ -241,6 +241,9 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor<P
|
||||
|
||||
PsiJavaCodeReferenceElement methodRef = (PsiJavaCodeReferenceElement)element;
|
||||
PsiElement parent = methodRef.getParent();
|
||||
if (parent instanceof PsiAnonymousClass) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
LOG.assertTrue(parent instanceof PsiCallExpression, "call expression expected, found " + parent);
|
||||
|
||||
PsiCallExpression call = (PsiCallExpression)parent;
|
||||
@@ -322,17 +325,24 @@ public class MakeClassStaticProcessor extends MakeMethodOrClassStaticProcessor<P
|
||||
if (call instanceof PsiMethodCallExpression) {
|
||||
instanceRef.replace(newQualifier);
|
||||
} else {
|
||||
final PsiJavaCodeReferenceElement classReference = ((PsiNewExpression)call).getClassReference();
|
||||
LOG.assertTrue(classReference != null);
|
||||
final PsiNewExpression newExpr =
|
||||
(PsiNewExpression)factory.createExpressionFromText("new " + newQualifier.getText() + "." + classReference.getText() + "()", classReference);
|
||||
final PsiExpressionList callArgs = call.getArgumentList();
|
||||
if (callArgs != null) {
|
||||
final PsiExpressionList argumentList = newExpr.getArgumentList();
|
||||
LOG.assertTrue(argumentList != null);
|
||||
argumentList.replace(callArgs);
|
||||
final PsiAnonymousClass anonymousClass = ((PsiNewExpression)call).getAnonymousClass();
|
||||
if (anonymousClass != null) {
|
||||
((PsiNewExpression)call).getQualifier().delete();
|
||||
final PsiJavaCodeReferenceElement baseClassReference = anonymousClass.getBaseClassReference();
|
||||
baseClassReference.replace(((PsiNewExpression)factory.createExpressionFromText("new " + newQualifier.getText() + "." + baseClassReference.getText() + "()", baseClassReference)).getClassReference());
|
||||
} else {
|
||||
PsiJavaCodeReferenceElement classReference = ((PsiNewExpression)call).getClassReference();
|
||||
LOG.assertTrue(classReference != null);
|
||||
final PsiNewExpression newExpr =
|
||||
(PsiNewExpression)factory.createExpressionFromText("new " + newQualifier.getText() + "." + classReference.getText() + "()", classReference);
|
||||
final PsiExpressionList callArgs = call.getArgumentList();
|
||||
if (callArgs != null) {
|
||||
final PsiExpressionList argumentList = newExpr.getArgumentList();
|
||||
LOG.assertTrue(argumentList != null);
|
||||
argumentList.replace(callArgs);
|
||||
}
|
||||
call.replace(newExpr);
|
||||
}
|
||||
call.replace(newExpr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
public class A {
|
||||
class <caret>B {
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
void foo() {
|
||||
new A().new B() {
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}.toString();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
public class A {
|
||||
static class B {
|
||||
public B() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
void foo() {
|
||||
new A().new B() {
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}.toString();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
public class A {
|
||||
class <caret>B {
|
||||
B() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
void foo() {
|
||||
new A().new B() {
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}.toString();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
public class A {
|
||||
static class B {
|
||||
B() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
void foo() {
|
||||
new A.B() {
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}.toString();
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,9 @@ public class MakeClassStaticTest extends LightCodeInsightTestCase {
|
||||
|
||||
public void testNewExpressionQualifications() throws Exception {perform();}
|
||||
|
||||
public void testNonDefaultConstructorAnonymousClass() throws Exception {perform();}
|
||||
public void testDefaultConstructorAnonymousClass() throws Exception {perform();}
|
||||
|
||||
public void testRegularReference() throws Exception {
|
||||
perform();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user