inline method: avoid dbl substitution of return/param types

This commit is contained in:
Anna.Kozlova
2016-08-12 11:06:57 +02:00
parent 208ae02ea2
commit 4866aa1f89
4 changed files with 37 additions and 3 deletions
@@ -634,9 +634,6 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
PsiSubstitutor callSubstitutor = getCallSubstitutor(methodCall);
BlockData blockData = prepareBlock(ref, callSubstitutor, methodCall.getArgumentList(), tailCall);
InlineUtil.solveVariableNameConflicts(blockData.block, ref, myMethodCopy.getBody());
if (callSubstitutor != PsiSubstitutor.EMPTY) {
substituteMethodTypeParams(blockData.block, callSubstitutor);
}
addParmAndThisVarInitializers(blockData, methodCall);
PsiElement anchor = RefactoringUtil.getParentStatement(methodCall, true);
@@ -801,6 +798,9 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
final InlineUtil.TailCallType tailCallType)
throws IncorrectOperationException {
final PsiCodeBlock block = myMethodCopy.getBody();
if (callSubstitutor != PsiSubstitutor.EMPTY) {
substituteMethodTypeParams(block, callSubstitutor);
}
final PsiStatement[] originalStatements = block.getStatements();
PsiLocalVariable resultVar = null;
@@ -0,0 +1,17 @@
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
class A {
<T> void bar(List<T> root, LinkedHashSet<List<T>> list) {
add<caret>IfNotNull(root, list);
}
private static <T> void addIfNotNull(T element, Collection<T> result) {
nested(result, element);
}
private static <S> void nested(Collection<S> result, S element) {}
}
@@ -0,0 +1,13 @@
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
class A {
<T> void bar(List<T> root, LinkedHashSet<List<T>> list) {
nested(list, root);
}
private static <S> void nested(Collection<S> result, S element) {}
}
@@ -330,6 +330,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
doTest();
}
public void testAvoidMultipleSubstitutionInParameterTypes() throws Exception {
doTest();
}
private void doTestInlineThisOnly() {
@NonNls String fileName = "/refactoring/inlineMethod/" + getTestName(false) + ".java";
configureByFile(fileName);