mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
inline parameter: assignment to local variable between its declaration and the call causes the incompilable code (IDEA-52164)
This commit is contained in:
+7
@@ -121,6 +121,13 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
|
||||
else if (elements[0] instanceof PsiAssignmentExpression) {
|
||||
localInitializer = ((PsiAssignmentExpression)elements[0]).getRExpression();
|
||||
}
|
||||
else if (elements[0] instanceof PsiReferenceExpression) {
|
||||
final PsiReferenceExpression refElement = (PsiReferenceExpression)elements[0];
|
||||
final PsiElement parent = refElement.getParent();
|
||||
if (parent instanceof PsiAssignmentExpression && ((PsiAssignmentExpression)parent).getLExpression() == refElement) {
|
||||
localInitializer = ((PsiAssignmentExpression)parent).getRExpression();
|
||||
}
|
||||
}
|
||||
if (localInitializer != null) {
|
||||
final PsiElement replacement;
|
||||
if (localToParamRef.containsKey(localVariable)) {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
public class ExpData {
|
||||
public void use(Object p) {
|
||||
System.out.println(p);
|
||||
}
|
||||
|
||||
public void context() {
|
||||
ObjectType v1 = new ObjectType();
|
||||
v1 = v1.provide();
|
||||
inline1(v1);
|
||||
|
||||
int v2 = 1;
|
||||
v2 += System.identityHashCode(new Object());
|
||||
inline2(v2);
|
||||
}
|
||||
|
||||
public void inline1(ObjectType <caret>subj) {
|
||||
use(subj);
|
||||
}
|
||||
|
||||
public void inline2(int subj) {
|
||||
use(subj);
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectType {
|
||||
private int value = 1;
|
||||
|
||||
public ObjectType provide() {
|
||||
return new ObjectType();
|
||||
}
|
||||
}
|
||||
@@ -228,6 +228,15 @@ public class InlineParameterTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testWriteAccess() throws Exception {
|
||||
try {
|
||||
doTest(false);
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
assertEquals("Parameter initializer depends on value which is not available inside method and cannot be inlined", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void doTest(final boolean createLocal) throws Exception {
|
||||
getProject().putUserData(InlineParameterExpressionProcessor.CREATE_LOCAL_FOR_TESTS,createLocal);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user