mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda -> anonymous: static calls (IDEA-124187)
This commit is contained in:
+7
-4
@@ -64,8 +64,8 @@ public class ReplaceLambdaWithAnonymousIntention extends Intention {
|
||||
PsiCodeBlock blockFromText = psiElementFactory.createCodeBlockFromText(blockText, lambdaExpression);
|
||||
ChangeContextUtil.encodeContextInfo(blockFromText, true);
|
||||
PsiNewExpression newExpression = (PsiNewExpression)psiElementFactory.createExpressionFromText("new " + functionalInterfaceType.getCanonicalText() + "(){}", lambdaExpression);
|
||||
final PsiClass thisClass = PsiTreeUtil.getParentOfType(lambdaExpression, PsiClass.class, true);
|
||||
final String thisClassName = thisClass.getName();
|
||||
final PsiClass thisClass = RefactoringChangeUtil.getThisClass(lambdaExpression);
|
||||
final String thisClassName = thisClass != null ? thisClass.getName() : null;
|
||||
if (thisClassName != null) {
|
||||
final PsiThisExpression thisAccessExpr = thisClass instanceof PsiAnonymousClass ? null : RefactoringChangeUtil
|
||||
.createThisExpression(lambdaExpression.getManager(), thisClass);
|
||||
@@ -86,8 +86,11 @@ public class ReplaceLambdaWithAnonymousIntention extends Intention {
|
||||
@Override
|
||||
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
if (thisAccessExpr != null && expression.getMethodExpression().getQualifierExpression() == null) {
|
||||
replacements.put(expression, psiElementFactory.createExpressionFromText(thisAccessExpr.getText() + "." + expression.getText(), expression));
|
||||
if (thisAccessExpr != null) {
|
||||
final PsiMethod psiMethod = expression.resolveMethod();
|
||||
if (psiMethod != null && !psiMethod.hasModifierProperty(PsiModifier.STATIC) && expression.getMethodExpression().getQualifierExpression() == null) {
|
||||
replacements.put(expression, psiElementFactory.createExpressionFromText(thisAccessExpr.getText() + "." + expression.getText(), expression));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Thread((<caret>) -> print());
|
||||
}
|
||||
|
||||
public static void print() {
|
||||
System.out.println("print");
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
class Foo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
print();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void print() {
|
||||
System.out.println("print");
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -75,6 +75,10 @@ public class ReplaceLambdaWithAnonymousIntentionTest extends IPPTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testStaticCalls() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getIntentionName() {
|
||||
return IntentionPowerPackBundle.message("replace.lambda.with.anonymous.intention.name");
|
||||
|
||||
Reference in New Issue
Block a user