Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
3345967b
Commit
3345967b
authored
6 years ago
by
Tagir Valeev
Browse files
Options
Download
Email Patches
Plain Diff
Parameter mapping fixed in case if two vars introduced
parent
723c0554
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java
+22
-18
...om/intellij/refactoring/inline/InlineMethodProcessor.java
java/java-tests/testData/refactoring/inlineMethod/ConvertToSingleReturnWithFinished.java
+16
-0
...oring/inlineMethod/ConvertToSingleReturnWithFinished.java
java/java-tests/testData/refactoring/inlineMethod/ConvertToSingleReturnWithFinished.java.after
+21
-0
...inlineMethod/ConvertToSingleReturnWithFinished.java.after
java/java-tests/testSrc/com/intellij/java/refactoring/inline/InlineMethodTest.java
+4
-0
...om/intellij/java/refactoring/inline/InlineMethodTest.java
with
63 additions
and
18 deletions
+63
-18
java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java
+
22
-
18
View file @
3345967b
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
java/java-tests/testData/refactoring/inlineMethod/ConvertToSingleReturnWithFinished.java
0 → 100644
+
16
-
0
View file @
3345967b
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"
);
}
}
This diff is collapsed.
Click to expand it.
java/java-tests/testData/refactoring/inlineMethod/ConvertToSingleReturnWithFinished.java.after
0 → 100644
+
21
-
0
View file @
3345967b
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");
}
}
This diff is collapsed.
Click to expand it.
java/java-tests/testSrc/com/intellij/java/refactoring/inline/InlineMethodTest.java
+
4
-
0
View file @
3345967b
...
...
@@ -462,6 +462,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
public
void
testNotTailCallInsideIf
()
{
doTestAssertBadReturn
();
}
public
void
testConvertToSingleReturnWithFinished
()
{
doTestAssertBadReturn
();
}
@Override
protected
Sdk
getProjectJDK
()
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help