mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
surround lambda/method refs with cast when inline in expression list (IDEA-92742)
This commit is contained in:
@@ -150,7 +150,8 @@ public class InlineUtil {
|
||||
}
|
||||
|
||||
private static PsiExpression surroundWithCast(PsiVariable variable, PsiExpression expr, PsiExpression expression) {
|
||||
if (expression.getParent() instanceof PsiReferenceExpression) {
|
||||
final PsiElement parent = expression.getParent();
|
||||
if (parent instanceof PsiReferenceExpression || parent instanceof PsiExpressionList) {
|
||||
PsiTypeCastExpression cast = (PsiTypeCastExpression)JavaPsiFacade.getElementFactory(expr.getProject()).createExpressionFromText("(t)a", null);
|
||||
PsiTypeElement castTypeElement = cast.getCastType();
|
||||
assert castTypeElement != null;
|
||||
@@ -159,6 +160,9 @@ public class InlineUtil {
|
||||
assert operand != null;
|
||||
operand.replace(expr);
|
||||
expr = (PsiTypeCastExpression)expr.replace(cast);
|
||||
if (RedundantCastUtil.isCastRedundant((PsiTypeCastExpression)expr)) {
|
||||
expr = (PsiExpression)expr.replace(((PsiTypeCastExpression)expr).getOperand());
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class Test {
|
||||
void test() {
|
||||
I b1 = System::exit;
|
||||
a(b<caret>1);
|
||||
}
|
||||
|
||||
void a(Object b) {}
|
||||
|
||||
interface I {
|
||||
void i(int i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
void test() {
|
||||
a((I) System::exit);
|
||||
}
|
||||
|
||||
void a(Object b) {}
|
||||
|
||||
interface I {
|
||||
void i(int i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class Test {
|
||||
void test() {
|
||||
I b1 = System::exit;
|
||||
a(b<caret>1);
|
||||
}
|
||||
|
||||
void a(I b) {}
|
||||
|
||||
interface I {
|
||||
void i(int i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
void test() {
|
||||
a(System::exit);
|
||||
}
|
||||
|
||||
void a(I b) {}
|
||||
|
||||
interface I {
|
||||
void i(int i);
|
||||
}
|
||||
}
|
||||
@@ -184,6 +184,14 @@ public class InlineLocalTest extends LightCodeInsightTestCase {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testCastAroundLambda() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testNoCastAroundLambda() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testLocalVarInsideLambdaBodyWriteUsage() throws Exception {
|
||||
doTest(true, "Cannot perform refactoring.\n" +
|
||||
"Variable 'hello' is accessed for writing.");
|
||||
|
||||
Reference in New Issue
Block a user