mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
Inline inner: assignments to local vars and params in constructor body fixed (IDEA-39285)
This commit is contained in:
+6
-11
@@ -183,7 +183,7 @@ class InlineToAnonymousConstructorProcessor {
|
||||
ProcessingContext context = new ProcessingContext();
|
||||
if (ourAssignmentPattern.accepts(stmt, context)) {
|
||||
PsiAssignmentExpression expression = context.get(ourAssignmentKey);
|
||||
if (!processAssignmentInConstructor(expression)) {
|
||||
if (processAssignmentInConstructor(expression)) {
|
||||
initializerBlock.addBefore(replaceParameterReferences(stmt, null, false), initializerBlock.getRBrace());
|
||||
}
|
||||
}
|
||||
@@ -205,7 +205,7 @@ class InlineToAnonymousConstructorProcessor {
|
||||
if (expression.getLExpression() instanceof PsiReferenceExpression) {
|
||||
PsiReferenceExpression lExpr = (PsiReferenceExpression) expression.getLExpression();
|
||||
final PsiExpression rExpr = expression.getRExpression();
|
||||
if (rExpr == null) return true;
|
||||
if (rExpr == null) return false;
|
||||
final PsiElement psiElement = lExpr.resolve();
|
||||
if (psiElement instanceof PsiField) {
|
||||
PsiField field = (PsiField) psiElement;
|
||||
@@ -217,25 +217,20 @@ class InlineToAnonymousConstructorProcessor {
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (!localVarRefs.isEmpty()) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
myFieldInitializers.put(field.getName(), initializer);
|
||||
}
|
||||
}
|
||||
else if (psiElement instanceof PsiVariable) {
|
||||
try {
|
||||
replaceParameterReferences(rExpr.copy(), new ArrayList<PsiReferenceExpression>(), false);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isConstant(final PsiExpression expr) {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
public class WithCtor {
|
||||
private int myInt = 8;
|
||||
private String myString = "Sashya";
|
||||
|
||||
public WithCtor() {
|
||||
}
|
||||
|
||||
public WithCtor(int anInt, String string) {
|
||||
int i = 2;
|
||||
i = 3;
|
||||
myInt = i + anInt;
|
||||
int j = 4;
|
||||
j = 5;
|
||||
myString = string.substring(j);
|
||||
}
|
||||
}
|
||||
|
||||
class Usage {
|
||||
private WithCtor wc1 = new With<caret>Ctor(17, "Sa");
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class Usage {
|
||||
private Object wc1 = new Object() {
|
||||
private int myInt = 8;
|
||||
private String myString = "Sashya";
|
||||
|
||||
{
|
||||
int i = 2;
|
||||
i = 3;
|
||||
myInt = i + 17;
|
||||
int j = 4;
|
||||
j = 5;
|
||||
myString = "Sa".substring(j);
|
||||
}
|
||||
};
|
||||
}
|
||||
+4
@@ -218,6 +218,10 @@ public class InlineToAnonymousClassTest extends LightCodeInsightTestCase {
|
||||
doTest(false, true);
|
||||
}
|
||||
|
||||
public void testMultipleAssignments() throws Exception {
|
||||
doTest(false, true);
|
||||
}
|
||||
|
||||
public void testNoInlineAbstract() throws Exception {
|
||||
doTestNoInline("Abstract classes cannot be inlined");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user