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 f02de67d1fdd..8ee73bb0017f 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/InlineUtil.java @@ -55,7 +55,8 @@ public class InlineUtil { PsiExpression expr = (PsiExpression)replaceDiamondWithInferredTypesIfNeeded(initializer, ref); PsiType exprType = expr.getType(); if (exprType != null && (!varType.equals(exprType) && varType instanceof PsiPrimitiveType - || !TypeConversionUtil.isAssignable(varType, exprType))) { + || !TypeConversionUtil.isAssignable(varType, exprType) + || expr instanceof PsiConditionalExpression)) { boolean matchedTypes = false; //try explicit type arguments final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); diff --git a/java/java-tests/testData/refactoring/inlineLocal/ConditionExpr.java b/java/java-tests/testData/refactoring/inlineLocal/ConditionExpr.java new file mode 100644 index 000000000000..58f3df62ffcd --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineLocal/ConditionExpr.java @@ -0,0 +1,7 @@ +public class Test2 { + { + Integer iii = true ? 1 : 2; + iii.byteValue(); + } +} + diff --git a/java/java-tests/testData/refactoring/inlineLocal/ConditionExpr.java.after b/java/java-tests/testData/refactoring/inlineLocal/ConditionExpr.java.after new file mode 100644 index 000000000000..0f18f384053a --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineLocal/ConditionExpr.java.after @@ -0,0 +1,6 @@ +public class Test2 { + { + ((Integer) (true ? 1 : 2)).byteValue(); + } +} + 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 85484e5cf462..7cd884aab33c 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java @@ -148,6 +148,10 @@ public class InlineLocalTest extends LightCodeInsightTestCase { "Variable 'x' is accessed for writing."); } + public void testConditionExpr() throws Exception { + doTest(true); + } + public void testLambdaExpr() throws Exception { doTest(true); }