diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntention.java index 11578be9b40d..16808a8fedcd 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import com.siyeh.ig.psiutils.ParenthesesUtils; import com.siyeh.ipp.base.Intention; import com.siyeh.ipp.base.PsiElementPredicate; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import static com.intellij.psi.CommonClassNames.JAVA_LANG_BOOLEAN; import static com.siyeh.ig.psiutils.ParenthesesUtils.AND_PRECEDENCE; @@ -57,7 +58,10 @@ public class ReplaceConditionalWithBooleanExpressionIntention extends Intention PsiReplacementUtil.replaceExpression((PsiExpression)element, replacementText); } - private static String getText(PsiExpression expression) { + private static String getText(@Nullable PsiExpression expression) { + if (expression == null) { + return ""; + } if (ParenthesesUtils.getPrecedence(expression) > AND_PRECEDENCE) { return '(' + expression.getText() + ')'; } diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntentionTest.java index 1ed412496702..c9848a094bd4 100644 --- a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntentionTest.java +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntentionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,4 +36,17 @@ public class ReplaceConditionalWithBooleanExpressionIntentionTest extends IPPTes " }" + "}"); } + + public void testIncomplete() { + doTest("class X {" + + " boolean test(boolean a, boolean b, boolean c) {" + + " return a /*_Replace '?:' with boolean expression*/? b ? c;" + + " }" + + "}", + "class X {" + + " boolean test(boolean a, boolean b, boolean c) {" + + " return a && (b ? c) || !a &&;" + + " }" + + "}"); + } }