diff --git a/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java b/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java index 0fbce084a213..6fd5ff28eedf 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java @@ -24,6 +24,7 @@ import com.intellij.psi.*; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.RedundantCastUtil; +import com.intellij.psi.util.TypeConversionUtil; import com.intellij.refactoring.RefactoringBundle; import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; @@ -54,7 +55,8 @@ public class InlineUtil { ChangeContextUtil.encodeContextInfo(initializer, false); PsiExpression expr = (PsiExpression)ref.replace(initializer); PsiType exprType = expr.getType(); - if (exprType != null && !varType.equals(exprType)) { + if (exprType != null && (!varType.equals(exprType) && varType instanceof PsiPrimitiveType + || !TypeConversionUtil.isAssignable(varType, exprType))) { boolean matchedTypes = false; //try explicit type arguments final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); diff --git a/java/java-tests/testData/refactoring/inlineLocal/Wildcard.java b/java/java-tests/testData/refactoring/inlineLocal/Wildcard.java new file mode 100644 index 000000000000..581682b6b9a2 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineLocal/Wildcard.java @@ -0,0 +1,11 @@ +import java.util.*; +class Test { + void foo() { + final Collection extensions = getExtensions(); + for (Number extension : extensions) { + } + } + + Collection getExtensions() {return null;} +} + diff --git a/java/java-tests/testData/refactoring/inlineLocal/Wildcard.java.after b/java/java-tests/testData/refactoring/inlineLocal/Wildcard.java.after new file mode 100644 index 000000000000..351037abb958 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineLocal/Wildcard.java.after @@ -0,0 +1,10 @@ +import java.util.*; +class Test { + void foo() { + for (Number extension : getExtensions()) { + } + } + + Collection getExtensions() {return null;} +} + diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java index af0c14e070aa..5e4f8f12b8c1 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java @@ -110,6 +110,10 @@ public class InlineLocalTest extends LightCodeInsightTestCase { doTest(true); } + public void testWildcard() throws Exception { + doTest(true); + } + private void doTest(final boolean inlineDef, String conflictMessage) throws Exception { try { doTest(inlineDef);