ConditionalExpressionGenerator (ConditionalModel model) { PsiExpression condition = model.getCondition(); PsiExpression thenExpression = model.getThenExpression(); PsiExpression elseExpression = model.getElseExpression(); if (PsiTypes.booleanType().equals(model.getType()) || model.getType().equalsToText(CommonClassNames.JAVA_LANG_BOOLEAN)) { PsiLiteralExpression thenLiteral = ExpressionUtils.getLiteral(thenExpression); PsiLiteralExpression elseLiteral = ExpressionUtils.getLiteral(elseExpression); Boolean thenValue = thenLiteral == null ? null : tryCast(thenLiteral.getValue(), Boolean.class); Boolean elseValue = elseLiteral == null ? null : tryCast(elseLiteral.getValue(), Boolean.class); if (thenValue != null && elseValue != null) { if (thenValue.equals(elseValue)) { // Equal branches are handled by separate inspections return null; } if (thenValue) { return new ConditionalExpressionGenerator("", condition); } return new ConditionalExpressionGenerator("", ct -> BoolUtils.getNegatedExpressionText(condition, ct)); } if ((thenValue != null || elseValue != null) && PsiTypes.booleanType().equals(model.getType())) { return getAndOrGenerator(condition, thenExpression, elseExpression, thenValue, elseValue); } if (BoolUtils.areExpressionsOpposite(thenExpression, elseExpression)) { return getEqualityGenerator(model.getCondition(), thenExpression); } } PsiExpression redundantComparisonReplacement = getRedundantComparisonReplacement(model); if (redundantComparisonReplacement != null) { return new ConditionalExpressionGenerator("", redundantComparisonReplacement); } return new ConditionalExpressionGenerator("?:", ct -> generateTernary(ct, condition, thenExpression, elseExpression, model.getType())); }