inline: ensure to insert valid specification (IDEA-161992)

This commit is contained in:
Anna.Kozlova
2016-10-04 18:45:14 +02:00
parent 1f41202f49
commit df5219221c
4 changed files with 29 additions and 1 deletions
@@ -27,6 +27,7 @@ import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiTypesUtil;
import com.intellij.psi.util.RedundantCastUtil;
import com.intellij.refactoring.RefactoringBundle;
import com.intellij.util.IncorrectOperationException;
@@ -127,7 +128,7 @@ public class InlineUtil {
if (substituted == null) break;
copy.getTypeArgumentList().add(elementFactory.createTypeElement(substituted));
}
if (varType.equals(copy.getType())) {
if (varType.equals(copy.getType()) && copy.resolveMethodGenerics().isValidResult()) {
((PsiCallExpression)expr).getTypeArgumentList().replace(copy.getTypeArgumentList());
return (PsiMethod)resolved;
}
@@ -0,0 +1,12 @@
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
class Main {
public Collection<? extends Number> get() {
List<Number> lis<caret>t = IntStream.range(0, 100).boxed().collect(Collectors.toList());
return list;
}
}
@@ -0,0 +1,11 @@
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
class Main {
public Collection<? extends Number> get() {
return IntStream.range(0, 100).boxed().collect(Collectors.toList());
}
}
@@ -292,6 +292,10 @@ public class InlineLocalTest extends LightCodeInsightTestCase {
"Variable 'hello' is accessed for writing");
}
public void testAvoidTypeSpecificationWhenPossibleToAvoid() throws Exception {
doTest(false);
}
private void doTest(final boolean inlineDef, String conflictMessage) throws Exception {
try {
doTest(inlineDef);