mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Parameter mapping fixed in case if two vars introduced
This commit is contained in:
@@ -652,8 +652,6 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
PsiElement firstAdded = null;
|
||||
if (firstBodyElement != null && firstBodyElement != blockData.block.getRBrace()) {
|
||||
int last = statements.length - 1;
|
||||
/*PsiElement first = statements[0];
|
||||
PsiElement last = statements[statements.length - 1];*/
|
||||
|
||||
if (last > 0 && statements[last] instanceof PsiReturnStatement &&
|
||||
tailCall != InlineUtil.TailCallType.Return) {
|
||||
@@ -668,22 +666,28 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
firstAdded = anchorParent.addRangeBefore(firstBodyElement, beforeRBraceStatement, anchor);
|
||||
|
||||
PsiElement current = firstAdded.getPrevSibling();
|
||||
LOG.assertTrue(current != null);
|
||||
if (blockData.resultVar != null) {
|
||||
PsiDeclarationStatement statement = PsiTreeUtil.getNextSiblingOfType(current, PsiDeclarationStatement.class);
|
||||
resultVar = (PsiLocalVariable)statement.getDeclaredElements()[0];
|
||||
current = statement;
|
||||
}
|
||||
if (blockData.thisVar != null) {
|
||||
PsiDeclarationStatement statement = PsiTreeUtil.getNextSiblingOfType(current, PsiDeclarationStatement.class);
|
||||
thisVar = (PsiLocalVariable)statement.getDeclaredElements()[0];
|
||||
current = statement;
|
||||
}
|
||||
for (int i = 0; i < parmVars.length; i++) {
|
||||
PsiDeclarationStatement statement = PsiTreeUtil.getNextSiblingOfType(current, PsiDeclarationStatement.class);
|
||||
parmVars[i] = (PsiLocalVariable)statement.getDeclaredElements()[0];
|
||||
current = statement;
|
||||
for (PsiElement e = firstAdded; e != anchor; e = e.getNextSibling()) {
|
||||
if (e instanceof PsiDeclarationStatement) {
|
||||
PsiElement[] elements = ((PsiDeclarationStatement)e).getDeclaredElements();
|
||||
PsiLocalVariable var = ObjectUtils.tryCast(ArrayUtil.getFirstElement(elements), PsiLocalVariable.class);
|
||||
if (var != null) {
|
||||
String name = var.getName();
|
||||
LOG.assertTrue(name != null);
|
||||
if (blockData.resultVar != null && name.equals(blockData.resultVar.getName())) {
|
||||
resultVar = var;
|
||||
}
|
||||
else if (blockData.thisVar != null && name.equals(blockData.thisVar.getName())) {
|
||||
thisVar = var;
|
||||
} else {
|
||||
for (int i = 0; i < blockData.parmVars.length; i++) {
|
||||
if (name.equals(blockData.parmVars[i].getName())) {
|
||||
parmVars[i] = var;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (statements.length > 0) {
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
class A {
|
||||
String foo(int i) {
|
||||
if (i > 0) {
|
||||
if (i == 10) return null;
|
||||
System.out.println(i);
|
||||
}
|
||||
return String.valueOf(i);
|
||||
}
|
||||
|
||||
void bar(int x) {
|
||||
if (x > 0) {
|
||||
System.out.println(f<caret>oo(x));
|
||||
}
|
||||
System.out.println("x < 0");
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
class A {
|
||||
|
||||
void bar(int x) {
|
||||
if (x > 0) {
|
||||
String result = null;
|
||||
boolean finished = false;
|
||||
if (x > 0) {
|
||||
if (x == 10) {
|
||||
finished = true;
|
||||
} else {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
if (!finished) {
|
||||
result = String.valueOf(x);
|
||||
}
|
||||
System.out.println(result);
|
||||
}
|
||||
System.out.println("x < 0");
|
||||
}
|
||||
}
|
||||
@@ -462,6 +462,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
public void testNotTailCallInsideIf() {
|
||||
doTestAssertBadReturn();
|
||||
}
|
||||
|
||||
public void testConvertToSingleReturnWithFinished() {
|
||||
doTestAssertBadReturn();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
|
||||
Reference in New Issue
Block a user