void (@NotNull GrConditionalExpression expression) { final GrExpression condition = expression.getCondition(); final GrExpression thenBranch = expression.getThenBranch(); final GrExpression elseBranch = expression.getElseBranch(); final boolean elvis = expression instanceof GrElvisExpression; final String var; if (elvis) { var = createVarByInitializer(condition); } else { var = null; } final PsiType type = condition.getType(); if (type == null || PsiTypes.booleanType().equals(TypesUtil.unboxPrimitiveTypeWrapper(type))) { if (elvis) { builder.append(var); } else { condition.accept(this); } } else { final GroovyResolveResult[] results = ResolveUtil.getMethodCandidates(type, "asBoolean", expression, PsiType.EMPTY_ARRAY); final GroovyResolveResult result = PsiImplUtil.extractUniqueResult(results); GenerationUtil.invokeMethodByResolveResult( elvis ? factory.createReferenceExpressionFromText(var, expression) : condition, result, "asBoolean", GrExpression.EMPTY_ARRAY, GrNamedArgument.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, this, expression ); } builder.append('?'); if (thenBranch != null) { if (elvis) { builder.append(var); } else { thenBranch.accept(this); } } builder.append(':'); if (elseBranch != null) { elseBranch.accept(this); } }